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.
- kasa/__init__.py +88 -27
- kasa/aestransport.py +51 -34
- kasa/cli.py +326 -130
- kasa/device.py +406 -0
- kasa/device_factory.py +83 -44
- kasa/device_type.py +7 -3
- kasa/deviceconfig.py +16 -9
- kasa/discover.py +100 -81
- kasa/emeterstatus.py +12 -7
- kasa/exceptions.py +41 -26
- kasa/feature.py +201 -0
- kasa/httpclient.py +21 -14
- kasa/interfaces/__init__.py +16 -0
- kasa/interfaces/fan.py +20 -0
- kasa/interfaces/led.py +38 -0
- kasa/interfaces/light.py +133 -0
- kasa/interfaces/lighteffect.py +80 -0
- kasa/interfaces/lightpreset.py +76 -0
- kasa/iot/__init__.py +18 -0
- kasa/{effects.py → iot/effects.py} +4 -2
- kasa/{smartbulb.py → iot/iotbulb.py} +100 -147
- kasa/{smartdevice.py → iot/iotdevice.py} +157 -286
- kasa/{smartdimmer.py → iot/iotdimmer.py} +42 -33
- kasa/iot/iotlightstrip.py +71 -0
- kasa/{modules/module.py → iot/iotmodule.py} +22 -42
- kasa/iot/iotplug.py +94 -0
- kasa/{smartstrip.py → iot/iotstrip.py} +57 -75
- kasa/{modules → iot/modules}/__init__.py +10 -2
- kasa/{modules → iot/modules}/ambientlight.py +31 -3
- kasa/{modules → iot/modules}/antitheft.py +1 -0
- kasa/{modules → iot/modules}/cloud.py +25 -6
- kasa/{modules → iot/modules}/countdown.py +1 -0
- kasa/iot/modules/emeter.py +210 -0
- kasa/iot/modules/led.py +32 -0
- kasa/iot/modules/light.py +221 -0
- kasa/iot/modules/lighteffect.py +122 -0
- kasa/iot/modules/lightpreset.py +151 -0
- kasa/{modules → iot/modules}/motion.py +8 -8
- kasa/{modules → iot/modules}/rulemodule.py +11 -12
- kasa/{modules → iot/modules}/schedule.py +1 -0
- kasa/{modules → iot/modules}/time.py +5 -4
- kasa/{modules → iot/modules}/usage.py +10 -8
- kasa/iotprotocol.py +22 -20
- kasa/klaptransport.py +25 -15
- kasa/module.py +136 -0
- kasa/modulemapping.py +25 -0
- kasa/modulemapping.pyi +96 -0
- kasa/protocol.py +6 -4
- kasa/smart/__init__.py +6 -0
- kasa/smart/effects.py +429 -0
- kasa/smart/modules/__init__.py +57 -0
- kasa/smart/modules/alarm.py +142 -0
- kasa/smart/modules/autooff.py +96 -0
- kasa/smart/modules/batterysensor.py +54 -0
- kasa/smart/modules/brightness.py +66 -0
- kasa/smart/modules/childdevice.py +10 -0
- kasa/smart/modules/cloud.py +42 -0
- kasa/smart/modules/color.py +96 -0
- kasa/smart/modules/colortemperature.py +78 -0
- kasa/smart/modules/contactsensor.py +42 -0
- kasa/smart/modules/devicemodule.py +22 -0
- kasa/smart/modules/energy.py +101 -0
- kasa/smart/modules/fan.py +80 -0
- kasa/smart/modules/firmware.py +216 -0
- kasa/smart/modules/frostprotection.py +59 -0
- kasa/smart/modules/humiditysensor.py +55 -0
- kasa/smart/modules/led.py +49 -0
- kasa/smart/modules/light.py +139 -0
- kasa/smart/modules/lighteffect.py +115 -0
- kasa/smart/modules/lightpreset.py +142 -0
- kasa/smart/modules/lightstripeffect.py +135 -0
- kasa/smart/modules/lighttransition.py +183 -0
- kasa/smart/modules/reportmode.py +36 -0
- kasa/smart/modules/temperaturecontrol.py +177 -0
- kasa/smart/modules/temperaturesensor.py +77 -0
- kasa/smart/modules/time.py +57 -0
- kasa/smart/modules/waterleaksensor.py +66 -0
- kasa/smart/smartchilddevice.py +65 -0
- kasa/smart/smartdevice.py +653 -0
- kasa/smart/smartmodule.py +112 -0
- kasa/smartprotocol.py +107 -41
- kasa/tests/conftest.py +27 -551
- kasa/tests/device_fixtures.py +427 -0
- kasa/tests/discovery_fixtures.py +197 -0
- kasa/tests/{newfakes.py → fakeprotocol_iot.py} +61 -291
- kasa/tests/fakeprotocol_smart.py +318 -0
- kasa/tests/fixtureinfo.py +154 -0
- kasa/tests/fixtures/smart/H100(EU)_1.0_1.2.3.json +221 -0
- kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.10.json +547 -0
- kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.5.json +391 -0
- kasa/tests/fixtures/smart/KH100(UK)_1.0_1.5.6.json +1557 -0
- kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.4.json +899 -0
- kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.5.json +479 -0
- kasa/tests/fixtures/smart/L530E(EU)_3.0_1.1.6.json +449 -0
- kasa/tests/fixtures/smart/P100_1.0.0_1.1.3.json +173 -0
- kasa/tests/fixtures/smart/P100_1.0.0_1.4.0.json +204 -0
- kasa/tests/fixtures/smart/P110(EU)_1.0_1.0.7.json +566 -0
- kasa/tests/fixtures/smart/P300(EU)_1.0_1.0.13.json +13 -23
- kasa/tests/fixtures/smart/P300(EU)_1.0_1.0.7.json +6 -6
- kasa/tests/fixtures/smart/TP15(US)_1.0_1.0.3.json +295 -0
- kasa/tests/fixtures/smart/TP25(US)_1.0_1.0.2.json +423 -0
- kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.4.0.json +170 -0
- kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.8.0.json +171 -0
- kasa/tests/fixtures/smart/child/KE100(UK)_1.0_2.8.0.json +171 -0
- kasa/tests/fixtures/smart/child/T110(EU)_1.0_1.8.0.json +526 -0
- kasa/tests/fixtures/smart/child/T300(EU)_1.0_1.7.0.json +533 -0
- kasa/tests/fixtures/smart/child/T310(EU)_1.0_1.5.0.json +530 -0
- kasa/tests/fixtures/smart/child/T315(EU)_1.0_1.7.0.json +537 -0
- kasa/tests/smart/__init__.py +0 -0
- kasa/tests/smart/features/__init__.py +0 -0
- kasa/tests/smart/features/test_brightness.py +55 -0
- kasa/tests/smart/features/test_colortemp.py +30 -0
- kasa/tests/smart/modules/__init__.py +0 -0
- kasa/tests/smart/modules/test_contact.py +28 -0
- kasa/tests/smart/modules/test_fan.py +79 -0
- kasa/tests/smart/modules/test_firmware.py +108 -0
- kasa/tests/smart/modules/test_humidity.py +28 -0
- kasa/tests/smart/modules/test_light_effect.py +41 -0
- kasa/tests/smart/modules/test_temperature.py +47 -0
- kasa/tests/smart/modules/test_temperaturecontrol.py +137 -0
- kasa/tests/smart/modules/test_waterleak.py +42 -0
- kasa/tests/test_aestransport.py +115 -25
- kasa/tests/test_bulb.py +169 -86
- kasa/tests/test_childdevice.py +84 -0
- kasa/tests/test_cli.py +452 -100
- kasa/tests/test_common_modules.py +216 -0
- kasa/tests/test_device.py +268 -0
- kasa/tests/test_device_factory.py +61 -41
- kasa/tests/test_device_type.py +1 -1
- kasa/tests/test_deviceconfig.py +2 -5
- kasa/tests/test_dimmer.py +33 -24
- kasa/tests/test_discovery.py +112 -69
- kasa/tests/test_emeter.py +39 -12
- kasa/tests/test_feature.py +205 -0
- kasa/tests/test_httpclient.py +9 -9
- kasa/tests/test_iotdevice.py +286 -0
- kasa/tests/test_klapprotocol.py +94 -41
- kasa/tests/test_lightstrip.py +24 -19
- kasa/tests/test_plug.py +51 -9
- kasa/tests/test_protocol.py +8 -12
- kasa/tests/test_readme_examples.py +86 -27
- kasa/tests/test_smartdevice.py +211 -247
- kasa/tests/test_smartprotocol.py +129 -26
- kasa/tests/test_strip.py +15 -6
- kasa/tests/test_usage.py +1 -3
- kasa/xortransport.py +15 -12
- {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/METADATA +45 -141
- python_kasa-0.7.0.dev0.dist-info/RECORD +239 -0
- {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/WHEEL +1 -1
- kasa/modules/emeter.py +0 -111
- kasa/smartlightstrip.py +0 -143
- kasa/smartplug.py +0 -91
- kasa/tapo/__init__.py +0 -7
- kasa/tapo/childdevice.py +0 -44
- kasa/tapo/tapobulb.py +0 -262
- kasa/tapo/tapodevice.py +0 -383
- kasa/tapo/tapoplug.py +0 -45
- kasa/tests/fixtures/HS105(US)_1.0_mocked.json +0 -47
- kasa/tests/fixtures/HS110(EU)_2.0_mocked.json +0 -50
- kasa/tests/fixtures/HS110(US)_1.0_mocked.json +0 -50
- kasa/tests/fixtures/HS200(US)_1.0_mocked.json +0 -47
- kasa/tests/fixtures/HS220(US)_1.0_mocked.json +0 -75
- kasa/tests/fixtures/LB100(US)_1.0_mocked.json +0 -103
- kasa/tests/fixtures/LB120(US)_1.0_mocked.json +0 -103
- kasa/tests/fixtures/LB130(US)_1.0_mocked.json +0 -104
- python_kasa-0.6.2.dist-info/RECORD +0 -163
- {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/LICENSE +0 -0
- {python_kasa-0.6.2.dist-info → python_kasa-0.7.0.dev0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Module for light effects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import asdict
|
|
6
|
+
from typing import TYPE_CHECKING, Sequence
|
|
7
|
+
|
|
8
|
+
from ...interfaces import LightPreset as LightPresetInterface
|
|
9
|
+
from ...interfaces import LightState
|
|
10
|
+
from ..smartmodule import SmartModule
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ..smartdevice import SmartDevice
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class LightPreset(SmartModule, LightPresetInterface):
|
|
17
|
+
"""Implementation of light presets."""
|
|
18
|
+
|
|
19
|
+
REQUIRED_COMPONENT = "preset"
|
|
20
|
+
QUERY_GETTER_NAME = "get_preset_rules"
|
|
21
|
+
|
|
22
|
+
SYS_INFO_STATE_KEY = "preset_state"
|
|
23
|
+
|
|
24
|
+
_presets: dict[str, LightState]
|
|
25
|
+
_preset_list: list[str]
|
|
26
|
+
|
|
27
|
+
def __init__(self, device: SmartDevice, module: str):
|
|
28
|
+
super().__init__(device, module)
|
|
29
|
+
self._state_in_sysinfo = self.SYS_INFO_STATE_KEY in device.sys_info
|
|
30
|
+
self._brightness_only: bool = False
|
|
31
|
+
|
|
32
|
+
def _post_update_hook(self):
|
|
33
|
+
"""Update the internal presets."""
|
|
34
|
+
index = 0
|
|
35
|
+
self._presets = {}
|
|
36
|
+
|
|
37
|
+
state_key = "states" if not self._state_in_sysinfo else self.SYS_INFO_STATE_KEY
|
|
38
|
+
if preset_states := self.data.get(state_key):
|
|
39
|
+
for preset_state in preset_states:
|
|
40
|
+
color_temp = preset_state.get("color_temp")
|
|
41
|
+
hue = preset_state.get("hue")
|
|
42
|
+
saturation = preset_state.get("saturation")
|
|
43
|
+
self._presets[f"Light preset {index + 1}"] = LightState(
|
|
44
|
+
brightness=preset_state["brightness"],
|
|
45
|
+
color_temp=color_temp,
|
|
46
|
+
hue=hue,
|
|
47
|
+
saturation=saturation,
|
|
48
|
+
)
|
|
49
|
+
if color_temp is None and hue is None and saturation is None:
|
|
50
|
+
self._brightness_only = True
|
|
51
|
+
index = index + 1
|
|
52
|
+
elif preset_brightnesses := self.data.get("brightness"):
|
|
53
|
+
self._brightness_only = True
|
|
54
|
+
for preset_brightness in preset_brightnesses:
|
|
55
|
+
self._presets[f"Brightness preset {index + 1}"] = LightState(
|
|
56
|
+
brightness=preset_brightness,
|
|
57
|
+
)
|
|
58
|
+
index = index + 1
|
|
59
|
+
|
|
60
|
+
self._preset_list = [self.PRESET_NOT_SET]
|
|
61
|
+
self._preset_list.extend(self._presets.keys())
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def preset_list(self) -> list[str]:
|
|
65
|
+
"""Return built-in effects list.
|
|
66
|
+
|
|
67
|
+
Example:
|
|
68
|
+
['Off', 'Light preset 1', 'Light preset 2', ...]
|
|
69
|
+
"""
|
|
70
|
+
return self._preset_list
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def preset_states_list(self) -> Sequence[LightState]:
|
|
74
|
+
"""Return built-in effects list.
|
|
75
|
+
|
|
76
|
+
Example:
|
|
77
|
+
['Off', 'Preset 1', 'Preset 2', ...]
|
|
78
|
+
"""
|
|
79
|
+
return list(self._presets.values())
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def preset(self) -> str:
|
|
83
|
+
"""Return current preset name."""
|
|
84
|
+
light = self._device.modules[SmartModule.Light]
|
|
85
|
+
brightness = light.brightness
|
|
86
|
+
color_temp = light.color_temp if light.is_variable_color_temp else None
|
|
87
|
+
h, s = (light.hsv.hue, light.hsv.saturation) if light.is_color else (None, None)
|
|
88
|
+
for preset_name, preset in self._presets.items():
|
|
89
|
+
if (
|
|
90
|
+
preset.brightness == brightness
|
|
91
|
+
and (
|
|
92
|
+
preset.color_temp == color_temp or not light.is_variable_color_temp
|
|
93
|
+
)
|
|
94
|
+
and preset.hue == h
|
|
95
|
+
and preset.saturation == s
|
|
96
|
+
):
|
|
97
|
+
return preset_name
|
|
98
|
+
return self.PRESET_NOT_SET
|
|
99
|
+
|
|
100
|
+
async def set_preset(
|
|
101
|
+
self,
|
|
102
|
+
preset_name: str,
|
|
103
|
+
) -> None:
|
|
104
|
+
"""Set a light preset for the device."""
|
|
105
|
+
light = self._device.modules[SmartModule.Light]
|
|
106
|
+
if preset_name == self.PRESET_NOT_SET:
|
|
107
|
+
if light.is_color:
|
|
108
|
+
preset = LightState(hue=0, saturation=0, brightness=100)
|
|
109
|
+
else:
|
|
110
|
+
preset = LightState(brightness=100)
|
|
111
|
+
elif (preset := self._presets.get(preset_name)) is None: # type: ignore[assignment]
|
|
112
|
+
raise ValueError(f"{preset_name} is not a valid preset: {self.preset_list}")
|
|
113
|
+
await self._device.modules[SmartModule.Light].set_state(preset)
|
|
114
|
+
|
|
115
|
+
async def save_preset(
|
|
116
|
+
self,
|
|
117
|
+
preset_name: str,
|
|
118
|
+
preset_state: LightState,
|
|
119
|
+
) -> None:
|
|
120
|
+
"""Update the preset with preset_name with the new preset_info."""
|
|
121
|
+
if preset_name not in self._presets:
|
|
122
|
+
raise ValueError(f"{preset_name} is not a valid preset: {self.preset_list}")
|
|
123
|
+
index = list(self._presets.keys()).index(preset_name)
|
|
124
|
+
if self._brightness_only:
|
|
125
|
+
bright_list = [state.brightness for state in self._presets.values()]
|
|
126
|
+
bright_list[index] = preset_state.brightness
|
|
127
|
+
await self.call("set_preset_rules", {"brightness": bright_list})
|
|
128
|
+
else:
|
|
129
|
+
state_params = asdict(preset_state)
|
|
130
|
+
new_info = {k: v for k, v in state_params.items() if v is not None}
|
|
131
|
+
await self.call("edit_preset_rules", {"index": index, "state": new_info})
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def has_save_preset(self) -> bool:
|
|
135
|
+
"""Return True if the device supports updating presets."""
|
|
136
|
+
return True
|
|
137
|
+
|
|
138
|
+
def query(self) -> dict:
|
|
139
|
+
"""Query to execute during the update cycle."""
|
|
140
|
+
if self._state_in_sysinfo: # Child lights can have states in the child info
|
|
141
|
+
return {}
|
|
142
|
+
return {self.QUERY_GETTER_NAME: None}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Module for light effects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ...interfaces.lighteffect import LightEffect as LightEffectInterface
|
|
6
|
+
from ..effects import EFFECT_MAPPING, EFFECT_NAMES
|
|
7
|
+
from ..smartmodule import SmartModule
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LightStripEffect(SmartModule, LightEffectInterface):
|
|
11
|
+
"""Implementation of dynamic light effects."""
|
|
12
|
+
|
|
13
|
+
REQUIRED_COMPONENT = "light_strip_lighting_effect"
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def name(self) -> str:
|
|
17
|
+
"""Name of the module.
|
|
18
|
+
|
|
19
|
+
By default smart modules are keyed in the module mapping by class name.
|
|
20
|
+
The name is overriden here as this module implements the same common interface
|
|
21
|
+
as the bulb light_effect and the assumption is a device only supports one
|
|
22
|
+
or the other.
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
return "LightEffect"
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def effect(self) -> str:
|
|
29
|
+
"""Return effect state.
|
|
30
|
+
|
|
31
|
+
Example:
|
|
32
|
+
{'brightness': 50,
|
|
33
|
+
'custom': 0,
|
|
34
|
+
'enable': 0,
|
|
35
|
+
'id': '',
|
|
36
|
+
'name': ''}
|
|
37
|
+
"""
|
|
38
|
+
eff = self.data["lighting_effect"]
|
|
39
|
+
name = eff["name"]
|
|
40
|
+
if eff["enable"]:
|
|
41
|
+
return name
|
|
42
|
+
return self.LIGHT_EFFECTS_OFF
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def effect_list(self) -> list[str]:
|
|
46
|
+
"""Return built-in effects list.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
['Aurora', 'Bubbling Cauldron', ...]
|
|
50
|
+
"""
|
|
51
|
+
effect_list = [self.LIGHT_EFFECTS_OFF]
|
|
52
|
+
effect_list.extend(EFFECT_NAMES)
|
|
53
|
+
return effect_list
|
|
54
|
+
|
|
55
|
+
async def set_effect(
|
|
56
|
+
self,
|
|
57
|
+
effect: str,
|
|
58
|
+
*,
|
|
59
|
+
brightness: int | None = None,
|
|
60
|
+
transition: int | None = None,
|
|
61
|
+
) -> None:
|
|
62
|
+
"""Set an effect on the device.
|
|
63
|
+
|
|
64
|
+
If brightness or transition is defined,
|
|
65
|
+
its value will be used instead of the effect-specific default.
|
|
66
|
+
|
|
67
|
+
See :meth:`effect_list` for available effects,
|
|
68
|
+
or use :meth:`set_custom_effect` for custom effects.
|
|
69
|
+
|
|
70
|
+
:param str effect: The effect to set
|
|
71
|
+
:param int brightness: The wanted brightness
|
|
72
|
+
:param int transition: The wanted transition time
|
|
73
|
+
"""
|
|
74
|
+
if effect == self.LIGHT_EFFECTS_OFF:
|
|
75
|
+
effect_dict = dict(self.data["lighting_effect"])
|
|
76
|
+
effect_dict["enable"] = 0
|
|
77
|
+
elif effect not in EFFECT_MAPPING:
|
|
78
|
+
raise ValueError(f"The effect {effect} is not a built in effect.")
|
|
79
|
+
else:
|
|
80
|
+
effect_dict = EFFECT_MAPPING[effect]
|
|
81
|
+
|
|
82
|
+
if brightness is not None:
|
|
83
|
+
effect_dict["brightness"] = brightness
|
|
84
|
+
if transition is not None:
|
|
85
|
+
effect_dict["transition"] = transition
|
|
86
|
+
|
|
87
|
+
await self.set_custom_effect(effect_dict)
|
|
88
|
+
|
|
89
|
+
async def set_custom_effect(
|
|
90
|
+
self,
|
|
91
|
+
effect_dict: dict,
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Set a custom effect on the device.
|
|
94
|
+
|
|
95
|
+
:param str effect_dict: The custom effect dict to set
|
|
96
|
+
"""
|
|
97
|
+
return await self.call(
|
|
98
|
+
"set_lighting_effect",
|
|
99
|
+
effect_dict,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def has_custom_effects(self) -> bool:
|
|
104
|
+
"""Return True if the device supports setting custom effects."""
|
|
105
|
+
return True
|
|
106
|
+
|
|
107
|
+
def query(self):
|
|
108
|
+
"""Return the base query."""
|
|
109
|
+
return {}
|
|
110
|
+
|
|
111
|
+
@property # type: ignore
|
|
112
|
+
def _deprecated_effect(self) -> dict:
|
|
113
|
+
"""Return effect state.
|
|
114
|
+
|
|
115
|
+
Example:
|
|
116
|
+
{'brightness': 50,
|
|
117
|
+
'custom': 0,
|
|
118
|
+
'enable': 0,
|
|
119
|
+
'id': '',
|
|
120
|
+
'name': ''}
|
|
121
|
+
"""
|
|
122
|
+
# LightEffectModule returns the current effect name
|
|
123
|
+
# so return the dict here for backwards compatibility
|
|
124
|
+
return self.data["lighting_effect"]
|
|
125
|
+
|
|
126
|
+
@property # type: ignore
|
|
127
|
+
def _deprecated_effect_list(self) -> list[str] | None:
|
|
128
|
+
"""Return built-in effects list.
|
|
129
|
+
|
|
130
|
+
Example:
|
|
131
|
+
['Aurora', 'Bubbling Cauldron', ...]
|
|
132
|
+
"""
|
|
133
|
+
# LightEffectModule returns effect names along with a LIGHT_EFFECTS_OFF value
|
|
134
|
+
# so return the original effect names here for backwards compatibility
|
|
135
|
+
return EFFECT_NAMES
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""Module for smooth light transitions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from ...exceptions import KasaException
|
|
8
|
+
from ...feature import Feature
|
|
9
|
+
from ..smartmodule import SmartModule
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from ..smartdevice import SmartDevice
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class LightTransition(SmartModule):
|
|
16
|
+
"""Implementation of gradual on/off."""
|
|
17
|
+
|
|
18
|
+
REQUIRED_COMPONENT = "on_off_gradually"
|
|
19
|
+
QUERY_GETTER_NAME = "get_on_off_gradually_info"
|
|
20
|
+
MAXIMUM_DURATION = 60
|
|
21
|
+
|
|
22
|
+
def __init__(self, device: SmartDevice, module: str):
|
|
23
|
+
super().__init__(device, module)
|
|
24
|
+
self._create_features()
|
|
25
|
+
|
|
26
|
+
def _create_features(self):
|
|
27
|
+
"""Create features based on the available version."""
|
|
28
|
+
icon = "mdi:transition"
|
|
29
|
+
if self.supported_version == 1:
|
|
30
|
+
self._add_feature(
|
|
31
|
+
Feature(
|
|
32
|
+
device=self._device,
|
|
33
|
+
container=self,
|
|
34
|
+
id="smooth_transitions",
|
|
35
|
+
name="Smooth transitions",
|
|
36
|
+
icon=icon,
|
|
37
|
+
attribute_getter="enabled_v1",
|
|
38
|
+
attribute_setter="set_enabled_v1",
|
|
39
|
+
type=Feature.Type.Switch,
|
|
40
|
+
)
|
|
41
|
+
)
|
|
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.
|
|
47
|
+
self._add_feature(
|
|
48
|
+
Feature(
|
|
49
|
+
self._device,
|
|
50
|
+
id="smooth_transition_on",
|
|
51
|
+
name="Smooth transition on",
|
|
52
|
+
container=self,
|
|
53
|
+
attribute_getter="turn_on_transition",
|
|
54
|
+
attribute_setter="set_turn_on_transition",
|
|
55
|
+
icon=icon,
|
|
56
|
+
type=Feature.Type.Number,
|
|
57
|
+
maximum_value=self.MAXIMUM_DURATION,
|
|
58
|
+
)
|
|
59
|
+
) # self._turn_on_transition_max
|
|
60
|
+
self._add_feature(
|
|
61
|
+
Feature(
|
|
62
|
+
self._device,
|
|
63
|
+
id="smooth_transition_off",
|
|
64
|
+
name="Smooth transition off",
|
|
65
|
+
container=self,
|
|
66
|
+
attribute_getter="turn_off_transition",
|
|
67
|
+
attribute_setter="set_turn_off_transition",
|
|
68
|
+
icon=icon,
|
|
69
|
+
type=Feature.Type.Number,
|
|
70
|
+
maximum_value=self.MAXIMUM_DURATION,
|
|
71
|
+
)
|
|
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
|
+
)
|
|
81
|
+
|
|
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:
|
|
88
|
+
raise KasaException(
|
|
89
|
+
f"Unsupported for {self.REQUIRED_COMPONENT} v{self.supported_version}"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
return self.data["off_state"]
|
|
93
|
+
|
|
94
|
+
async def set_enabled_v1(self, enable: bool):
|
|
95
|
+
"""Enable gradual on/off."""
|
|
96
|
+
return await self.call("set_on_off_gradually_info", {"enable": enable})
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def enabled_v1(self) -> bool:
|
|
100
|
+
"""Return True if gradual on/off is enabled."""
|
|
101
|
+
return bool(self.data["enable"])
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def turn_on_transition(self) -> int:
|
|
105
|
+
"""Return transition time for turning the light on.
|
|
106
|
+
|
|
107
|
+
Available only from v2.
|
|
108
|
+
"""
|
|
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"]
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def _turn_on_transition_max(self) -> int:
|
|
115
|
+
"""Maximum turn on duration."""
|
|
116
|
+
# v3 added max_duration, we default to 60 when it's not available
|
|
117
|
+
return self._turn_on.get("max_duration", 60)
|
|
118
|
+
|
|
119
|
+
async def set_turn_on_transition(self, seconds: int):
|
|
120
|
+
"""Set turn on transition in seconds.
|
|
121
|
+
|
|
122
|
+
Setting to 0 turns the feature off.
|
|
123
|
+
"""
|
|
124
|
+
if seconds > self._turn_on_transition_max:
|
|
125
|
+
raise ValueError(
|
|
126
|
+
f"Value {seconds} out of range, max {self._turn_on_transition_max}"
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
if seconds <= 0:
|
|
130
|
+
return await self.call(
|
|
131
|
+
"set_on_off_gradually_info",
|
|
132
|
+
{"on_state": {**self._turn_on, "enable": False}},
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return await self.call(
|
|
136
|
+
"set_on_off_gradually_info",
|
|
137
|
+
{"on_state": {**self._turn_on, "duration": seconds}},
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def turn_off_transition(self) -> int:
|
|
142
|
+
"""Return transition time for turning the light off.
|
|
143
|
+
|
|
144
|
+
Available only from v2.
|
|
145
|
+
"""
|
|
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"]
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def _turn_off_transition_max(self) -> int:
|
|
152
|
+
"""Maximum turn on duration."""
|
|
153
|
+
# v3 added max_duration, we default to 60 when it's not available
|
|
154
|
+
return self._turn_off.get("max_duration", 60)
|
|
155
|
+
|
|
156
|
+
async def set_turn_off_transition(self, seconds: int):
|
|
157
|
+
"""Set turn on transition in seconds.
|
|
158
|
+
|
|
159
|
+
Setting to 0 turns the feature off.
|
|
160
|
+
"""
|
|
161
|
+
if seconds > self._turn_off_transition_max:
|
|
162
|
+
raise ValueError(
|
|
163
|
+
f"Value {seconds} out of range, max {self._turn_off_transition_max}"
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
if seconds <= 0:
|
|
167
|
+
return await self.call(
|
|
168
|
+
"set_on_off_gradually_info",
|
|
169
|
+
{"off_state": {**self._turn_off, "enable": False}},
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
return await self.call(
|
|
173
|
+
"set_on_off_gradually_info",
|
|
174
|
+
{"off_state": {**self._turn_on, "duration": seconds}},
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
def query(self) -> dict:
|
|
178
|
+
"""Query to execute during the update cycle."""
|
|
179
|
+
# Some devices have the required info in the device info.
|
|
180
|
+
if "gradually_on_mode" in self._device.sys_info:
|
|
181
|
+
return {}
|
|
182
|
+
else:
|
|
183
|
+
return {self.QUERY_GETTER_NAME: None}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Implementation of report module."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
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 ReportMode(SmartModule):
|
|
15
|
+
"""Implementation of report module."""
|
|
16
|
+
|
|
17
|
+
REQUIRED_COMPONENT = "report_mode"
|
|
18
|
+
QUERY_GETTER_NAME = "get_report_mode"
|
|
19
|
+
|
|
20
|
+
def __init__(self, device: SmartDevice, module: str):
|
|
21
|
+
super().__init__(device, module)
|
|
22
|
+
self._add_feature(
|
|
23
|
+
Feature(
|
|
24
|
+
device,
|
|
25
|
+
id="report_interval",
|
|
26
|
+
name="Report interval",
|
|
27
|
+
container=self,
|
|
28
|
+
attribute_getter="report_interval",
|
|
29
|
+
category=Feature.Category.Debug,
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def report_interval(self):
|
|
35
|
+
"""Reporting interval of a sensor device."""
|
|
36
|
+
return self._device.sys_info["report_interval"]
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""Implementation of temperature control module."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
from ...feature import Feature
|
|
10
|
+
from ..smartmodule import SmartModule
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ..smartdevice import SmartDevice
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
_LOGGER = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ThermostatState(Enum):
|
|
20
|
+
"""Thermostat state."""
|
|
21
|
+
|
|
22
|
+
Heating = "heating"
|
|
23
|
+
Calibrating = "progress_calibration"
|
|
24
|
+
Idle = "idle"
|
|
25
|
+
Off = "off"
|
|
26
|
+
Unknown = "unknown"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TemperatureControl(SmartModule):
|
|
30
|
+
"""Implementation of temperature module."""
|
|
31
|
+
|
|
32
|
+
REQUIRED_COMPONENT = "temp_control"
|
|
33
|
+
|
|
34
|
+
def __init__(self, device: SmartDevice, module: str):
|
|
35
|
+
super().__init__(device, module)
|
|
36
|
+
self._add_feature(
|
|
37
|
+
Feature(
|
|
38
|
+
device,
|
|
39
|
+
id="target_temperature",
|
|
40
|
+
name="Target temperature",
|
|
41
|
+
container=self,
|
|
42
|
+
attribute_getter="target_temperature",
|
|
43
|
+
attribute_setter="set_target_temperature",
|
|
44
|
+
range_getter="allowed_temperature_range",
|
|
45
|
+
icon="mdi:thermometer",
|
|
46
|
+
type=Feature.Type.Number,
|
|
47
|
+
category=Feature.Category.Primary,
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
# TODO: this might belong into its own module, temperature_correction?
|
|
51
|
+
self._add_feature(
|
|
52
|
+
Feature(
|
|
53
|
+
device,
|
|
54
|
+
id="temperature_offset",
|
|
55
|
+
name="Temperature offset",
|
|
56
|
+
container=self,
|
|
57
|
+
attribute_getter="temperature_offset",
|
|
58
|
+
attribute_setter="set_temperature_offset",
|
|
59
|
+
minimum_value=-10,
|
|
60
|
+
maximum_value=10,
|
|
61
|
+
type=Feature.Type.Number,
|
|
62
|
+
category=Feature.Category.Config,
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
self._add_feature(
|
|
67
|
+
Feature(
|
|
68
|
+
device,
|
|
69
|
+
id="state",
|
|
70
|
+
name="State",
|
|
71
|
+
container=self,
|
|
72
|
+
attribute_getter="state",
|
|
73
|
+
attribute_setter="set_state",
|
|
74
|
+
category=Feature.Category.Primary,
|
|
75
|
+
type=Feature.Type.Switch,
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
self._add_feature(
|
|
80
|
+
Feature(
|
|
81
|
+
device,
|
|
82
|
+
id="mode",
|
|
83
|
+
name="Mode",
|
|
84
|
+
container=self,
|
|
85
|
+
attribute_getter="mode",
|
|
86
|
+
category=Feature.Category.Primary,
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def query(self) -> dict:
|
|
91
|
+
"""Query to execute during the update cycle."""
|
|
92
|
+
# Target temperature is contained in the main device info response.
|
|
93
|
+
return {}
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def state(self) -> bool:
|
|
97
|
+
"""Return thermostat state."""
|
|
98
|
+
return self._device.sys_info["frost_protection_on"] is False
|
|
99
|
+
|
|
100
|
+
async def set_state(self, enabled: bool):
|
|
101
|
+
"""Set thermostat state."""
|
|
102
|
+
return await self.call("set_device_info", {"frost_protection_on": not enabled})
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def mode(self) -> ThermostatState:
|
|
106
|
+
"""Return thermostat state."""
|
|
107
|
+
# If frost protection is enabled, the thermostat is off.
|
|
108
|
+
if self._device.sys_info.get("frost_protection_on", False):
|
|
109
|
+
return ThermostatState.Off
|
|
110
|
+
|
|
111
|
+
states = self._device.sys_info["trv_states"]
|
|
112
|
+
|
|
113
|
+
# If the states is empty, the device is idling
|
|
114
|
+
if not states:
|
|
115
|
+
return ThermostatState.Idle
|
|
116
|
+
|
|
117
|
+
if len(states) > 1:
|
|
118
|
+
_LOGGER.warning(
|
|
119
|
+
"Got multiple states (%s), using the first one: %s", states, states[0]
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
state = states[0]
|
|
123
|
+
try:
|
|
124
|
+
return ThermostatState(state)
|
|
125
|
+
except: # noqa: E722
|
|
126
|
+
_LOGGER.warning("Got unknown state: %s", state)
|
|
127
|
+
return ThermostatState.Unknown
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def allowed_temperature_range(self) -> tuple[int, int]:
|
|
131
|
+
"""Return allowed temperature range."""
|
|
132
|
+
return self.minimum_target_temperature, self.maximum_target_temperature
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def minimum_target_temperature(self) -> int:
|
|
136
|
+
"""Minimum available target temperature."""
|
|
137
|
+
return self._device.sys_info["min_control_temp"]
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def maximum_target_temperature(self) -> int:
|
|
141
|
+
"""Minimum available target temperature."""
|
|
142
|
+
return self._device.sys_info["max_control_temp"]
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def target_temperature(self) -> float:
|
|
146
|
+
"""Return target temperature."""
|
|
147
|
+
return self._device.sys_info["target_temp"]
|
|
148
|
+
|
|
149
|
+
async def set_target_temperature(self, target: float):
|
|
150
|
+
"""Set target temperature."""
|
|
151
|
+
if (
|
|
152
|
+
target < self.minimum_target_temperature
|
|
153
|
+
or target > self.maximum_target_temperature
|
|
154
|
+
):
|
|
155
|
+
raise ValueError(
|
|
156
|
+
f"Invalid target temperature {target}, must be in range "
|
|
157
|
+
f"[{self.minimum_target_temperature},{self.maximum_target_temperature}]"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
payload = {"target_temp": target}
|
|
161
|
+
# If the device has frost protection, we set it off to enable heating
|
|
162
|
+
if "frost_protection_on" in self._device.sys_info:
|
|
163
|
+
payload["frost_protection_on"] = False
|
|
164
|
+
|
|
165
|
+
return await self.call("set_device_info", payload)
|
|
166
|
+
|
|
167
|
+
@property
|
|
168
|
+
def temperature_offset(self) -> int:
|
|
169
|
+
"""Return temperature offset."""
|
|
170
|
+
return self._device.sys_info["temp_offset"]
|
|
171
|
+
|
|
172
|
+
async def set_temperature_offset(self, offset: int):
|
|
173
|
+
"""Set temperature offset."""
|
|
174
|
+
if offset < -10 or offset > 10:
|
|
175
|
+
raise ValueError("Temperature offset must be [-10, 10]")
|
|
176
|
+
|
|
177
|
+
return await self.call("set_device_info", {"temp_offset": offset})
|