|
14 | 14 |
|
15 | 15 | import kasa |
16 | 16 | from kasa import Credentials, Device, DeviceConfig, DeviceType, KasaException, Module |
17 | | -from kasa.iot import IotDevice |
| 17 | +from kasa.iot import ( |
| 18 | + IotBulb, |
| 19 | + IotDevice, |
| 20 | + IotDimmer, |
| 21 | + IotLightStrip, |
| 22 | + IotPlug, |
| 23 | + IotStrip, |
| 24 | + IotWallSwitch, |
| 25 | +) |
18 | 26 | from kasa.iot.iottimezone import ( |
19 | 27 | TIMEZONE_INDEX, |
20 | 28 | get_timezone, |
21 | 29 | get_timezone_index, |
22 | 30 | ) |
23 | 31 | from kasa.iot.modules import IotLightPreset |
24 | 32 | from kasa.smart import SmartChildDevice, SmartDevice |
| 33 | +from kasa.smartcamera import SmartCamera |
25 | 34 |
|
26 | 35 |
|
27 | 36 | def _get_subclasses(of_class): |
@@ -80,6 +89,41 @@ async def test_device_class_ctors(device_class_name_obj): |
80 | 89 | assert dev.credentials == credentials |
81 | 90 |
|
82 | 91 |
|
| 92 | +@device_classes |
| 93 | +async def test_device_class_repr(device_class_name_obj): |
| 94 | + """Test device repr when update() not called and no discovery info.""" |
| 95 | + host = "127.0.0.2" |
| 96 | + port = 1234 |
| 97 | + credentials = Credentials("foo", "bar") |
| 98 | + config = DeviceConfig(host, port_override=port, credentials=credentials) |
| 99 | + klass = device_class_name_obj[1] |
| 100 | + if issubclass(klass, SmartChildDevice): |
| 101 | + parent = SmartDevice(host, config=config) |
| 102 | + dev = klass( |
| 103 | + parent, {"dummy": "info", "device_id": "dummy"}, {"dummy": "components"} |
| 104 | + ) |
| 105 | + else: |
| 106 | + dev = klass(host, config=config) |
| 107 | + |
| 108 | + CLASS_TO_DEFAULT_TYPE = { |
| 109 | + IotDevice: DeviceType.Unknown, |
| 110 | + IotBulb: DeviceType.Bulb, |
| 111 | + IotPlug: DeviceType.Plug, |
| 112 | + IotDimmer: DeviceType.Dimmer, |
| 113 | + IotStrip: DeviceType.Strip, |
| 114 | + IotWallSwitch: DeviceType.WallSwitch, |
| 115 | + IotLightStrip: DeviceType.LightStrip, |
| 116 | + SmartChildDevice: DeviceType.Unknown, |
| 117 | + SmartDevice: DeviceType.Unknown, |
| 118 | + SmartCamera: DeviceType.Camera, |
| 119 | + } |
| 120 | + type_ = CLASS_TO_DEFAULT_TYPE[klass] |
| 121 | + child_repr = "<DeviceType.Unknown(child) of <DeviceType.Unknown at 127.0.0.2 - update() needed>>" |
| 122 | + not_child_repr = f"<{type_} at 127.0.0.2 - update() needed>" |
| 123 | + expected_repr = child_repr if klass is SmartChildDevice else not_child_repr |
| 124 | + assert repr(dev) == expected_repr |
| 125 | + |
| 126 | + |
83 | 127 | async def test_create_device_with_timeout(): |
84 | 128 | """Make sure timeout is passed to the protocol.""" |
85 | 129 | host = "127.0.0.1" |
|
0 commit comments