python-kasa 0.7.0.dev5__py3-none-any.whl → 0.7.0.2__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 (64) hide show
  1. kasa/aestransport.py +13 -4
  2. kasa/cli.py +60 -45
  3. kasa/device.py +110 -2
  4. kasa/discover.py +2 -1
  5. kasa/exceptions.py +10 -0
  6. kasa/feature.py +88 -11
  7. kasa/httpclient.py +1 -1
  8. kasa/interfaces/energy.py +6 -0
  9. kasa/interfaces/light.py +61 -1
  10. kasa/interfaces/lighteffect.py +41 -1
  11. kasa/interfaces/lightpreset.py +70 -2
  12. kasa/iot/iotdevice.py +6 -1
  13. kasa/iot/iotstrip.py +23 -8
  14. kasa/iot/modules/lightpreset.py +2 -1
  15. kasa/module.py +42 -1
  16. kasa/smart/effects.py +25 -0
  17. kasa/smart/modules/__init__.py +2 -0
  18. kasa/smart/modules/alarm.py +1 -0
  19. kasa/smart/modules/autooff.py +3 -1
  20. kasa/smart/modules/brightness.py +14 -1
  21. kasa/smart/modules/childdevice.py +39 -1
  22. kasa/smart/modules/firmware.py +4 -1
  23. kasa/smart/modules/frostprotection.py +0 -22
  24. kasa/smart/modules/humiditysensor.py +1 -0
  25. kasa/smart/modules/led.py +1 -1
  26. kasa/smart/modules/lighteffect.py +70 -6
  27. kasa/smart/modules/lightpreset.py +2 -1
  28. kasa/smart/modules/lightstripeffect.py +38 -8
  29. kasa/smart/modules/lighttransition.py +101 -55
  30. kasa/smart/modules/reportmode.py +2 -0
  31. kasa/smart/modules/temperaturecontrol.py +3 -2
  32. kasa/smart/modules/temperaturesensor.py +3 -2
  33. kasa/smart/modules/time.py +3 -2
  34. kasa/smart/modules/waterleaksensor.py +2 -0
  35. kasa/smart/smartdevice.py +10 -5
  36. kasa/smartprotocol.py +42 -6
  37. kasa/tests/device_fixtures.py +9 -3
  38. kasa/tests/discovery_fixtures.py +6 -2
  39. kasa/tests/fakeprotocol_smart.py +73 -4
  40. kasa/tests/fixtureinfo.py +21 -3
  41. kasa/tests/smart/modules/test_firmware.py +12 -1
  42. kasa/tests/smart/modules/test_light_effect.py +42 -0
  43. kasa/tests/smart/modules/test_light_strip_effect.py +101 -0
  44. kasa/tests/smart/modules/test_lighttransition.py +80 -0
  45. kasa/tests/test_aestransport.py +27 -0
  46. kasa/tests/test_childdevice.py +21 -1
  47. kasa/tests/test_cli.py +18 -3
  48. kasa/tests/test_common_modules.py +9 -5
  49. kasa/tests/test_device.py +2 -1
  50. kasa/tests/test_device_factory.py +35 -17
  51. kasa/tests/test_emeter.py +8 -8
  52. kasa/tests/test_feature.py +6 -2
  53. kasa/tests/test_httpclient.py +2 -2
  54. kasa/tests/test_iotdevice.py +5 -4
  55. kasa/tests/test_readme_examples.py +59 -0
  56. kasa/tests/test_smartdevice.py +4 -3
  57. kasa/tests/test_smartprotocol.py +109 -7
  58. kasa/tests/test_strip.py +15 -2
  59. kasa/xortransport.py +3 -3
  60. {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.2.dist-info}/METADATA +102 -129
  61. {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.2.dist-info}/RECORD +64 -62
  62. {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.2.dist-info}/LICENSE +0 -0
  63. {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.2.dist-info}/WHEEL +0 -0
  64. {python_kasa-0.7.0.dev5.dist-info → python_kasa-0.7.0.2.dist-info}/entry_points.txt +0 -0
@@ -3,14 +3,16 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import base64
6
+ import binascii
7
+ import contextlib
6
8
  import copy
7
9
  from typing import Any
8
10
 
