2020-05-20 19:17:33 +00:00
|
|
|
# type: ignore
|
|
|
|
import pytest # type: ignore # https://github.com/pytest-dev/pytest/issues/3342
|
|
|
|
|
|
|
|
from kasa import DeviceType, Discover, SmartDevice, SmartDeviceException
|
|
|
|
|
2020-07-19 20:32:17 +00:00
|
|
|
from .conftest import bulb, dimmer, lightstrip, plug, pytestmark, strip
|
2020-05-20 19:17:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@plug
|
|
|
|
async def test_type_detection_plug(dev: SmartDevice):
|
|
|
|
d = Discover._get_device_class(dev.protocol.discovery_data)("localhost")
|
|
|
|
assert d.is_plug
|
|
|
|
assert d.device_type == DeviceType.Plug
|
|
|
|
|
|
|
|
|
|
|
|
@bulb
|
|
|
|
async def test_type_detection_bulb(dev: SmartDevice):
|
|
|
|
d = Discover._get_device_class(dev.protocol.discovery_data)("localhost")
|
2020-07-19 20:32:17 +00:00
|
|
|
# TODO: light_strip is a special case for now to force bulb tests on it
|
|
|
|
if not d.is_light_strip:
|
|
|
|
assert d.is_bulb
|
|
|
|
assert d.device_type == DeviceType.Bulb
|
2020-05-20 19:17:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
@strip
|
|
|
|
async def test_type_detection_strip(dev: SmartDevice):
|
|
|
|
d = Discover._get_device_class(dev.protocol.discovery_data)("localhost")
|
|
|
|
assert d.is_strip
|
|
|
|
assert d.device_type == DeviceType.Strip
|
|
|
|
|
|
|
|
|
|
|
|
@dimmer
|
|
|
|
async def test_type_detection_dimmer(dev: SmartDevice):
|
|
|
|
d = Discover._get_device_class(dev.protocol.discovery_data)("localhost")
|
|
|
|
assert d.is_dimmer
|
|
|
|
assert d.device_type == DeviceType.Dimmer
|
|
|
|
|
|
|
|
|
2020-07-19 20:32:17 +00:00
|
|
|
@lightstrip
|
|
|
|
async def test_type_detection_lightstrip(dev: SmartDevice):
|
|
|
|
d = Discover._get_device_class(dev.protocol.discovery_data)("localhost")
|
|
|
|
assert d.is_light_strip
|
|
|
|
assert d.device_type == DeviceType.LightStrip
|
|
|
|
|
|
|
|
|
2020-05-20 19:17:33 +00:00
|
|
|
async def test_type_unknown():
|
|
|
|
invalid_info = {"system": {"get_sysinfo": {"type": "nosuchtype"}}}
|
|
|
|
with pytest.raises(SmartDeviceException):
|
|
|
|
Discover._get_device_class(invalid_info)
|