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
kasa/interfaces/light.py CHANGED
@@ -1,4 +1,64 @@
1
- """Module for Device base class."""
1
+ """Interact with a TPLink Light.
2
+
3
+ >>> from kasa import Discover, Module
4
+ >>>
5
+ >>> dev = await Discover.discover_single(
6
+ >>> "127.0.0.3",
7
+ >>> username="user@example.com",
8
+ >>> password="great_password"
9
+ >>> )
10
+ >>> await dev.update()
11
+ >>> print(dev.alias)
12
+ Living Room Bulb
13
+
14
+ Lights, like any other supported devices, can be turned on and off:
15
+
16
+ >>> print(dev.is_on)
17
+ >>> await dev.turn_on()
18
+ >>> await dev.update()
19
+ >>> print(dev.is_on)
20
+ True
21
+
22
+ Get the light module to interact:
23
+
24
+ >>> light = dev.modules[Module.Light]
25
+
26
+ You can use the ``is_``-prefixed properties to check for supported features:
27
+
28
+ >>> light.is_dimmable
29
+ True
30
+ >>> light.is_color
31
+ True
32
+ >>> light.is_variable_color_temp
33
+ True
34
+
35
+ All known bulbs support changing the brightness:
36
+
37
+ >>> light.brightness
38
+ 100
39
+ >>> await light.set_brightness(50)
40
+ >>> await dev.update()
41
+ >>> light.brightness
42
+ 50
43
+
44
+ Bulbs supporting color temperature can be queried for the supported range:
45
+
46
+ >>> light.valid_temperature_range
47
+ ColorTempRange(min=2500, max=6500)
48
+ >>> await light.set_color_temp(3000)
49
+ >>> await dev.update()
50
+ >>> light.color_temp
51
+ 3000
52
+
53
+ Color bulbs can be adjusted by passing hue, saturation and value:
54
+
55
+ >>> await light.set_hsv(180, 100, 80)
56
+ >>> await dev.update()
57
+ >>> light.hsv
58
+ HSV(hue=180, saturation=100, value=80)
59
+
60
+
61
+ """
2
62
 
3
63
  from __future__ import annotations
4
64
 
@@ -1,4 +1,44 @@
1
- """Module for base light effect module."""
1
+ """Interact with a TPLink Light Effect.
2
+
3
+ >>> from kasa import Discover, Module, LightState
4
+ >>>
5
+ >>> dev = await Discover.discover_single(
6
+ >>> "127.0.0.3",
7
+ >>> username="user@example.com",
8
+ >>> password="great_password"
9
+ >>> )
10
+ >>> await dev.update()
11
+ >>> print(dev.alias)
12
+ Living Room Bulb
13
+
14
+ Light effects are accessed via the LightPreset module. To list available presets
15
+
16
+ >>> if dev.modules[Module.Light].has_effects:
17
+ >>> light_effect = dev.modules[Module.LightEffect]
18
+ >>> light_effect.effect_list
19
+ ['Off', 'Party', 'Relax']
20
+
21
+ To view the currently selected effect:
22
+
23
+ >>> light_effect.effect
24
+ Off
25
+
26
+ To activate a light effect:
27
+
28
+ >>> await light_effect.set_effect("Party")
29
+ >>> await dev.update()
30
+ >>> light_effect.effect
31
+ Party
32
+
33
+ If the device supports it you can set custom effects:
34
+
35
+ >>> if light_effect.has_custom_effects:
36
+ >>> effect_list = { "brightness", 50 }
37
+ >>> await light_effect.set_custom_effect(effect_list)
38
+ >>> light_effect.has_custom_effects # The device in this examples does not support \
39
+ custom effects
40
+ False
41
+ """
2
42
 
3
43
  from __future__ import annotations
4
44
 