9
- from ...interfaces.lighteffect import LightEffect as LightEffectInterface
10
- from ..smartmodule import SmartModule
11
+ from ..effects import SmartLightEffect
12
+ from ..smartmodule import Module, SmartModule
11
13
 
12
14
 
13
- class LightEffect(SmartModule, LightEffectInterface):
15
+ class LightEffect(SmartModule, SmartLightEffect):
14
16
  """Implementation of dynamic light effects."""
15
17
 
16
18
  REQUIRED_COMPONENT = "light_effect"
@@ -36,8 +38,11 @@ class LightEffect(SmartModule, LightEffectInterface):
36
38
  # If the name has not been edited scene_name will be an empty string
37
39
  effect["scene_name"] = self.AVAILABLE_BULB_EFFECTS[effect["id"]]
38
40
  else:
39
- # Otherwise it will be b64 encoded
40
- effect["scene_name"] = base64.b64decode(effect["scene_name"]).decode()
41
+ # Otherwise it might be b64 encoded or raw string
42
+ with contextlib.suppress(binascii.Error):
43
+ effect["scene_name"] = base64.b64decode(
44
+ effect["scene_name"]
45
+ ).decode()
41
46
 
42
47
  self._effect_state_list = effects
43
48
  self._effect_list = [self.LIGHT_EFFECTS_OFF]
@@ -77,6 +82,8 @@ class LightEffect(SmartModule, LightEffectInterface):
77
82
  ) -> None:
78
83
  """Set an effect for the device.
79
84
 
85
+ Calling this will modify the brightness of the effect on the device.
86
+
80
87
  The device doesn't store an active effect while not enabled so store locally.
81
88
  """
82
89
  if effect != self.LIGHT_EFFECTS_OFF and effect not in self._scenes_names_to_id:
@@ -90,7 +97,64 @@ class LightEffect(SmartModule, LightEffectInterface):
90
97
  if enable:
91
98
  effect_id = self._scenes_names_to_id[effect]
92
99
  params["id"] = effect_id
93
- return await self.call("set_dynamic_light_effect_rule_enable", params)
100
+
101
+ # We set the wanted brightness before activating the effect
102
+ brightness_module = self._device.modules[Module.Brightness]
103
+ brightness = (
104
+ brightness if brightness is not None else brightness_module.brightness
105
+ )
106
+ await self.set_brightness(brightness, effect_id=effect_id)
107
+
108
+ await self.call("set_dynamic_light_effect_rule_enable", params)
109
+
110
+ @property
111
+ def is_active(self) -> bool:
112
+ """Return True if effect is active."""
113
+ return bool(self._device._info["dynamic_light_effect_enable"])
114
+
115
+ def _get_effect_data(self, effect_id: str | None = None) -> dict[str, Any]:
116
+ """Return effect data for the *effect_id*.
117
+
118
+ If *effect_id* is None, return the data for active effect.
119
+ """
120
+ if effect_id is None:
121
+ effect_id = self.data["current_rule_id"]
122
+
123
+ return self._effect_state_list[effect_id]
124
+
125
+ @property
126
+ def brightness(self) -> int:
127
+ """Return effect brightness."""
128
+ first_color_status = self._get_effect_data()["color_status_list"][0]
129
+ brightness = first_color_status[0]
130
+
131
+ return brightness
132
+
133
+ async def set_brightness(
134
+ self,
135
+ brightness: int,
136
+ *,
137
+ transition: int | None = None,
138
+ effect_id: str | None = None,
139
+ ):
140
+ """Set effect brightness."""
141
+ new_effect = self._get_effect_data(effect_id=effect_id).copy()
142
+
143
+ def _replace_brightness(data, new_brightness):
144
+ """Replace brightness.
145
+
146
+ The first element is the brightness, the rest are unknown.
147
+ [[33, 0, 0, 2700], [33, 321, 99, 0], [33, 196, 99, 0], .. ]
148
+ """
149
+ return [new_brightness, data[1], data[2], data[3]]
150
+
151
+ new_color_status_list = [
152
+ _replace_brightness(state, brightness)
153
+ for state in new_effect["color_status_list"]
154
+ ]
155
+ new_effect["color_status_list"] = new_color_status_list
156
+
157
+ return await self.call("edit_dynamic_light_effect_rule", new_effect)
94
158
 
