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
@@ -0,0 +1,77 @@
1
+ """Implementation of temperature module."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Literal
6
+
7
+ from ...feature import Feature
8
+ from ..smartmodule import SmartModule
9
+
10
+ if TYPE_CHECKING:
11
+ from ..smartdevice import SmartDevice
12
+
13
+
14
+ class TemperatureSensor(SmartModule):
15
+ """Implementation of temperature module."""
16
+
17
+ REQUIRED_COMPONENT = "temperature"
18
+ QUERY_GETTER_NAME = "get_comfort_temp_config"
19
+
20
+ def __init__(self, device: SmartDevice, module: str):
21
+ super().__init__(device, module)
22
+ self._add_feature(
23
+ Feature(
24
+ device,
25
+ id="temperature",
26
+ name="Temperature",
27
+ container=self,
28
+ attribute_getter="temperature",
29
+ icon="mdi:thermometer",
30
+ category=Feature.Category.Primary,
31
+ )
32
+ )
33
+ if "current_temp_exception" in device.sys_info:
34
+ self._add_feature(
35
+ Feature(
36
+ device,
37
+ id="temperature_warning",
38
+ name="Temperature warning",
39
+ container=self,
40
+ attribute_getter="temperature_warning",
41
+ type=Feature.Type.BinarySensor,
42
+ icon="mdi:alert",
43
+ category=Feature.Category.Debug,
44
+ )
45
+ )
46
+ self._add_feature(
47
+ Feature(
48
+ device,
49
+ id="temperature_unit",
50
+ name="Temperature unit",
51
+ container=self,
52
+ attribute_getter="temperature_unit",
53
+ attribute_setter="set_temperature_unit",
54
+ type=Feature.Type.Choice,
55
+ choices=["celsius", "fahrenheit"],
56
+ )
57
+ )
58
+ # TODO: use temperature_unit for feature creation
59
+
60
+ @property
61
+ def temperature(self):
62
+ """Return current humidity in percentage."""
63
+ return self._device.sys_info["current_temp"]
64
+
65
+ @property
66
+ def temperature_warning(self) -> bool:
67
+ """Return True if temperature is outside of the wanted range."""
68
+ return self._device.sys_info.get("current_temp_exception", 0) != 0
69
+
70
+ @property
71
+ def temperature_unit(self):
72
+ """Return current temperature unit."""
73
+ return self._device.sys_info["temp_unit"]
74
+
75
+ async def set_temperature_unit(self, unit: Literal["celsius", "fahrenheit"]):
76
+ """Set the device temperature unit."""
77
+ return await self.call("set_temperature_unit", {"temp_unit": unit})
@@ -0,0 +1,57 @@
1
+ """Implementation of time module."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime, timedelta, timezone
6
+ from time import mktime
7
+ from typing import TYPE_CHECKING, cast
8
+
9
+ from ...feature import Feature
10
+ from ..smartmodule import SmartModule
11
+
12
+ if TYPE_CHECKING:
13
+ from ..smartdevice import SmartDevice
14
+
15
+
16
+ class Time(SmartModule):
17
+ """Implementation of device_local_time."""
18
+
19
+ REQUIRED_COMPONENT = "time"
20
+ QUERY_GETTER_NAME = "get_device_time"
21
+
22
+ def __init__(self, device: SmartDevice, module: str):
23
+ super().__init__(device, module)
24
+
25
+ self._add_feature(
26
+ Feature(
27
+ device=device,
28
+ id="time",
29
+ name="Time",
30
+ attribute_getter="time",
31
+ container=self,
32
+ category=Feature.Category.Debug,
33
+ )
34
+ )
35
+
36
+ @property
37
+ def time(self) -> datetime:
38
+ """Return device's current datetime."""
39
+ td = timedelta(minutes=cast(float, self.data.get("time_diff")))
40
+ if self.data.get("region"):
41
+ tz = timezone(td, str(self.data.get("region")))
42
+ else:
43
+ # in case the device returns a blank region this will result in the
44
+ # tzname being a UTC offset
45
+ tz = timezone(td)
46
+ return datetime.fromtimestamp(
47
+ cast(float, self.data.get("timestamp")),
48
+ tz=tz,
49
+ )
50
+
51
+ async def set_time(self, dt: datetime):
52
+ """Set device time."""
53
+ unixtime = mktime(dt.timetuple())
54
+ return await self.call(
55
+ "set_device_time",
56
+ {"timestamp": unixtime, "time_diff": dt.utcoffset(), "region": dt.tzname()},
57
+ )
@@ -0,0 +1,66 @@
1
+ """Implementation of waterleak module."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from enum import Enum
6
+ from typing import TYPE_CHECKING
7
+
8
+ from ...feature import Feature
9
+ from ..smartmodule import SmartModule
10
+
11
+ if TYPE_CHECKING:
12
+ from ..smartdevice import SmartDevice
13
+
14
+
15
+ class WaterleakStatus(Enum):
16
+ """Waterleawk status."""
17
+
18
+ Normal = "normal"
19
+ LeakDetected = "water_leak"
20
+ Drying = "water_dry"
21
+
22
+
23
+ class WaterleakSensor(SmartModule):
24
+ """Implementation of waterleak module."""
25
+
26
+ REQUIRED_COMPONENT = "sensor_alarm"
27
+
28
+ def __init__(self, device: SmartDevice, module: str):
29
+ super().__init__(device, module)
30
+ self._add_feature(
31
+ Feature(
32
+ device,
33
+ id="water_leak",
34
+ name="Water leak",
35
+ container=self,
36
+ attribute_getter="status",
37
+ icon="mdi:water",
38
+ category=Feature.Category.Debug,
39
+ )
40
+ )
41
+ self._add_feature(
42
+ Feature(
43
+ device,
44
+ id="water_alert",
45
+ name="Water alert",
46
+ container=self,
47
+ attribute_getter="alert",
48
+ icon="mdi:water-alert",
49
+ category=Feature.Category.Primary,
50
+ )
51
+ )
52
+
53
+ def query(self) -> dict:
54
+ """Query to execute during the update cycle."""
55
+ # Water leak information is contained in the main device info response.
56
+ return {}
57
+
58
+ @property
59
+ def status(self) -> WaterleakStatus:
60
+ """Return current humidity in percentage."""
61
+ return WaterleakStatus(self._device.sys_info["water_leak_status"])
62
+
63
+ @property
64
+ def alert(self) -> bool:
65
+ """Return true if alarm is active."""
66
+ return self._device.sys_info["in_alarm"]
@@ -0,0 +1,65 @@
1
+ """Child device implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+
7
+ from ..device_type import DeviceType
8
+ from ..deviceconfig import DeviceConfig
9
+ from ..smartprotocol import SmartProtocol, _ChildProtocolWrapper
10
+ from .smartdevice import SmartDevice
11
+
12
+ _LOGGER = logging.getLogger(__name__)
13
+
14
+
15
+ class SmartChildDevice(SmartDevice):
16
+ """Presentation of a child device.
17
+
18
+ This wraps the protocol communications and sets internal data for the child.
19
+ """
20
+
21
+ def __init__(
22
+ self,
23
+ parent: SmartDevice,
24
+ info,
25
+ component_info,
26
+ config: DeviceConfig | None = None,
27
+ protocol: SmartProtocol | None = None,
28
+ ) -> None:
29
+ super().__init__(parent.host, config=parent.config, protocol=parent.protocol)
30
+ self._parent = parent
31
+ self._update_internal_state(info)
32
+ self._components = component_info
33
+ self._id = info["device_id"]
34
+ self.protocol = _ChildProtocolWrapper(self._id, parent.protocol)
35
+
36
+ async def update(self, update_children: bool = True):
37
+ """Noop update. The parent updates our internals."""
38
+
39
+ @classmethod
40
+ async def create(cls, parent: SmartDevice, child_info, child_components):
41
+ """Create a child device based on device info and component listing."""
42
+ child: SmartChildDevice = cls(parent, child_info, child_components)
43
+ await child._initialize_modules()
44
+ return child
45
+
46
+ @property
47
+ def device_type(self) -> DeviceType:
48
+ """Return child device type."""
49
+ child_device_map = {
50
+ "plug.powerstrip.sub-plug": DeviceType.Plug,
51
+ "subg.trigger.contact-sensor": DeviceType.Sensor,
52
+ "subg.trigger.temp-hmdt-sensor": DeviceType.Sensor,
53
+ "subg.trigger.water-leak-sensor": DeviceType.Sensor,
54
+ "kasa.switch.outlet.sub-fan": DeviceType.Fan,
55
+ "kasa.switch.outlet.sub-dimmer": DeviceType.Dimmer,
56
+ "subg.trv": DeviceType.Thermostat,
57
+ }
58
+ dev_type = child_device_map.get(self.sys_info["category"])
59
+ if dev_type is None:
60
+ _LOGGER.warning("Unknown child device type, please open issue ")
61
+ dev_type = DeviceType.Unknown
62
+ return dev_type
63
+
64
+ def __repr__(self):
65
+ return f"<{self.device_type} {self.alias} ({self.model}) of {self._parent}>"