@@ -1,9 +1,77 @@
1
- """Module for LightPreset base class."""
1
+ """Interact with TPLink Light Presets.
2
+
3
+ >>> from kasa import Discover, Module, LightState
4
+ >>>
5
+ >>> dev = await Discover.discover_single(
6
+ >>> "127.0.0.3",
7
+ >>> username="user@example.com",
8
+ >>> password="great_password"
9
+ >>> )
10
+ >>> await dev.update()
11
+ >>> print(dev.alias)
12
+ Living Room Bulb
13
+
14
+ Light presets are accessed via the LightPreset module. To list available presets
15
+
16
+ >>> light_preset = dev.modules[Module.LightPreset]
17
+ >>> light_preset.preset_list
18
+ ['Not set', 'Light preset 1', 'Light preset 2', 'Light preset 3',\
19
+ 'Light preset 4', 'Light preset 5', 'Light preset 6', 'Light preset 7']
20
+
21
+ To view the currently selected preset:
22
+
23
+ >>> light_preset.preset
24
+ Not set
25
+
26
+ To view the actual light state for the presets:
27
+
28
+ >>> len(light_preset.preset_states_list)
29
+ 7
30
+
31
+ >>> light_preset.preset_states_list[0]
32
+ LightState(light_on=None, brightness=50, hue=0,\
33
+ saturation=100, color_temp=2700, transition=None)
34
+
35
+ To set a preset as active:
36
+
37
+ >>> dev.modules[Module.Light].state # This is only needed to show the example working
38
+ LightState(light_on=True, brightness=100, hue=0,\
39
+ saturation=100, color_temp=2700, transition=None)
40
+ >>> await light_preset.set_preset("Light preset 1")
41
+ >>> await dev.update()
42
+ >>> light_preset.preset
43
+ Light preset 1
44
+ >>> dev.modules[Module.Light].state # This is only needed to show the example working
45
+ LightState(light_on=True, brightness=50, hue=0,\
46
+ saturation=100, color_temp=2700, transition=None)
47
+
48
+ You can save a new preset state if the device supports it:
49
+
50
+ >>> if light_preset.has_save_preset:
51
+ >>> new_preset_state = LightState(light_on=True, brightness=75, hue=0,\
52
+ saturation=100, color_temp=2700, transition=None)
53
+ >>> await light_preset.save_preset("Light preset 1", new_preset_state)
54
+ >>> await dev.update()
55
+ >>> light_preset.preset # Saving updates the preset state for the preset, it does not \
56
+ set the preset
57
+ Not set
58
+ >>> light_preset.preset_states_list[0]
59
+ LightState(light_on=None, brightness=75, hue=0,\
60
+ saturation=100, color_temp=2700, transition=None)
61
+
62
+ If you manually set the light state to a preset state it will show that preset as \
63
+ active:
64
+
65
+ >>> await dev.modules[Module.Light].set_brightness(75)
66
+ >>> await dev.update()
67
+ >>> light_preset.preset
68
+ Light preset 1
69
+ """
2
70
 
3
71
  from __future__ import annotations
4
72
 
5
73
  from abc import abstractmethod
6
- from typing import Sequence
74
+ from collections.abc import Sequence
7
75
 
8
76
  from ..feature import Feature
9
77
  from ..module import Module
kasa/iot/iotdevice.py CHANGED
@@ -18,8 +18,9 @@ import collections.abc
18
18
  import functools
19
19
  import inspect
20
20
  import logging
21
+ from collections.abc import Mapping, Sequence
21
22
  from datetime import datetime, timedelta, timezone
22
- from typing import TYPE_CHECKING, Any, Mapping, Sequence, cast
23
+ from typing import TYPE_CHECKING, Any, cast
23
24
 
24
25
  from ..device import Device, WifiNetwork
25
26
  from ..deviceconfig import DeviceConfig
@@ -339,7 +340,9 @@ class IotDevice(Device):
339
340
  name="RSSI",
340
341
  attribute_getter="rssi",
341
342
  icon="mdi:signal",
343
+ unit="dBm",
342
344
  category=Feature.Category.Debug,
345
+ type=Feature.Type.Sensor,
343
346
  )
344
347
  )
345
348
  # iot strips calculate on_since from the children