95
159
  async def set_custom_effect(
96
160
  self,
@@ -2,8 +2,9 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from collections.abc import Sequence
5
6
  from dataclasses import asdict
6
- from typing import TYPE_CHECKING, Sequence
7
+ from typing import TYPE_CHECKING
7
8
 
8
9
  from ...interfaces import LightPreset as LightPresetInterface
9
10
  from ...interfaces import LightState
@@ -4,15 +4,14 @@ from __future__ import annotations
4
4
 
5
5
  from typing import TYPE_CHECKING
6
6
 
7
- from ...interfaces.lighteffect import LightEffect as LightEffectInterface
8
- from ..effects import EFFECT_MAPPING, EFFECT_NAMES
9
- from ..smartmodule import SmartModule
7
+ from ..effects import EFFECT_MAPPING, EFFECT_NAMES, SmartLightEffect
8
+ from ..smartmodule import Module, SmartModule
10
9
 
11
10
  if TYPE_CHECKING:
12
11
  from ..smartdevice import SmartDevice
13
12
 
14
13
 
15
- class LightStripEffect(SmartModule, LightEffectInterface):
14
+ class LightStripEffect(SmartModule, SmartLightEffect):
16
15
  """Implementation of dynamic light effects."""
17
16
 
18
17
  REQUIRED_COMPONENT = "light_strip_lighting_effect"
@@ -22,6 +21,7 @@ class LightStripEffect(SmartModule, LightEffectInterface):
22
21
  effect_list = [self.LIGHT_EFFECTS_OFF]
23
22
  effect_list.extend(EFFECT_NAMES)
24
23
  self._effect_list = effect_list
24
+ self._effect_mapping = EFFECT_MAPPING
25
25
 
26
26
  @property
27
27
  def name(self) -> str:
@@ -53,6 +53,28 @@ class LightStripEffect(SmartModule, LightEffectInterface):
53
53
  return name
54
54
  return self.LIGHT_EFFECTS_OFF
55
55
 
56
+ @property
57
+ def is_active(self) -> bool:
58
+ """Return if effect is active."""
59
+ eff = self.data["lighting_effect"]
60
+ # softAP has enable=1, but brightness 0 which fails on tests
61
+ return bool(eff["enable"]) and eff["name"] in self._effect_list
62
+
63
+ @property
64
+ def brightness(self) -> int:
65
+ """Return effect brightness."""
66
+ eff = self.data["lighting_effect"]
67
+ return eff["brightness"]
68
+
69
+ async def set_brightness(self, brightness: int, *, transition: int | None = None):
70
+ """Set effect brightness."""
71
+ if brightness <= 0:
72
+ return await self.set_effect(self.LIGHT_EFFECTS_OFF)
73
+
74
+ # Need to pass bAdjusted to keep the existing effect running
75
+ eff = {"brightness": brightness, "bAdjusted": True}
76
+ return await self.set_custom_effect(eff)
77
+
56
78
  @property
57
79
  def effect_list(self) -> list[str]:
58
80
  """Return built-in effects list.
@@ -81,16 +103,24 @@ class LightStripEffect(SmartModule, LightEffectInterface):
81
103
  :param int brightness: The wanted brightness
82
104
  :param int transition: The wanted transition time
83
105
  """
106
+ brightness_module = self._device.modules[Module.Brightness]
84
107
  if effect == self.LIGHT_EFFECTS_OFF:
85
- effect_dict = dict(self.data["lighting_effect"])
86
- effect_dict["enable"] = 0
87
- elif effect not in EFFECT_MAPPING:
108
+ state = self._device.modules[Module.Light].state
109
+ await self._device.modules[Module.Light].set_state(state)
110
+ return
111
+
112
+ if effect not in self._effect_mapping:
88
113
  raise ValueError(f"The effect {effect} is not a built in effect.")
89
114
  else:
90
- effect_dict = EFFECT_MAPPING[effect]
115
+ effect_dict = self._effect_mapping[effect]
91
116
 
117
+ # Use explicitly given brightness
92
118
  if brightness is not None:
93
119
  effect_dict["brightness"] = brightness
120
+ # Fall back to brightness reported by the brightness module
121
+ elif brightness_module.brightness:
122
+ effect_dict["brightness"] = brightness_module.brightness
123
+
94
124
  if transition is not None:
95
125
  effect_dict["transition"] = transition
96
126
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
5
+ from typing import TYPE_CHECKING, TypedDict
6
6
 
7
7
  from ...exceptions import KasaException
8
8
  from ...feature import Feature
@@ -12,6 +12,12 @@ if TYPE_CHECKING:
12
12
  from ..smartdevice import SmartDevice
13
13
 
14
14
 
15
+ class _State(TypedDict):
16
+ duration: int
17
+ enable: bool
18
+ max_duration: int
19
+
20
+
15
21
  class LightTransition(SmartModule):
16
22
  """Implementation of gradual on/off."""
17
23
 
@@ -19,14 +25,30 @@ class LightTransition(SmartModule):
19
25
  QUERY_GETTER_NAME = "get_on_off_gradually_info"
20
26
  MAXIMUM_DURATION = 60
21
27
 
28
+ # Key in sysinfo that indicates state can be retrieved from there.
29
+ # Usually only for child lights, i.e, ks240.
30
+ SYS_INFO_STATE_KEYS = (
31
+ "gradually_on_mode",
32
+ "gradually_off_mode",
33
+ "fade_on_time",
34
+ "fade_off_time",
35
+ )
36
+
37
+ _on_state: _State
38
+ _off_state: _State
39
+ _enabled: bool
40
+
22
41
  def __init__(self, device: SmartDevice, module: str):
23
42
  super().__init__(device, module)
24
- self._create_features()
43
+ self._state_in_sysinfo = all(
44
+ key in device.sys_info for key in self.SYS_INFO_STATE_KEYS
45
+ )
46
+ self._supports_on_and_off: bool = self.supported_version > 1
25
47
 
26
- def _create_features(self):
27
- """Create features based on the available version."""
48
+ def _initialize_features(self):
49
+ """Initialize features."""
28
50
  icon = "mdi:transition"
29
- if self.supported_version == 1:
51
+ if not self._supports_on_and_off:
30
52
  self._add_feature(
31
53
  Feature(
32
54
  device=self._device,
@@ -34,16 +56,12 @@ class LightTransition(SmartModule):
34
56
  id="smooth_transitions",
35
57
  name="Smooth transitions",
36
58
  icon=icon,
37
- attribute_getter="enabled_v1",
38
- attribute_setter="set_enabled_v1",
59
+ attribute_getter="enabled",
60
+ attribute_setter="set_enabled",
39
61
  type=Feature.Type.Switch,
40
62
  )
41
63
  )
42
- elif self.supported_version >= 2:
43
- # v2 adds separate on & off states
44
- # v3 adds max_duration
45
- # TODO: note, hardcoding the maximums for now as the features get
46
- # initialized before the first update.
64
+ else:
47
65
  self._add_feature(
48
66
  Feature(
49
67
  self._device,
@@ -54,9 +72,9 @@ class LightTransition(SmartModule):
54
72
  attribute_setter="set_turn_on_transition",
55
73
  icon=icon,
56
74
  type=Feature.Type.Number,
57
- maximum_value=self.MAXIMUM_DURATION,
75
+ maximum_value=self._turn_on_transition_max,
58
76
  )
59
- ) # self._turn_on_transition_max
77
+ )
60
78
  self._add_feature(
61
79
  Feature(
62
80
  self._device,
@@ -67,38 +85,74 @@ class LightTransition(SmartModule):
67
85
  attribute_setter="set_turn_off_transition",
68
86
  icon=icon,
69
87
  type=Feature.Type.Number,
70
- maximum_value=self.MAXIMUM_DURATION,
88
+ maximum_value=self._turn_off_transition_max,
71
89
  )
72
- ) # self._turn_off_transition_max
73
-
74
- @property
75
- def _turn_on(self):
76
- """Internal getter for turn on settings."""
77
- if "on_state" not in self.data:
78
- raise KasaException(
79
- f"Unsupported for {self.REQUIRED_COMPONENT} v{self.supported_version}"
80
90
  )
