mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-11 18:08:02 +00:00
Add https parameter to device class factory (#1184)
`SMART.TAPOHUB` resolves to different device classes based on the https value
This commit is contained in:
@@ -67,7 +67,8 @@ async def connect(*, host: str | None = None, config: DeviceConfig) -> Device:
|
||||
if (protocol := get_protocol(config=config)) is None:
|
||||
raise UnsupportedDeviceError(
|
||||
f"Unsupported device for {config.host}: "
|
||||
+ f"{config.connection_type.device_family.value}"
|
||||
+ f"{config.connection_type.device_family.value}",
|
||||
host=config.host,
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -110,7 +111,7 @@ async def _connect(config: DeviceConfig, protocol: BaseProtocol) -> Device:
|
||||
_perf_log(True, "update")
|
||||
return device
|
||||
elif device_class := get_device_class_from_family(
|
||||
config.connection_type.device_family.value
|
||||
config.connection_type.device_family.value, https=config.connection_type.https
|
||||
):
|
||||
device = device_class(host=config.host, protocol=protocol)
|
||||
await device.update()
|
||||
@@ -119,7 +120,8 @@ async def _connect(config: DeviceConfig, protocol: BaseProtocol) -> Device:
|
||||
else:
|
||||
raise UnsupportedDeviceError(
|
||||
f"Unsupported device for {config.host}: "
|
||||
+ f"{config.connection_type.device_family.value}"
|
||||
+ f"{config.connection_type.device_family.value}",
|
||||
host=config.host,
|
||||
)
|
||||
|
||||
|
||||
@@ -164,7 +166,9 @@ def get_device_class_from_sys_info(sysinfo: dict[str, Any]) -> type[IotDevice]:
|
||||
return TYPE_TO_CLASS[_get_device_type_from_sys_info(sysinfo)]
|
||||
|
||||
|
||||
def get_device_class_from_family(device_type: str) -> type[Device] | None:
|
||||
def get_device_class_from_family(
|
||||
device_type: str, *, https: bool
|
||||
) -> type[Device] | None:
|
||||
"""Return the device class from the type name."""
|
||||
supported_device_types: dict[str, type[Device]] = {
|
||||
"SMART.TAPOPLUG": SmartDevice,
|
||||
@@ -172,14 +176,16 @@ def get_device_class_from_family(device_type: str) -> type[Device] | None:
|
||||
"SMART.TAPOSWITCH": SmartDevice,
|
||||
"SMART.KASAPLUG": SmartDevice,
|
||||
"SMART.TAPOHUB": SmartDevice,
|
||||
"SMART.TAPOHUB.HTTPS": SmartCamera,
|
||||
"SMART.KASAHUB": SmartDevice,
|
||||
"SMART.KASASWITCH": SmartDevice,
|
||||
"SMART.IPCAMERA": SmartCamera,
|
||||
"SMART.IPCAMERA.HTTPS": SmartCamera,
|
||||
"IOT.SMARTPLUGSWITCH": IotPlug,
|
||||
"IOT.SMARTBULB": IotBulb,
|
||||
}
|
||||
lookup_key = f"{device_type}{'.HTTPS' if https else ''}"
|
||||
if (
|
||||
cls := supported_device_types.get(device_type)
|
||||
cls := supported_device_types.get(lookup_key)
|
||||
) is None and device_type.startswith("SMART."):
|
||||
_LOGGER.warning("Unknown SMART device with %s, using SmartDevice", device_type)
|
||||
cls = SmartDevice
|
||||
|
Reference in New Issue
Block a user