@@ -351,6 +354,8 @@ class IotDevice(Device):
351
354
  name="On since",
352
355
  attribute_getter="on_since",
353
356
  icon="mdi:clock",
357
+ category=Feature.Category.Info,
358
+ type=Feature.Type.Sensor,
354
359
  )
355
360
  )
356
361
 
kasa/iot/iotstrip.py CHANGED
@@ -21,7 +21,7 @@ from .iotdevice import (
21
21
  )
22
22
  from .iotmodule import IotModule
23
23
  from .iotplug import IotPlug
24
- from .modules import Antitheft, Countdown, Schedule, Time, Usage
24
+ from .modules import Antitheft, Cloud, Countdown, Emeter, Led, Schedule, Time, Usage
25
25
 
26
26
  _LOGGER = logging.getLogger(__name__)
27
27
 
@@ -107,6 +107,8 @@ class IotStrip(IotDevice):
107
107
  self.add_module(Module.IotUsage, Usage(self, "schedule"))
108
108
  self.add_module(Module.IotTime, Time(self, "time"))
109
109
  self.add_module(Module.IotCountdown, Countdown(self, "countdown"))
110
+ self.add_module(Module.Led, Led(self, "system"))
111
+ self.add_module(Module.IotCloud, Cloud(self, "cnCloud"))
110
112
  if self.has_emeter:
111
113
  _LOGGER.debug(
112
114
  "The device has emeter, querying its information along sysinfo"
@@ -305,10 +307,12 @@ class IotStripPlug(IotPlug):
305
307
  The plug inherits (most of) the system information from the parent.
306
308
  """
307
309
 
310
+ _parent: IotStrip
311
+
308
312
  def __init__(self, host: str, parent: IotStrip, child_id: str) -> None:
309
313
  super().__init__(host)
310
314
 
311
- self.parent = parent
315
+ self._parent = parent
312
316
  self.child_id = child_id
313
317
  self._last_update = parent._last_update
314
318
  self._set_sys_info(parent.sys_info)
@@ -317,8 +321,12 @@ class IotStripPlug(IotPlug):
317
321
 
318
322
  async def _initialize_modules(self):
319
323
  """Initialize modules not added in init."""
320
- await super()._initialize_modules()
321
- self.add_module("time", Time(self, "time"))
324
+ if self.has_emeter:
325
+ self.add_module(Module.Energy, Emeter(self, self.emeter_type))
326
+ self.add_module(Module.IotUsage, Usage(self, "schedule"))
327
+ self.add_module(Module.IotAntitheft, Antitheft(self, "anti_theft"))
328
+ self.add_module(Module.IotSchedule, Schedule(self, "schedule"))
329
+ self.add_module(Module.IotCountdown, Countdown(self, "countdown"))
322
330
 
323
331
  async def _initialize_features(self):
324
332
  """Initialize common features."""
@@ -340,6 +348,8 @@ class IotStripPlug(IotPlug):
340
348
  name="On since",
341
349
  attribute_getter="on_since",
342
350
  icon="mdi:clock",
351
+ category=Feature.Category.Info,
352
+ type=Feature.Type.Sensor,
343
353
  )
344
354
  )
345
355
  for module in self._supported_modules.values():
@@ -353,6 +363,9 @@ class IotStripPlug(IotPlug):
353
363
  Needed for properties that are decorated with `requires_update`.
354
364
  """
355
365
  await self._modular_update({})
366
+ for module in self._modules.values():
367
+ module._post_update_hook()
368
+
356
369
  if not self._features:
357
370
  await self._initialize_features()
358
371
 
@@ -369,7 +382,7 @@ class IotStripPlug(IotPlug):
369
382
  self, target: str, cmd: str, arg: dict | None = None, child_ids=None
370
383
  ) -> Any:
371
384
  """Override query helper to include the child_ids."""