81
91
 
82
- return self.data["on_state"]
83
-
84
- @property
85
- def _turn_off(self):
86
- """Internal getter for turn off settings."""
87
- if "off_state" not in self.data:
92
+ def _post_update_hook(self) -> None:
93
+ """Update the states."""
94
+ # Assumes any device with state in sysinfo supports on and off and
95
+ # has maximum values for both.
96
+ # v2 adds separate on & off states
97
+ # v3 adds max_duration except for ks240 which is v2 but supports it
98
+ if not self._supports_on_and_off:
99
+ self._enabled = self.data["enable"]
100
+ return
101
+
102
+ if self._state_in_sysinfo:
103
+ on_max = self._device.sys_info.get(
104
+ "max_fade_on_time", self.MAXIMUM_DURATION
105
+ )
106
+ off_max = self._device.sys_info.get(
107
+ "max_fade_off_time", self.MAXIMUM_DURATION
108
+ )
109
+ on_enabled = bool(self._device.sys_info["gradually_on_mode"])
110
+ off_enabled = bool(self._device.sys_info["gradually_off_mode"])
111
+ on_duration = self._device.sys_info["fade_on_time"]
112
+ off_duration = self._device.sys_info["fade_off_time"]
113
+ elif (on_state := self.data.get("on_state")) and (
114
+ off_state := self.data.get("off_state")
115
+ ):
116
+ on_max = on_state.get("max_duration", self.MAXIMUM_DURATION)
117
+ off_max = off_state.get("max_duration", self.MAXIMUM_DURATION)
118
+ on_enabled = on_state["enable"]
119
+ off_enabled = off_state["enable"]
120
+ on_duration = on_state["duration"]
121
+ off_duration = off_state["duration"]
122
+ else:
88
123
  raise KasaException(
89
124
  f"Unsupported for {self.REQUIRED_COMPONENT} v{self.supported_version}"
90
125
  )
