From edc9e38f261e25e879e9e50ad7c02f563f9b56b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Maria=20Semprini?= Date: Fri, 4 Apr 2025 11:14:15 +0000 Subject: [PATCH 1/5] nicosemp/fallback-alias-for-p304m: fallback p304m alias to model --- kasa/smart/smartdevice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 2e2dc7cd5..7028937cb 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -598,6 +598,8 @@ def alias(self) -> str | None: """Returns the device alias or nickname.""" if self._info and (nickname := self._info.get("nickname")): return base64.b64decode(nickname).decode() + elif self._info and (model := self._info.get("model")): + return model else: return None From 6662b73fce1373ab80ef1075123b08348d2434d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Maria=20Semprini?= Date: Sat, 5 Apr 2025 23:43:56 +0000 Subject: [PATCH 2/5] nicosemp/fallback-alias-for-p304m: use device type instead of model + fix test --- kasa/smart/smartdevice.py | 22 ++++++++++++++++++++-- tests/smart/test_smartdevice.py | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 7028937cb..a2b372c14 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -43,6 +43,24 @@ ComponentsRaw: TypeAlias = dict[str, list[dict[str, int | str]]] +DEVICE_TYPE_TO_LABEL = { + DeviceType.Plug: "Plug", + DeviceType.Strip: "Power Strip", + DeviceType.StripSocket: "Power Strip", + DeviceType.Dimmer: "Wall Switch", + DeviceType.WallSwitch: "Wall Switch", + DeviceType.Fan: "Wall Switch", + DeviceType.Bulb: "Bulb", + DeviceType.LightStrip: "Light Strip", + DeviceType.Camera: "Camera", + DeviceType.Doorbell: "Doorbell", + DeviceType.Chime: "Chime", + DeviceType.Vacuum: "Vacuum", + DeviceType.Hub: "Hub", + DeviceType.Sensor: "Hub-Connected Device", + DeviceType.Thermostat: "Hub-Connected Thermostat", +} + # Device must go last as the other interfaces also inherit Device # and python needs a consistent method resolution order. @@ -598,8 +616,8 @@ def alias(self) -> str | None: """Returns the device alias or nickname.""" if self._info and (nickname := self._info.get("nickname")): return base64.b64decode(nickname).decode() - elif self._info and (model := self._info.get("model")): - return model + elif label := DEVICE_TYPE_TO_LABEL.get(self._device_type): + return label else: return None diff --git a/tests/smart/test_smartdevice.py b/tests/smart/test_smartdevice.py index 155c2bdf7..34b756516 100644 --- a/tests/smart/test_smartdevice.py +++ b/tests/smart/test_smartdevice.py @@ -90,7 +90,7 @@ async def test_device_type_no_update(discovery_mock, caplog: pytest.LogCaptureFi assert dev.device_type is DeviceType.Plug assert ( repr(dev) - == f"" + == f"" ) assert "Unknown device type, falling back to plug" in caplog.text From 164e37a075f9edd3fcbb13ff92ff0621e3f8b485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Maria=20Semprini?= Date: Wed, 11 Jun 2025 17:01:40 +0000 Subject: [PATCH 3/5] nicosemp/fallback-alias-for-p304m: address nits --- kasa/smart/smartdevice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index a2b372c14..cd91c2a90 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -49,7 +49,7 @@ DeviceType.StripSocket: "Power Strip", DeviceType.Dimmer: "Wall Switch", DeviceType.WallSwitch: "Wall Switch", - DeviceType.Fan: "Wall Switch", + DeviceType.Fan: "Fan", DeviceType.Bulb: "Bulb", DeviceType.LightStrip: "Light Strip", DeviceType.Camera: "Camera", @@ -57,7 +57,7 @@ DeviceType.Chime: "Chime", DeviceType.Vacuum: "Vacuum", DeviceType.Hub: "Hub", - DeviceType.Sensor: "Hub-Connected Device", + DeviceType.Sensor: "Sensor", DeviceType.Thermostat: "Hub-Connected Thermostat", } @@ -617,7 +617,7 @@ def alias(self) -> str | None: if self._info and (nickname := self._info.get("nickname")): return base64.b64decode(nickname).decode() elif label := DEVICE_TYPE_TO_LABEL.get(self._device_type): - return label + return f"Unnamed {label} ({self.model} {self.device_id})" else: return None From 83bc7f1602a9a1a530c0d1e0ee398449f238987f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Maria=20Semprini?= Date: Wed, 11 Jun 2025 17:38:52 +0000 Subject: [PATCH 4/5] nicosemp/fallback-alias-for-p304m: remove the unnamed part from the string --- kasa/smart/smartdevice.py | 2 +- tests/smart/test_smartdevice.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index cd91c2a90..1a76d5686 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -617,7 +617,7 @@ def alias(self) -> str | None: if self._info and (nickname := self._info.get("nickname")): return base64.b64decode(nickname).decode() elif label := DEVICE_TYPE_TO_LABEL.get(self._device_type): - return f"Unnamed {label} ({self.model} {self.device_id})" + return f"{label} ({self.model} {self.device_id})" else: return None diff --git a/tests/smart/test_smartdevice.py b/tests/smart/test_smartdevice.py index 34b756516..9034f5ed5 100644 --- a/tests/smart/test_smartdevice.py +++ b/tests/smart/test_smartdevice.py @@ -76,6 +76,10 @@ async def test_device_type_no_update(discovery_mock, caplog: pytest.LogCaptureFi discovery_result = copy.deepcopy(discovery_mock.discovery_data["result"]) + print("TESTERINO", discovery_result) + + disco_id = discovery_result["device_id"] + disco_model = discovery_result["device_model"] short_model, _, _ = disco_model.partition("(") dev.update_from_discover_info(discovery_result) @@ -90,7 +94,7 @@ async def test_device_type_no_update(discovery_mock, caplog: pytest.LogCaptureFi assert dev.device_type is DeviceType.Plug assert ( repr(dev) - == f"" + == f"" ) assert "Unknown device type, falling back to plug" in caplog.text From 4937672e25be9f28cb303317ca2d9fb5c342b096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Maria=20Semprini?= Date: Thu, 12 Jun 2025 14:39:14 +0000 Subject: [PATCH 5/5] nicosemp/fallback-alias-for-p304m: remove duplicate short_model --- kasa/smart/smartdevice.py | 2 +- tests/smart/test_smartdevice.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 1a76d5686..50c4ff472 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -617,7 +617,7 @@ def alias(self) -> str | None: if self._info and (nickname := self._info.get("nickname")): return base64.b64decode(nickname).decode() elif label := DEVICE_TYPE_TO_LABEL.get(self._device_type): - return f"{label} ({self.model} {self.device_id})" + return f"{label} ({self.device_id})" else: return None diff --git a/tests/smart/test_smartdevice.py b/tests/smart/test_smartdevice.py index 9034f5ed5..ce4c34008 100644 --- a/tests/smart/test_smartdevice.py +++ b/tests/smart/test_smartdevice.py @@ -94,7 +94,7 @@ async def test_device_type_no_update(discovery_mock, caplog: pytest.LogCaptureFi assert dev.device_type is DeviceType.Plug assert ( repr(dev) - == f"" + == f"" ) assert "Unknown device type, falling back to plug" in caplog.text