372
- return await self.parent._query_helper(
385
+ return await self._parent._query_helper(
373
386
  target, cmd, arg, child_ids=[self.child_id]
374
387
  )
375
388
 
@@ -430,13 +443,15 @@ class IotStripPlug(IotPlug):
430
443
  @requires_update
431
444
  def model(self) -> str:
432
445
  """Return device model for a child socket."""
433
- sys_info = self.parent.sys_info
446
+ sys_info = self._parent.sys_info
434
447
  return f"Socket for {sys_info['model']}"
435
448
 
436
449
  def _get_child_info(self) -> dict:
437
450
  """Return the subdevice information for this device."""
438
- for plug in self.parent.sys_info["children"]:
451
+ for plug in self._parent.sys_info["children"]:
439
452
  if plug["id"] == self.child_id:
440
453
  return plug
441
454
 
442
- raise KasaException(f"Unable to find children {self.child_id}")
455
+ raise KasaException(
456
+ f"Unable to find children {self.child_id}"
457
+ ) # pragma: no cover
@@ -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, Optional, Sequence
7
+ from typing import TYPE_CHECKING, Optional
7
8
 
8
9
  from pydantic.v1 import BaseModel, Field
9
10
 
kasa/module.py CHANGED
@@ -1,4 +1,42 @@
1
- """Base class for all module implementations."""
1
+ """Interact with modules.
2
+
3
+ Modules are implemented by devices to encapsulate sets of functionality like
4
+ Light, AutoOff, Firmware etc.
5
+
6
+ >>> from kasa import Discover, Module
7
+ >>>
8
+ >>> dev = await Discover.discover_single(
9
+ >>> "127.0.0.3",
10
+ >>> username="user@example.com",
11
+ >>> password="great_password"
12
+ >>> )
13
+ >>> await dev.update()
14
+ >>> print(dev.alias)
15
+ Living Room Bulb
16
+
17
+ To see whether a device supports functionality check for the existence of the module:
18
+
19
+ >>> if light := dev.modules.get("Light"):
20
+ >>> print(light.hsv)
21
+ HSV(hue=0, saturation=100, value=100)
22
+
23
+ If you know or expect the module to exist you can access by index:
24
+
25
+ >>> light_preset = dev.modules["LightPreset"]
26
+ >>> print(light_preset.preset_list)
27
+ ['Not set', 'Light preset 1', 'Light preset 2', 'Light preset 3',\
28
+ 'Light preset 4', 'Light preset 5', 'Light preset 6', 'Light preset 7']
29
+
30
+ Modules support typing via the Module names in Module:
31
+
32
+ >>> from typing_extensions import reveal_type, TYPE_CHECKING
33
+ >>> light_effect = dev.modules.get("LightEffect")
34
+ >>> light_effect_typed = dev.modules.get(Module.LightEffect)
35
+ >>> if TYPE_CHECKING:
36
+ >>> reveal_type(light_effect) # Static checker will reveal: str
37
+ >>> reveal_type(light_effect_typed) # Static checker will reveal: LightEffect
38
+
39
+ """
2
40
 
3
41
  from __future__ import annotations
4
42
 
@@ -74,6 +112,9 @@ class Module(ABC):
74
112
  "LightTransition"
75
113
  )
76
114
  ReportMode: Final[ModuleName[smart.ReportMode]] = ModuleName("ReportMode")
115
+ SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = ModuleName(
116
+ "LightEffect"
117
+ )
77
118
  TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = ModuleName(
78
119
  "TemperatureSensor"
79
120
  )
kasa/smart/effects.py CHANGED
@@ -2,8 +2,33 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from abc import ABC, abstractmethod
5
6
  from typing import cast
6
7
 