91
126
 
92
- return self.data["off_state"]
93
-
94
- async def set_enabled_v1(self, enable: bool):
127
+ self._enabled = on_enabled or off_enabled
128
+ self._on_state = {
129
+ "duration": on_duration,
130
+ "enable": on_enabled,
131
+ "max_duration": on_max,
132
+ }
133
+ self._off_state = {
134
+ "duration": off_duration,
135
+ "enable": off_enabled,
136
+ "max_duration": off_max,
137
+ }
138
+
139
+ async def set_enabled(self, enable: bool):
95
140
  """Enable gradual on/off."""
96
- return await self.call("set_on_off_gradually_info", {"enable": enable})
141
+ if not self._supports_on_and_off:
142
+ return await self.call("set_on_off_gradually_info", {"enable": enable})
143
+ else:
144
+ on = await self.call(
145
+ "set_on_off_gradually_info", {"on_state": {"enable": enable}}
146
+ )
147
+ off = await self.call(
148
+ "set_on_off_gradually_info", {"off_state": {"enable": enable}}
149
+ )
150
+ return {**on, **off}
97
151
 
98
152
  @property
99
- def enabled_v1(self) -> bool:
153
+ def enabled(self) -> bool:
100
154
  """Return True if gradual on/off is enabled."""
101
- return bool(self.data["enable"])
155
+ return self._enabled
102
156
 
103
157
  @property
104
158
  def turn_on_transition(self) -> int:
@@ -106,15 +160,13 @@ class LightTransition(SmartModule):
106
160
 
107
161
  Available only from v2.
108
162
  """
109
- if "fade_on_time" in self._device.sys_info:
110
- return self._device.sys_info["fade_on_time"]
111
- return self._turn_on["duration"]
163
+ return self._on_state["duration"] if self._on_state["enable"] else 0
112
164
 
113
165
  @property
114
166
  def _turn_on_transition_max(self) -> int:
115
167
  """Maximum turn on duration."""
116
168
  # v3 added max_duration, we default to 60 when it's not available
117
- return self._turn_on.get("max_duration", 60)
169
+ return self._on_state["max_duration"]
118
170
 
119
171
  async def set_turn_on_transition(self, seconds: int):
120
172
  """Set turn on transition in seconds.
@@ -129,12 +181,12 @@ class LightTransition(SmartModule):
129
181
  if seconds <= 0:
130
182
  return await self.call(
131
183
  "set_on_off_gradually_info",
132
- {"on_state": {**self._turn_on, "enable": False}},
184
+ {"on_state": {"enable": False}},
133
185
  )
