python-kasa 0.6.2__py3-none-any.whl → 0.7.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. kasa/__init__.py +88 -27
  2. kasa/aestransport.py +51 -34
  3. kasa/cli.py +326 -130
  4. kasa/device.py +406 -0
  5. kasa/device_factory.py +83 -44
  6. kasa/device_type.py +7 -3
  7. kasa/deviceconfig.py +16 -9
  8. kasa/discover.py +100 -81
  9. kasa/emeterstatus.py +12 -7
  10. kasa/exceptions.py +41 -26
  11. kasa/feature.py +201 -0
  12. kasa/httpclient.py +21 -14
  13. kasa/interfaces/__init__.py +16 -0
  14. kasa/interfaces/fan.py +20 -0
  15. kasa/interfaces/led.py +38 -0
  16. kasa/interfaces/light.py +133 -0
  17. kasa/interfaces/lighteffect.py +80 -0
  18. kasa/interfaces/lightpreset.py +76 -0
  19. kasa/iot/__init__.py +18 -0
  20. kasa/{effects.py → iot/effects.py} +4 -2
  21. kasa/{smartbulb.py → iot/iotbulb.py} +100 -147
  22. kasa/{smartdevice.py → iot/iotdevice.py} +157 -286
  23. kasa/{smartdimmer.py → iot/iotdimmer.py} +42 -33
  24. kasa/iot/iotlightstrip.py +71 -0
  25. kasa/{modules/module.py → iot/iotmodule.py} +22 -42
  26. kasa/iot/iotplug.py +94 -0
  27. kasa/{smartstrip.py → iot/iotstrip.py} +57 -75
  28. kasa/{modules → iot/modules}/__init__.py +10 -2
  29. kasa/{modules → iot/modules}/ambientlight.py +31 -3
  30. kasa/{modules → iot/modules}/antitheft.py +1 -0
  31. kasa/{modules → iot/modules}/cloud.py +25 -6
  32. kasa/{modules → iot/modules}/countdown.py +1 -0
  33. kasa/iot/modules/emeter.py +210 -0
  34. kasa/iot/modules/led.py +32 -0
  35. kasa/iot/modules/light.py +221 -0
  36. kasa/iot/modules/lighteffect.py +122 -0
  37. kasa/iot/modules/lightpreset.py +151 -0
  38. kasa/{modules → iot/modules}/motion.py +8 -8
  39. kasa/{modules → iot/modules}/rulemodule.py +11 -12
  40. kasa/{modules → iot/modules}/schedule.py +1 -0
  41. kasa/{modules → iot/modules}/time.py +5 -4
  42. kasa/{modules → iot/modules}/usage.py +10 -8
  43. kasa/iotprotocol.py +22 -20
  44. kasa/klaptransport.py +25 -15
  45. kasa/module.py +136 -0
  46. kasa/modulemapping.py +25 -0
  47. kasa/modulemapping.pyi +96 -0
  48. kasa/protocol.py +6 -4
  49. kasa/smart/__init__.py +6 -0
  50. kasa/smart/effects.py +429 -0
  51. kasa/smart/modules/__init__.py +57 -0
  52. kasa/smart/modules/alarm.py +142 -0
  53. kasa/smart/modules/autooff.py +96 -0
  54. kasa/smart/modules/batterysensor.py +54 -0
  55. kasa/smart/modules/brightness.py +66 -0
  56. kasa/smart/modules/childdevice.py +10 -0
  57. kasa/smart/modules/cloud.py +42 -0
  58. kasa/smart/modules/color.py +96 -0
  59. kasa/smart/modules/colortemperature.py +78 -0
  60. kasa/smart/modules/contactsensor.py +42 -0
  61. kasa/smart/modules/devicemodule.py +22 -0
  62. kasa/smart/modules/energy.py +101 -0
  63. kasa/smart/modules/fan.py +80 -0
  64. kasa/smart/modules/firmware.py +216 -0
  65. kasa/smart/modules/frostprotection.py +59 -0
  66. kasa/smart/modules/humiditysensor.py +55 -0
  67. kasa/smart/modules/led.py +49 -0
  68. kasa/smart/modules/light.py +139 -0
  69. kasa/smart/modules/lighteffect.py +115 -0
  70. kasa/smart/modules/lightpreset.py +142 -0
  71. kasa/smart/modules/lightstripeffect.py +135 -0
  72. kasa/smart/modules/lighttransition.py +183 -0
  73. kasa/smart/modules/reportmode.py +36 -0
  74. kasa/smart/modules/temperaturecontrol.py +177 -0
  75. kasa/smart/modules/temperaturesensor.py +77 -0
  76. kasa/smart/modules/time.py +57 -0
  77. kasa/smart/modules/waterleaksensor.py +66 -0
  78. kasa/smart/smartchilddevice.py +65 -0
  79. kasa/smart/smartdevice.py +653 -0
  80. kasa/smart/smartmodule.py +112 -0
  81. kasa/smartprotocol.py +107 -41
  82. kasa/tests/conftest.py +27 -551
  83. kasa/tests/device_fixtures.py +427 -0
  84. kasa/tests/discovery_fixtures.py +197 -0
  85. kasa/tests/{newfakes.py → fakeprotocol_iot.py} +61 -291
  86. kasa/tests/fakeprotocol_smart.py +318 -0
  87. kasa/tests/fixtureinfo.py +154 -0
  88. kasa/tests/fixtures/smart/H100(EU)_1.0_1.2.3.json +221 -0
  89. kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.10.json +547 -0
  90. kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.5.json +391 -0
  91. kasa/tests/fixtures/smart/KH100(UK)_1.0_1.5.6.json +1557 -0
  92. kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.4.json +899 -0
  93. kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.5.json +479 -0
  94. kasa/tests/fixtures/smart/L530E(EU)_3.0_1.1.6.json +449 -0
  95. kasa/tests/fixtures/smart/P100_1.0.0_1.1.3.json +173 -0
  96. kasa/tests/fixtures/smart/P100_1.0.0_1.4.0.json +204 -0
  97. kasa/tests/fixtures/smart/P110(EU)_1.0_1.0.7.json +566 -0
  98. kasa/tests/fixtures/smart/P300(EU)_1.0_1.0.13.json +13 -23
  99. kasa/tests/fixtures/smart/P300(EU)_1.0_1.0.7.json +6 -6
  100. kasa/tests/fixtures/smart/TP15(US)_1.0_1.0.3.json +295 -0
  101. kasa/tests/fixtures/smart/TP25(US)_1.0_1.0.2.json +423 -0
  102. kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.4.0.json +170 -0
  103. kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.8.0.json +171 -0
  104. kasa/tests/fixtures/smart/child/KE100(UK)_1.0_2.8.0.json +171 -0
  105. kasa/tests/fixtures/smart/child/T110(EU)_1.0_1.8.0.json +526 -0
  106. kasa/tests/fixtures/smart/child/T300(EU)_1.0_1.7.0.json +533 -0
  107. kasa/tests/fixtures/smart/child/T310(EU)_1.0_1.5.0.json +530 -0
  108. kasa/tests/fixtures/smart/child/T315(EU)_1.0_1.7.0.json +537 -0
  109. kasa/tests/smart/__init__.py +0 -0
  110. kasa/tests/smart/features/__init__.py +0 -0
  111. kasa/tests/smart/features/test_brightness.py +55 -0
  112. kasa/tests/smart/features/test_colortemp.py +30 -0
  113. kasa/tests/smart/modules/__init__.py +0 -0
  114. kasa/tests/smart/modules/test_contact.py +28 -0
  115. kasa/tests/smart/modules/test_fan.py +79 -0
  116. kasa/tests/smart/modules/test_firmware.py +108 -0
  117. kasa/tests/smart/modules/test_humidity.py +28 -0
  118. kasa/tests/smart/modules/test_light_effect.py +41 -0
  119. kasa/tests/smart/modules/test_temperature.py +47 -0
  120. kasa/tests/smart/modules/test_temperaturecontrol.py +137 -0
  121. kasa/tests/smart/modules/test_waterleak.py +42 -0
  122. kasa/tests/test_aestransport.py +115 -25
  123. kasa/tests/test_bulb.py +169 -86
  124. kasa/tests/test_childdevice.py +84 -0
  125. kasa/tests/test_cli.py +452 -100
  126. kasa/tests/test_common_modules.py +216 -0
  127. kasa/tests/test_device.py +268 -0
  128. kasa/tests/test_device_factory.py +61 -41
  129. kasa/tests/test_device_type.py +1 -1
  130. kasa/tests/test_deviceconfig.py +2 -5
  131. kasa/tests/test_dimmer.py +33 -24
  132. kasa/tests/test_discovery.py +112 -69
  133. kasa/tests/test_emeter.py +39 -12
  134. kasa/tests/test_feature.py +205 -0
  135. kasa/tests/test_httpclient.py +9 -9
  136. kasa/tests/test_iotdevice.py +286 -0
  137. kasa/tests/test_klapprotocol.py +94 -41
  138. kasa/tests/test_lightstrip.py +24 -19
  139. kasa/tests/test_plug.py +51 -9
  140. kasa/tests/test_protocol.py +8 -12
  141. kasa/tests/test_readme_examples.py +86 -27
  142. kasa/tests/test_smartdevice.py +211 -247
  143. kasa/tests/test_smartprotocol.py +129 -26
  144. kasa/tests/test_strip.py +15 -6
  145. kasa/tests/test_usage.py +1 -3
  146. kasa/xortransport.py +15 -12
  147. {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/METADATA +45 -141
  148. python_kasa-0.7.0.dev0.dist-info/RECORD +239 -0
  149. {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/WHEEL +1 -1
  150. kasa/modules/emeter.py +0 -111
  151. kasa/smartlightstrip.py +0 -143
  152. kasa/smartplug.py +0 -91
  153. kasa/tapo/__init__.py +0 -7
  154. kasa/tapo/childdevice.py +0 -44
  155. kasa/tapo/tapobulb.py +0 -262
  156. kasa/tapo/tapodevice.py +0 -383
  157. kasa/tapo/tapoplug.py +0 -45
  158. kasa/tests/fixtures/HS105(US)_1.0_mocked.json +0 -47
  159. kasa/tests/fixtures/HS110(EU)_2.0_mocked.json +0 -50
  160. kasa/tests/fixtures/HS110(US)_1.0_mocked.json +0 -50
  161. kasa/tests/fixtures/HS200(US)_1.0_mocked.json +0 -47
  162. kasa/tests/fixtures/HS220(US)_1.0_mocked.json +0 -75
  163. kasa/tests/fixtures/LB100(US)_1.0_mocked.json +0 -103
  164. kasa/tests/fixtures/LB120(US)_1.0_mocked.json +0 -103
  165. kasa/tests/fixtures/LB130(US)_1.0_mocked.json +0 -104
  166. python_kasa-0.6.2.dist-info/RECORD +0 -163
  167. {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/LICENSE +0 -0
  168. {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/entry_points.txt +0 -0
@@ -1,185 +1,13 @@
1
- import base64
2
1
  import copy
3
2
  import logging
4
- import re
5
- import warnings
6
- from json import loads as json_loads
7
-
8
- from voluptuous import (
9
- REMOVE_EXTRA,
10
- All,
11
- Any,
12
- Coerce, # type: ignore
13
- Invalid,
14
- Optional,
15
- Range,
16
- Schema,
17
- )
18
-
19
- from ..credentials import Credentials
3
+
20
4
  from ..deviceconfig import DeviceConfig
21
- from ..exceptions import SmartDeviceException
22
5
  from ..iotprotocol import IotProtocol
23
- from ..protocol import BaseTransport
24
- from ..smartprotocol import SmartProtocol
25
6
  from ..xortransport import XorTransport
26
7
 
27
8
  _LOGGER = logging.getLogger(__name__)
28
9
 
29
10
 
30
- def check_int_bool(x):
31
- if x != 0 and x != 1:
32
- raise Invalid(x)
33
- return x
34
-
35
-
36
- def check_mac(x):
37
- if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", x.lower()):
38
- return x
39
- raise Invalid(x)
40
-
41
-
42
- def check_mode(x):
43
- if x in ["schedule", "none", "count_down"]:
44
- return x
45
-
46
- raise Invalid(f"invalid mode {x}")
47
-
48
-
49
- def lb_dev_state(x):
50
- if x in ["normal"]:
51
- return x
52
-
53
- raise Invalid(f"Invalid dev_state {x}")
54
-
55
-
56
- TZ_SCHEMA = Schema(
57
- {"zone_str": str, "dst_offset": int, "index": All(int, Range(min=0)), "tz_str": str}
58
- )
59
-
60
- CURRENT_CONSUMPTION_SCHEMA = Schema(
61
- Any(
62
- {
63
- "voltage": Any(All(float, Range(min=0, max=300)), None),
64
- "power": Any(Coerce(float, Range(min=0)), None),
65
- "total": Any(Coerce(float, Range(min=0)), None),
66
- "current": Any(All(float, Range(min=0)), None),
67
- "voltage_mv": Any(
68
- All(float, Range(min=0, max=300000)), int, None
69
- ), # TODO can this be int?
70
- "power_mw": Any(Coerce(float, Range(min=0)), None),
71
- "total_wh": Any(Coerce(float, Range(min=0)), None),
72
- "current_ma": Any(
73
- All(float, Range(min=0)), int, None
74
- ), # TODO can this be int?
75
- "slot_id": Any(Coerce(int, Range(min=0)), None),
76
- },
77
- None,
78
- )
79
- )
80
-
81
- # these schemas should go to the mainlib as
82
- # they can be useful when adding support for new features/devices
83
- # as well as to check that faked devices are operating properly.
84
- PLUG_SCHEMA = Schema(
85
- {
86
- "active_mode": check_mode,
87
- "alias": str,
88
- "dev_name": str,
89
- "deviceId": str,
90
- "feature": str,
91
- "fwId": str,
92
- "hwId": str,
93
- "hw_ver": str,
94
- "icon_hash": str,
95
- "led_off": check_int_bool,
96
- "latitude": Any(All(float, Range(min=-90, max=90)), 0, None),
97
- "latitude_i": Any(
98
- All(int, Range(min=-900000, max=900000)),
99
- All(float, Range(min=-900000, max=900000)),
100
- 0,
101
- None,
102
- ),
103
- "longitude": Any(All(float, Range(min=-180, max=180)), 0, None),
104
- "longitude_i": Any(
105
- All(int, Range(min=-18000000, max=18000000)),
106
- All(float, Range(min=-18000000, max=18000000)),
107
- 0,
108
- None,
109
- ),
110
- "mac": check_mac,
111
- "model": str,
112
- "oemId": str,
113
- "on_time": int,
114
- "relay_state": int,
115
- "rssi": Any(int, None), # rssi can also be positive, see #54
116
- "sw_ver": str,
117
- "type": str,
118
- "mic_type": str,
119
- "updating": check_int_bool,
120
- # these are available on hs220
121
- "brightness": int,
122
- "preferred_state": [
123
- {"brightness": All(int, Range(min=0, max=100)), "index": int}
124
- ],
125
- "next_action": {"type": int},
126
- "child_num": Optional(Any(None, int)), # TODO fix hs300 checks
127
- "children": Optional(list), # TODO fix hs300
128
- # TODO some tplink simulator entries contain invalid (mic_mac, _i variants for lat/lon)
129
- # Therefore we add REMOVE_EXTRA..
130
- # "INVALIDmac": Optional,
131
- # "INVALIDlatitude": Optional,
132
- # "INVALIDlongitude": Optional,
133
- },
134
- extra=REMOVE_EXTRA,
135
- )
136
-
137
- LIGHT_STATE_SCHEMA = Schema(
138
- {
139
- "brightness": All(int, Range(min=0, max=100)),
140
- "color_temp": int,
141
- "hue": All(int, Range(min=0, max=360)),
142
- "mode": str,
143
- "on_off": check_int_bool,
144
- "saturation": All(int, Range(min=0, max=100)),
145
- "dft_on_state": Optional(
146
- {
147
- "brightness": All(int, Range(min=0, max=100)),
148
- "color_temp": All(int, Range(min=0, max=9000)),
149
- "hue": All(int, Range(min=0, max=360)),
150
- "mode": str,
151
- "saturation": All(int, Range(min=0, max=100)),
152
- }
153
- ),
154
- "err_code": int,
155
- }
156
- )
157
-
158
- BULB_SCHEMA = PLUG_SCHEMA.extend(
159
- {
160
- "ctrl_protocols": Optional(dict),
161
- "description": Optional(str), # TODO: LBxxx similar to dev_name
162
- "dev_state": lb_dev_state,
163
- "disco_ver": str,
164
- "heapsize": int,
165
- "is_color": check_int_bool,
166
- "is_dimmable": check_int_bool,
167
- "is_factory": bool,
168
- "is_variable_color_temp": check_int_bool,
169
- "light_state": LIGHT_STATE_SCHEMA,
170
- "preferred_state": [
171
- {
172
- "brightness": All(int, Range(min=0, max=100)),
173
- "color_temp": int,
174
- "hue": All(int, Range(min=0, max=360)),
175
- "index": int,
176
- "saturation": All(int, Range(min=0, max=100)),
177
- }
178
- ],
179
- }
180
- )
181
-
182
-
183
11
  def get_realtime(obj, x, *args):
184
12
  return {
185
13
  "current": 0.268587,
@@ -293,134 +121,74 @@ TIME_MODULE = {
293
121
  "set_timezone": None,
294
122
  }
295
123
 
296
-
297
- class FakeSmartProtocol(SmartProtocol):
298
- def __init__(self, info):
299
- super().__init__(
300
- transport=FakeSmartTransport(info),
301
- )
302
-
303
- async def query(self, request, retry_count: int = 3):
304
- """Implement query here so can still patch SmartProtocol.query."""
305
- resp_dict = await self._query(request, retry_count)
306
- return resp_dict
307
-
308
-
309
- class FakeSmartTransport(BaseTransport):
310
- def __init__(self, info):
311
- super().__init__(
312
- config=DeviceConfig(
313
- "127.0.0.123",
314
- credentials=Credentials(
315
- username="dummy_user",
316
- password="dummy_password", # noqa: S106
317
- ),
318
- ),
319
- )
320
- self.info = info
321
- self.components = {
322
- comp["id"]: comp["ver_code"]
323
- for comp in self.info["component_nego"]["component_list"]
324
- }
325
-
326
- @property
327
- def default_port(self):
328
- """Default port for the transport."""
329
- return 80
330
-
331
- @property
332
- def credentials_hash(self):
333
- """The hashed credentials used by the transport."""
334
- return self._credentials.username + self._credentials.password + "hash"
335
-
336
- FIXTURE_MISSING_MAP = {
337
- "get_wireless_scan_info": ("wireless", {"ap_list": [], "wep_supported": False}),
124
+ CLOUD_MODULE = {
125
+ "get_info": {
126
+ "username": "",
127
+ "server": "devs.tplinkcloud.com",
128
+ "binded": 0,
129
+ "cld_connection": 0,
130
+ "illegalType": -1,
131
+ "stopConnect": -1,
132
+ "tcspStatus": -1,
133
+ "fwDlPage": "",
134
+ "tcspInfo": "",
135
+ "fwNotifyType": 0,
338
136
  }
137
+ }
339
138
 
340
- async def send(self, request: str):
341
- request_dict = json_loads(request)
342
- method = request_dict["method"]
343
- params = request_dict["params"]
344
- if method == "multipleRequest":
345
- responses = []
346
- for request in params["requests"]:
347
- response = self._send_request(request) # type: ignore[arg-type]
348
- response["method"] = request["method"] # type: ignore[index]
349
- responses.append(response)
350
- return {"result": {"responses": responses}, "error_code": 0}
351
- else:
352
- return self._send_request(request_dict)
353
-
354
- def _send_request(self, request_dict: dict):
355
- method = request_dict["method"]
356
- params = request_dict["params"]
357
-
358
- info = self.info
359
- if method == "control_child":
360
- device_id = params.get("device_id")
361
- request_data = params.get("requestData")
362
-
363
- child_method = request_data.get("method")
364
- child_params = request_data.get("params")
365
-
366
- children = info["get_child_device_list"]["child_device_list"]
367
-
368
- for child in children:
369
- if child["device_id"] == device_id:
370
- info = child
371
- break
372
-
373
- # We only support get & set device info for now.
374
- if child_method == "get_device_info":
375
- return {"result": info, "error_code": 0}
376
- elif child_method == "set_device_info":
377
- info.update(child_params)
378
- return {"error_code": 0}
379
-
380
- raise NotImplementedError(
381
- "Method %s not implemented for children" % child_method
382
- )
383
139
 
384
- if method == "component_nego" or method[:4] == "get_":
385
- if method in info:
386
- return {"result": info[method], "error_code": 0}
387
- elif (
388
- missing_result := self.FIXTURE_MISSING_MAP.get(method)
389
- ) and missing_result[0] in self.components:
390
- warnings.warn(
391
- UserWarning(
392
- f"Fixture missing expected method {method}, try to regenerate"
393
- ),
394
- stacklevel=1,
395
- )
396
- return {"result": missing_result[1], "error_code": 0}
397
- else:
398
- raise SmartDeviceException(f"Fixture doesn't support {method}")
399
- elif method == "set_qs_info":
400
- return {"error_code": 0}
401
- elif method[:4] == "set_":
402
- target_method = f"get_{method[4:]}"
403
- info[target_method].update(params)
404
- return {"error_code": 0}
140
+ AMBIENT_MODULE = {
141
+ "get_current_brt": {"value": 26, "err_code": 0},
142
+ "get_config": {
143
+ "devs": [
144
+ {
145
+ "hw_id": 0,
146
+ "enable": 0,
147
+ "dark_index": 1,
148
+ "min_adc": 0,
149
+ "max_adc": 2450,
150
+ "level_array": [
151
+ {"name": "cloudy", "adc": 490, "value": 20},
152
+ {"name": "overcast", "adc": 294, "value": 12},
153
+ {"name": "dawn", "adc": 222, "value": 9},
154
+ {"name": "twilight", "adc": 222, "value": 9},
155
+ {"name": "total darkness", "adc": 111, "value": 4},
156
+ {"name": "custom", "adc": 2400, "value": 97},
157
+ ],
158
+ }
159
+ ],
160
+ "ver": "1.0",
161
+ "err_code": 0,
162
+ },
163
+ }
405
164
 
406
- async def close(self) -> None:
407
- pass
408
165
 
409
- async def reset(self) -> None:
410
- pass
166
+ MOTION_MODULE = {
167
+ "get_config": {
168
+ "enable": 0,
169
+ "version": "1.0",
170
+ "trigger_index": 2,
171
+ "cold_time": 60000,
172
+ "min_adc": 0,
173
+ "max_adc": 4095,
174
+ "array": [80, 50, 20, 0],
175
+ "err_code": 0,
176
+ }
177
+ }
411
178
 
412
179
 
413
- class FakeTransportProtocol(IotProtocol):
180
+ class FakeIotProtocol(IotProtocol):
414
181
  def __init__(self, info):
415
182
  super().__init__(
416
183
  transport=XorTransport(
417
184
  config=DeviceConfig("127.0.0.123"),
418
185
  )
419
186
  )
187
+ info = copy.deepcopy(info)
420
188
  self.discovery_data = info
421
189
  self.writer = None
422
190
  self.reader = None
423
- proto = copy.deepcopy(FakeTransportProtocol.baseproto)
191
+ proto = copy.deepcopy(FakeIotProtocol.baseproto)
424
192
 
425
193
  for target in info:
426
194
  # print("target %s" % target)
@@ -534,9 +302,9 @@ class FakeTransportProtocol(IotProtocol):
534
302
 
535
303
  def set_preferred_state(self, new_state, *args):
536
304
  """Implement set_preferred_state."""
537
- self.proto["system"]["get_sysinfo"]["preferred_state"][
538
- new_state["index"]
539
- ] = new_state
305
+ self.proto["system"]["get_sysinfo"]["preferred_state"][new_state["index"]] = (
306
+ new_state
307
+ )
540
308
 
541
309
  def light_state(self, x, *args):
542
310
  light_state = self.proto["system"]["get_sysinfo"]["light_state"]
@@ -593,8 +361,10 @@ class FakeTransportProtocol(IotProtocol):
593
361
  "set_brightness": set_hs220_brightness,
594
362
  "set_dimmer_transition": set_hs220_dimmer_transition,
595
363
  },
596
- "smartlife.iot.LAS": {},
597
- "smartlife.iot.PIR": {},
364
+ "smartlife.iot.LAS": AMBIENT_MODULE,
365
+ "smartlife.iot.PIR": MOTION_MODULE,
366
+ "cnCloud": CLOUD_MODULE,
367
+ "smartlife.iot.common.cloud": CLOUD_MODULE,
598
368
  }
599
369
 
600
370
  async def query(self, request, port=9999):
@@ -643,4 +413,4 @@ class FakeTransportProtocol(IotProtocol):
643
413
  for target in request:
644
414
  response.update(get_response_for_module(target))
645
415
 
646
- return response
416
+ return copy.deepcopy(response)