diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 2e2dc7cd5..50c4ff472 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: "Fan", + DeviceType.Bulb: "Bulb", + DeviceType.LightStrip: "Light Strip", + DeviceType.Camera: "Camera", + DeviceType.Doorbell: "Doorbell", + DeviceType.Chime: "Chime", + DeviceType.Vacuum: "Vacuum", + DeviceType.Hub: "Hub", + DeviceType.Sensor: "Sensor", + 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,6 +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 label := DEVICE_TYPE_TO_LABEL.get(self._device_type): + return f"{label} ({self.device_id})" else: return None diff --git a/tests/smart/test_smartdevice.py b/tests/smart/test_smartdevice.py index 155c2bdf7..ce4c34008 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