From a63e0bed2d021c2776223b82075fbb6d4567fdb9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 31 Oct 2023 20:06:02 -0500 Subject: [PATCH] match names to cli --- kasa/cli.py | 13 +++++-------- kasa/discover.py | 1 + kasa/smartdevice.py | 14 +++++++------- kasa/tests/test_smartdevice.py | 16 ++++++++++++++-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/kasa/cli.py b/kasa/cli.py index 3bc77934..0058aef3 100755 --- a/kasa/cli.py +++ b/kasa/cli.py @@ -12,14 +12,13 @@ import asyncclick as click from kasa import ( Credentials, + DeviceType, Discover, SmartBulb, SmartDevice, - SmartDimmer, - SmartLightStrip, - SmartPlug, SmartStrip, ) +from kasa.discover import DEVICE_TYPE_TO_CLASS try: from rich import print as _do_echo @@ -43,11 +42,9 @@ except ImportError: echo = _do_echo TYPE_TO_CLASS = { - "plug": SmartPlug, - "bulb": SmartBulb, - "dimmer": SmartDimmer, - "strip": SmartStrip, - "lightstrip": SmartLightStrip, + device_type.value: DEVICE_TYPE_TO_CLASS[device_type] + for device_type in DeviceType + if device_type in DEVICE_TYPE_TO_CLASS } click.anyio_backend = "asyncio" diff --git a/kasa/discover.py b/kasa/discover.py index 90904d30..ab7a51ce 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -340,6 +340,7 @@ class Discover: The device type is discovered by querying the device. :param host: Hostname of device to query + :param device_type: Device type to use for the device. :rtype: SmartDevice :return: Object for querying/controlling found device. """ diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 342bc27c..a0faf795 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -32,13 +32,13 @@ _LOGGER = logging.getLogger(__name__) class DeviceType(Enum): """Device type enum.""" - Plug = "Plug" - Bulb = "Bulb" - Strip = "Strip" - StripSocket = "StripSocket" - Dimmer = "Dimmer" - LightStrip = "LightStrip" - Unknown = "Unknown" + Plug = "plug" + Bulb = "bulb" + Strip = "strip" + StripSocket = "stripsocket" + Dimmer = "dimmer" + LightStrip = "lightstrip" + Unknown = "unknown" @staticmethod def from_value(name: str) -> "DeviceType": diff --git a/kasa/tests/test_smartdevice.py b/kasa/tests/test_smartdevice.py index 24a3dd0f..f0ece094 100644 --- a/kasa/tests/test_smartdevice.py +++ b/kasa/tests/test_smartdevice.py @@ -65,8 +65,20 @@ async def test_smart_device_from_value(): assert DeviceType.from_value(name.value) is not None assert DeviceType.from_value("nonexistent") is DeviceType.Unknown - assert DeviceType.from_value("Plug") is DeviceType.Plug - assert DeviceType.Plug.value == "Plug" + assert DeviceType.from_value("plug") is DeviceType.Plug + assert DeviceType.Plug.value == "plug" + + assert DeviceType.from_value("bulb") is DeviceType.Bulb + assert DeviceType.Bulb.value == "bulb" + + assert DeviceType.from_value("dimmer") is DeviceType.Dimmer + assert DeviceType.Dimmer.value == "dimmer" + + assert DeviceType.from_value("strip") is DeviceType.Strip + assert DeviceType.Strip.value == "strip" + + assert DeviceType.from_value("lightstrip") is DeviceType.LightStrip + assert DeviceType.LightStrip.value == "lightstrip" async def test_query_helper(dev):