8
+ from ..interfaces.lighteffect import LightEffect as LightEffectInterface
9
+
10
+
11
+ class SmartLightEffect(LightEffectInterface, ABC):
12
+ """Abstract interface for smart light effects.
13
+
14
+ This interface extends lighteffect interface to add brightness controls.
15
+ """
16
+
17
+ @abstractmethod
18
+ async def set_brightness(self, brightness: int, *, transition: int | None = None):
19
+ """Set effect brightness."""
20
+
21
+ @property
22
+ @abstractmethod
23
+ def brightness(self) -> int:
24
+ """Return effect brightness."""
25
+
26
+ @property
27
+ @abstractmethod
28
+ def is_active(self) -> bool:
29
+ """Return True if effect is active."""
30
+
31
+
7
32
  EFFECT_AURORA = {
8
33
  "custom": 0,
9
34
  "id": "TapoStrip_1MClvV18i15Jq3bvJVf0eP",
@@ -1,5 +1,6 @@
1
1
  """Modules for SMART devices."""
2
2
 
3
+ from ..effects import SmartLightEffect
3
4
  from .alarm import Alarm
4
5
  from .autooff import AutoOff
5
6
  from .batterysensor import BatterySensor
@@ -54,4 +55,5 @@ __all__ = [
54
55
  "WaterleakSensor",
55
56
  "ContactSensor",
56
57
  "FrostProtection",
58
+ "SmartLightEffect",
57
59
  ]
@@ -43,6 +43,7 @@ class Alarm(SmartModule):
43
43
  container=self,
44
44
  attribute_getter="source",
45
45
  icon="mdi:bell",
46
+ type=Feature.Type.Sensor,
46
47
  )
47
48
  )
48
49
  self._add_feature(
@@ -40,11 +40,12 @@ class AutoOff(SmartModule):
40
40
  Feature(
41
41
  self._device,
42
42
  id="auto_off_minutes",
43
- name="Auto off minutes",
43
+ name="Auto off in",
44
44
  container=self,
45
45
  attribute_getter="delay",
46
46
  attribute_setter="set_delay",
47
47
  type=Feature.Type.Number,
48
+ unit="min", # ha-friendly unit, see UnitOfTime.MINUTES
48
49
  )
49
50
  )
50
51
  self._add_feature(
@@ -55,6 +56,7 @@ class AutoOff(SmartModule):
55
56
  container=self,
56
57
  attribute_getter="auto_off_at",
57
58
  category=Feature.Category.Info,
59
+ type=Feature.Type.Sensor,
58
60
  )
59
61
  )
60
62
 
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from ...feature import Feature
6
- from ..smartmodule import SmartModule
6
+ from ..smartmodule import Module, SmartModule
7
7
 
8
8
  BRIGHTNESS_MIN = 0
9
9
  BRIGHTNESS_MAX = 100
@@ -42,6 +42,12 @@ class Brightness(SmartModule):
42
42
  @property
43
43
  def brightness(self):
44
44
  """Return current brightness."""
45
+ # If the device supports effects and one is active, use its brightness
46
+ if (
47
+ light_effect := self._device.modules.get(Module.SmartLightEffect)
48
+ ) is not None and light_effect.is_active:
49
+ return light_effect.brightness
50
+
45
51
  return self.data["brightness"]
46
52
 
47
53
  async def set_brightness(self, brightness: int, *, transition: int | None = None):
@@ -59,6 +65,13 @@ class Brightness(SmartModule):
59
65
 
60
66
  if brightness == 0:
61
67
  return await self._device.turn_off()
68
+
69
+ # If the device supports effects and one is active, we adjust its brightness
70
+ if (
71
+ light_effect := self._device.modules.get(Module.SmartLightEffect)
72
+ ) is not None and light_effect.is_active:
73
+ return await light_effect.set_brightness(brightness)
74
+
62
75
  return await self.call("set_device_info", {"brightness": brightness})
63
76
 
64
77
  async def _check_supported(self):
