mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-06-11 04:35:40 +00:00
match names to cli
This commit is contained in:
parent
5e290633ed
commit
a63e0bed2d
13
kasa/cli.py
13
kasa/cli.py
@ -12,14 +12,13 @@ import asyncclick as click
|
|||||||
|
|
||||||
from kasa import (
|
from kasa import (
|
||||||
Credentials,
|
Credentials,
|
||||||
|
DeviceType,
|
||||||
Discover,
|
Discover,
|
||||||
SmartBulb,
|
SmartBulb,
|
||||||
SmartDevice,
|
SmartDevice,
|
||||||
SmartDimmer,
|
|
||||||
SmartLightStrip,
|
|
||||||
SmartPlug,
|
|
||||||
SmartStrip,
|
SmartStrip,
|
||||||
)
|
)
|
||||||
|
from kasa.discover import DEVICE_TYPE_TO_CLASS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from rich import print as _do_echo
|
from rich import print as _do_echo
|
||||||
@ -43,11 +42,9 @@ except ImportError:
|
|||||||
echo = _do_echo
|
echo = _do_echo
|
||||||
|
|
||||||
TYPE_TO_CLASS = {
|
TYPE_TO_CLASS = {
|
||||||
"plug": SmartPlug,
|
device_type.value: DEVICE_TYPE_TO_CLASS[device_type]
|
||||||
"bulb": SmartBulb,
|
for device_type in DeviceType
|
||||||
"dimmer": SmartDimmer,
|
if device_type in DEVICE_TYPE_TO_CLASS
|
||||||
"strip": SmartStrip,
|
|
||||||
"lightstrip": SmartLightStrip,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
click.anyio_backend = "asyncio"
|
click.anyio_backend = "asyncio"
|
||||||
|
@ -340,6 +340,7 @@ class Discover:
|
|||||||
The device type is discovered by querying the device.
|
The device type is discovered by querying the device.
|
||||||
|
|
||||||
:param host: Hostname of device to query
|
:param host: Hostname of device to query
|
||||||
|
:param device_type: Device type to use for the device.
|
||||||
:rtype: SmartDevice
|
:rtype: SmartDevice
|
||||||
:return: Object for querying/controlling found device.
|
:return: Object for querying/controlling found device.
|
||||||
"""
|
"""
|
||||||
|
@ -32,13 +32,13 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class DeviceType(Enum):
|
class DeviceType(Enum):
|
||||||
"""Device type enum."""
|
"""Device type enum."""
|
||||||
|
|
||||||
Plug = "Plug"
|
Plug = "plug"
|
||||||
Bulb = "Bulb"
|
Bulb = "bulb"
|
||||||
Strip = "Strip"
|
Strip = "strip"
|
||||||
StripSocket = "StripSocket"
|
StripSocket = "stripsocket"
|
||||||
Dimmer = "Dimmer"
|
Dimmer = "dimmer"
|
||||||
LightStrip = "LightStrip"
|
LightStrip = "lightstrip"
|
||||||
Unknown = "Unknown"
|
Unknown = "unknown"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_value(name: str) -> "DeviceType":
|
def from_value(name: str) -> "DeviceType":
|
||||||
|
@ -65,8 +65,20 @@ async def test_smart_device_from_value():
|
|||||||
assert DeviceType.from_value(name.value) is not None
|
assert DeviceType.from_value(name.value) is not None
|
||||||
|
|
||||||
assert DeviceType.from_value("nonexistent") is DeviceType.Unknown
|
assert DeviceType.from_value("nonexistent") is DeviceType.Unknown
|
||||||
assert DeviceType.from_value("Plug") is DeviceType.Plug
|
assert DeviceType.from_value("plug") is DeviceType.Plug
|
||||||
assert DeviceType.Plug.value == "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):
|
async def test_query_helper(dev):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user