From c6f2d89d44ec1ff89a2e04949a4d452f0c39ce80 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:55:07 +0100 Subject: [PATCH] Expose smart child device map as a class constant (#1173) To facilitate distinguishing between smart and smart camera child devices. --- kasa/smart/smartchilddevice.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/kasa/smart/smartchilddevice.py b/kasa/smart/smartchilddevice.py index 3b5f53ef..16006ea4 100644 --- a/kasa/smart/smartchilddevice.py +++ b/kasa/smart/smartchilddevice.py @@ -21,6 +21,17 @@ class SmartChildDevice(SmartDevice): This wraps the protocol communications and sets internal data for the child. """ + CHILD_DEVICE_TYPE_MAP = { + "plug.powerstrip.sub-plug": DeviceType.Plug, + "subg.trigger.contact-sensor": DeviceType.Sensor, + "subg.trigger.temp-hmdt-sensor": DeviceType.Sensor, + "subg.trigger.water-leak-sensor": DeviceType.Sensor, + "kasa.switch.outlet.sub-fan": DeviceType.Fan, + "kasa.switch.outlet.sub-dimmer": DeviceType.Dimmer, + "subg.trv": DeviceType.Thermostat, + "subg.trigger.button": DeviceType.Sensor, + } + def __init__( self, parent: SmartDevice, @@ -76,16 +87,7 @@ class SmartChildDevice(SmartDevice): @property def device_type(self) -> DeviceType: """Return child device type.""" - child_device_map = { - "plug.powerstrip.sub-plug": DeviceType.Plug, - "subg.trigger.contact-sensor": DeviceType.Sensor, - "subg.trigger.temp-hmdt-sensor": DeviceType.Sensor, - "subg.trigger.water-leak-sensor": DeviceType.Sensor, - "kasa.switch.outlet.sub-fan": DeviceType.Fan, - "kasa.switch.outlet.sub-dimmer": DeviceType.Dimmer, - "subg.trv": DeviceType.Thermostat, - } - dev_type = child_device_map.get(self.sys_info["category"]) + dev_type = self.CHILD_DEVICE_TYPE_MAP.get(self.sys_info["category"]) if dev_type is None: _LOGGER.warning("Unknown child device type, please open issue ") dev_type = DeviceType.Unknown