@@ -1,4 +1,42 @@
1
- """Implementation for child devices."""
1
+ """Interact with child devices.
2
+
3
+ >>> from kasa import Discover
4
+ >>>
5
+ >>> dev = await Discover.discover_single(
6
+ >>> "127.0.0.1",
7
+ >>> username="user@example.com",
8
+ >>> password="great_password"
9
+ >>> )
10
+ >>> await dev.update()
11
+ >>> print(dev.alias)
12
+ Bedroom Power Strip
13
+
14
+ All methods act on the whole strip:
15
+
16
+ >>> for plug in dev.children:
17
+ >>> print(f"{plug.alias}: {plug.is_on}")
18
+ Plug 1: True
19
+ Plug 2: False
20
+ Plug 3: False
21
+ >>> dev.is_on
22
+ True
23
+ >>> await dev.turn_off()
24
+ >>> await dev.update()
25
+
26
+ Accessing individual plugs can be done using the `children` property:
27
+
28
+ >>> len(dev.children)
29
+ 3
30
+ >>> for plug in dev.children:
31
+ >>> print(f"{plug.alias}: {plug.is_on}")
32
+ Plug 1: False
33
+ Plug 2: False
34
+ Plug 3: False
35
+ >>> await dev.children[1].turn_on()
36
+ >>> await dev.update()
37
+ >>> dev.is_on
38
+ True
39
+ """
2
40
 
3
41
  from ..smartmodule import SmartModule
4
42
 
@@ -4,8 +4,9 @@ from __future__ import annotations
4
4
 
5
5
  import asyncio
6
6
  import logging
7
+ from collections.abc import Coroutine
7
8
  from datetime import date
8
- from typing import TYPE_CHECKING, Any, Callable, Coroutine, Optional
9
+ from typing import TYPE_CHECKING, Any, Callable, Optional
9
10
 
10
11
  # When support for cpython older than 3.11 is dropped
11
12
  # async_timeout can be replaced with asyncio.timeout
@@ -100,6 +101,7 @@ class Firmware(SmartModule):
100
101
  container=self,
101
102
  attribute_getter="current_firmware",
102
103
  category=Feature.Category.Debug,
104
+ type=Feature.Type.Sensor,
103
105
  )
104
106
  )
105
107
  self._add_feature(
@@ -110,6 +112,7 @@ class Firmware(SmartModule):
110
112
  container=self,
111
113
  attribute_getter="latest_firmware",
112
114
  category=Feature.Category.Debug,
115
+ type=Feature.Type.Sensor,
113
116
  )
114
117
  )
115
118
 
@@ -2,15 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
6
-
7
- from ...feature import Feature
8
5
  from ..smartmodule import SmartModule
9
6
 
10
- # TODO: this may not be necessary with __future__.annotations
11
- if TYPE_CHECKING:
12
- from ..smartdevice import SmartDevice
13
-
14
7
 
15
8
  class FrostProtection(SmartModule):
16
9
  """Implementation for frost protection module.
@@ -19,23 +12,8 @@ class FrostProtection(SmartModule):
19
12
  """
20
13
 
21
14
  REQUIRED_COMPONENT = "frost_protection"
22
- # TODO: the information required for current features do not require this query
23
15
  QUERY_GETTER_NAME = "get_frost_protection"
24
16
 
25
- def __init__(self, device: SmartDevice, module: str):
26
- super().__init__(device, module)
27
- self._add_feature(
28
- Feature(
29
- device,
30
- "frost_protection_enabled",
31
- name="Frost protection enabled",
32
- container=self,
33
- attribute_getter="enabled",
34
- attribute_setter="set_enabled",
35
- type=Feature.Type.Switch,
36
- )
37
- )
38
-
39
17
  @property
40
18
  def enabled(self) -> bool:
41
19
  """Return True if frost protection is on."""
@@ -29,6 +29,7 @@ class HumiditySensor(SmartModule):
29
29
  icon="mdi:water-percent",
30
30
  unit="%",
31
31
  category=Feature.Category.Primary,
32
+ type=Feature.Type.Sensor,
32
33
  )
33
34
  )
34
35
  self._add_feature(
kasa/smart/modules/led.py CHANGED
@@ -27,7 +27,7 @@ class Led(SmartModule, LedInterface):
27
27
  @property
28
28
  def led(self):
29
29
  """Return current led status."""
30
- return self.data["led_status"]
30
+ return self.data["led_rule"] != "never"
31
31
 
32
32
  async def set_led(self, enable: bool):
33
33
  """Set led.