134
186
 
135
187
  return await self.call(
136
188
  "set_on_off_gradually_info",
137
- {"on_state": {**self._turn_on, "duration": seconds}},
189
+ {"on_state": {"enable": True, "duration": seconds}},
138
190
  )
139
191
 
140
192
  @property
@@ -143,15 +195,13 @@ class LightTransition(SmartModule):
143
195
 
144
196
  Available only from v2.
145
197
  """
146
- if "fade_off_time" in self._device.sys_info:
147
- return self._device.sys_info["fade_off_time"]
148
- return self._turn_off["duration"]
198
+ return self._off_state["duration"] if self._off_state["enable"] else 0
149
199
 
150
200
  @property
151
201
  def _turn_off_transition_max(self) -> int:
152
202
  """Maximum turn on duration."""
153
203
  # v3 added max_duration, we default to 60 when it's not available
154
- return self._turn_off.get("max_duration", 60)
204
+ return self._off_state["max_duration"]
155
205
 
156
206
  async def set_turn_off_transition(self, seconds: int):
157
207
  """Set turn on transition in seconds.
@@ -166,28 +216,24 @@ class LightTransition(SmartModule):
166
216
  if seconds <= 0:
167
217
  return await self.call(
168
218
  "set_on_off_gradually_info",
169
- {"off_state": {**self._turn_off, "enable": False}},
219
+ {"off_state": {"enable": False}},
170
220
  )
171
221
 
172
222
  return await self.call(
173
223
  "set_on_off_gradually_info",
174
- {"off_state": {**self._turn_on, "duration": seconds}},
224
+ {"off_state": {"enable": True, "duration": seconds}},
175
225
  )
176
226
 
177
227
  def query(self) -> dict:
178
228
  """Query to execute during the update cycle."""
179
229
  # Some devices have the required info in the device info.
180
- if "gradually_on_mode" in self._device.sys_info:
230
+ if self._state_in_sysinfo:
181
231
  return {}
182
232
  else:
183
233
  return {self.QUERY_GETTER_NAME: None}
184
234
 
185
235
  async def _check_supported(self):
186
- """Additional check to see if the module is supported by the device.
187
-
188
- Parent devices that report components of children such as ks240 will not have
189
- the brightness value is sysinfo.
190
- """
191
- # Look in _device.sys_info here because self.data is either sys_info or
192
- # get_preset_rules depending on whether it's a child device or not.
236
+ """Additional check to see if the module is supported by the device."""
237
+ # For devices that report child components on the parent that are not
238
+ # actually supported by the parent.
193
239
  return "brightness" in self._device.sys_info
@@ -26,7 +26,9 @@ class ReportMode(SmartModule):
26
26
  name="Report interval",
27
27
  container=self,
28
28
  attribute_getter="report_interval",
29
+ unit="s",
29
30
  category=Feature.Category.Debug,
31
+ type=Feature.Type.Sensor,
30
32
  )
31
33
  )
32
34
 
@@ -79,11 +79,12 @@ class TemperatureControl(SmartModule):
79
79
  self._add_feature(
80
80
  Feature(
81
81
  device,
82
- id="mode",
83
- name="Mode",
82
+ id="thermostat_mode",
83
+ name="Thermostat mode",
84
84
  container=self,
85
85
  attribute_getter="mode",
86
86
  category=Feature.Category.Primary,
87
+ type=Feature.Type.Sensor,
87
88
  )
88
89
  )
89
90
 
@@ -28,6 +28,8 @@ class TemperatureSensor(SmartModule):
28
28
  attribute_getter="temperature",
29
29
  icon="mdi:thermometer",
30
30
  category=Feature.Category.Primary,
31
+ unit_getter="temperature_unit",
32
+ type=Feature.Type.Sensor,
31
33
  )
32
34
  )
33
35
  if "current_temp_exception" in device.sys_info:
@@ -55,7 +57,6 @@ class TemperatureSensor(SmartModule):
55
57
  choices=["celsius", "fahrenheit"],
56
58
  )
57
59
  )
58
- # TODO: use temperature_unit for feature creation
59
60
 
60
61
  @property
61
62
  def temperature(self):
@@ -68,7 +69,7 @@ class TemperatureSensor(SmartModule):
68
69
  return self._device.sys_info.get("current_temp_exception", 0) != 0
69
70
 
70
71
  @property
71
- def temperature_unit(self):
72
+ def temperature_unit(self) -> Literal["celsius", "fahrenheit"]:
72
73
  """Return current temperature unit."""
73
74
  return self._device.sys_info["temp_unit"]
74
75
 
@@ -25,11 +25,12 @@ class Time(SmartModule):
25
25
  self._add_feature(
26
26
  Feature(
27
27
  device=device,
28
- id="time",
29
- name="Time",
28
+ id="device_time",
29
+ name="Device time",
30
30
  attribute_getter="time",
31
31
  container=self,
32
32
  category=Feature.Category.Debug,
33
+ type=Feature.Type.Sensor,
33
34
  )
34
35
  )
35
36
 
@@ -36,6 +36,7 @@ class WaterleakSensor(SmartModule):
36
36
  attribute_getter="status",
37
37
  icon="mdi:water",
38
38
  category=Feature.Category.Debug,
39
+ type=Feature.Type.Sensor,
39
40
  )
40
41
  )
41
42
  self._add_feature(
@@ -47,6 +48,7 @@ class WaterleakSensor(SmartModule):
47
48
  attribute_getter="alert",
48
49
  icon="mdi:water-alert",
49
50
  category=Feature.Category.Primary,
51
+ type=Feature.Type.BinarySensor,
50
52
  )
51
53
  )
52
54
 
kasa/smart/smartdevice.py CHANGED
@@ -4,8 +4,9 @@ from __future__ import annotations
4
4
 
5
5
  import base64
6
6
  import logging
7
+ from collections.abc import Mapping, Sequence
7
8
  from datetime import datetime, timedelta, timezone
8
- from typing import TYPE_CHECKING, Any, Mapping, Sequence, cast
9
+ from typing import Any, cast
9
10
 
10
11
  from ..aestransport import AesTransport
11
12
  from ..device import Device, WifiNetwork
@@ -97,9 +98,7 @@ class SmartDevice(Device):
97
98
  @property
98
99
  def modules(self) -> ModuleMapping[SmartModule]:
99
100
  """Return the device modules."""
100
- if TYPE_CHECKING: # Needed for python 3.8
101
- return cast(ModuleMapping[SmartModule], self._modules)
102
- return self._modules
101
+ return cast(ModuleMapping[SmartModule], self._modules)
103
102
 
104
103
  def _try_get_response(self, responses: dict, request: str, default=None) -> dict:
105
104
  response = responses.get(request)
@@ -243,6 +242,7 @@ class SmartDevice(Device):
243
242
  name="Device ID",
244
243
  attribute_getter="device_id",
245
244
  category=Feature.Category.Debug,
245
+ type=Feature.Type.Sensor,
246
246
  )
247
247
  )
248
248
  if "device_on" in self._info:
@@ -267,6 +267,7 @@ class SmartDevice(Device):
267
267
  attribute_getter=lambda x: x._info["signal_level"],
268
268
  icon="mdi:signal",
269
269
  category=Feature.Category.Info,
270
+ type=Feature.Type.Sensor,
270
271
  )
271
272
  )
272
273
 
@@ -278,7 +279,9 @@ class SmartDevice(Device):
278
279
  name="RSSI",
279
280
  attribute_getter=lambda x: x._info["rssi"],
280
281
  icon="mdi:signal",
282
+ unit="dBm",
281
283
  category=Feature.Category.Debug,
284
+ type=Feature.Type.Sensor,
282
285
  )
283
286
  )
284
287
 
@@ -291,6 +294,7 @@ class SmartDevice(Device):
291
294
  attribute_getter="ssid",
292
295
  icon="mdi:wifi",
293
296
  category=Feature.Category.Debug,
297
+ type=Feature.Type.Sensor,
294
298
  )
295
299
  )
296
300
 
@@ -317,7 +321,8 @@ class SmartDevice(Device):
317
321
  name="On since",
318
322
  attribute_getter="on_since",
319
323
  icon="mdi:clock",
320
- category=Feature.Category.Info,
324
+ category=Feature.Category.Debug,
325
+ type=Feature.Type.Sensor,
321
326
  )
322
327
  )
323
328