python-kasa 0.7.0.dev4__py3-none-any.whl → 0.7.0.1__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/aestransport.py +6 -2
- kasa/cli.py +117 -66
- kasa/device.py +126 -33
- kasa/discover.py +2 -1
- kasa/feature.py +90 -14
- kasa/httpclient.py +1 -1
- kasa/interfaces/__init__.py +2 -0
- kasa/interfaces/energy.py +187 -0
- kasa/interfaces/light.py +61 -1
- kasa/interfaces/lighteffect.py +41 -1
- kasa/interfaces/lightpreset.py +70 -2
- kasa/iot/iotbulb.py +1 -1
- kasa/iot/iotdevice.py +32 -102
- kasa/iot/iotstrip.py +125 -62
- kasa/iot/modules/emeter.py +30 -89
- kasa/iot/modules/led.py +5 -0
- kasa/iot/modules/lightpreset.py +2 -1
- kasa/module.py +41 -4
- kasa/smart/modules/alarm.py +1 -0
- kasa/smart/modules/autooff.py +3 -1
- kasa/smart/modules/childdevice.py +39 -1
- kasa/smart/modules/energy.py +58 -60
- kasa/smart/modules/firmware.py +4 -1
- kasa/smart/modules/frostprotection.py +0 -22
- kasa/smart/modules/humiditysensor.py +1 -0
- kasa/smart/modules/led.py +1 -1
- kasa/smart/modules/lightpreset.py +2 -1
- kasa/smart/modules/lightstripeffect.py +14 -4
- kasa/smart/modules/lighttransition.py +8 -0
- kasa/smart/modules/reportmode.py +2 -0
- kasa/smart/modules/temperaturecontrol.py +3 -2
- kasa/smart/modules/temperaturesensor.py +3 -2
- kasa/smart/modules/time.py +10 -3
- kasa/smart/modules/waterleaksensor.py +2 -0
- kasa/smart/smartdevice.py +29 -51
- kasa/tests/device_fixtures.py +1 -1
- kasa/tests/discovery_fixtures.py +3 -1
- kasa/tests/fakeprotocol_smart.py +2 -2
- kasa/tests/fixtures/smart/L920-5(EU)_1.0_1.0.7.json +350 -0
- kasa/tests/smart/modules/test_firmware.py +12 -1
- kasa/tests/test_cli.py +55 -8
- kasa/tests/test_device.py +16 -7
- kasa/tests/test_emeter.py +44 -16
- kasa/tests/test_feature.py +6 -2
- kasa/tests/test_httpclient.py +2 -2
- kasa/tests/test_iotdevice.py +14 -6
- kasa/tests/test_readme_examples.py +59 -0
- kasa/tests/test_smartdevice.py +4 -3
- kasa/tests/test_strip.py +15 -2
- kasa/xortransport.py +3 -3
- {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/METADATA +102 -129
- {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/RECORD +55 -53
- {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/LICENSE +0 -0
- {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/WHEEL +0 -0
- {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/entry_points.txt +0 -0
kasa/feature.py
CHANGED
|
@@ -1,4 +1,67 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Interact with feature.
|
|
2
|
+
|
|
3
|
+
Features are implemented by devices to represent individual pieces of functionality like
|
|
4
|
+
state, time, firmware.
|
|
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
|
+
Features allow for instrospection and can be interacted with as new features are added
|
|
18
|
+
to the API:
|
|
19
|
+
|
|
20
|
+
>>> for feature_id, feature in dev.features.items():
|
|
21
|
+
>>> print(f"{feature.name} ({feature_id}): {feature.value}")
|
|
22
|
+
Device ID (device_id): 0000000000000000000000000000000000000000
|
|
23
|
+
State (state): True
|
|
24
|
+
Signal Level (signal_level): 2
|
|
25
|
+
RSSI (rssi): -52
|
|
26
|
+
SSID (ssid): #MASKED_SSID#
|
|
27
|
+
Overheated (overheated): False
|
|
28
|
+
Brightness (brightness): 100
|
|
29
|
+
Cloud connection (cloud_connection): True
|
|
30
|
+
HSV (hsv): HSV(hue=0, saturation=100, value=100)
|
|
31
|
+
Color temperature (color_temperature): 2700
|
|
32
|
+
Auto update enabled (auto_update_enabled): False
|
|
33
|
+
Update available (update_available): False
|
|
34
|
+
Current firmware version (current_firmware_version): 1.1.6 Build 240130 Rel.173828
|
|
35
|
+
Available firmware version (available_firmware_version): 1.1.6 Build 240130 Rel.173828
|
|
36
|
+
Light effect (light_effect): Off
|
|
37
|
+
Light preset (light_preset): Not set
|
|
38
|
+
Smooth transition on (smooth_transition_on): 2
|
|
39
|
+
Smooth transition off (smooth_transition_off): 2
|
|
40
|
+
Device time (device_time): 2024-02-23 02:40:15+01:00
|
|
41
|
+
|
|
42
|
+
To see whether a device supports a feature, check for the existence of it:
|
|
43
|
+
|
|
44
|
+
>>> if feature := dev.features.get("brightness"):
|
|
45
|
+
>>> print(feature.value)
|
|
46
|
+
100
|
|
47
|
+
|
|
48
|
+
You can update the value of a feature
|
|
49
|
+
|
|
50
|
+
>>> await feature.set_value(50)
|
|
51
|
+
>>> await dev.update()
|
|
52
|
+
>>> print(feature.value)
|
|
53
|
+
50
|
|
54
|
+
|
|
55
|
+
Features have types that can be used for introspection:
|
|
56
|
+
|
|
57
|
+
>>> feature = dev.features["light_preset"]
|
|
58
|
+
>>> print(feature.type)
|
|
59
|
+
Type.Choice
|
|
60
|
+
|
|
61
|
+
>>> print(feature.choices)
|
|
62
|
+
['Not set', 'Light preset 1', 'Light preset 2', 'Light preset 3',\
|
|
63
|
+
'Light preset 4', 'Light preset 5', 'Light preset 6', 'Light preset 7']
|
|
64
|
+
"""
|
|
2
65
|
|
|
3
66
|
from __future__ import annotations
|
|
4
67
|
|
|
@@ -10,7 +73,6 @@ from typing import TYPE_CHECKING, Any, Callable
|
|
|
10
73
|
if TYPE_CHECKING:
|
|
11
74
|
from .device import Device
|
|
12
75
|
|
|
13
|
-
|
|
14
76
|
_LOGGER = logging.getLogger(__name__)
|
|
15
77
|
|
|
16
78
|
|
|
@@ -37,7 +99,7 @@ class Feature:
|
|
|
37
99
|
Choice = auto()
|
|
38
100
|
Unknown = -1
|
|
39
101
|
|
|
40
|
-
#
|
|
102
|
+
# Aliases for easy access
|
|
41
103
|
Sensor = Type.Sensor
|
|
42
104
|
BinarySensor = Type.BinarySensor
|
|
43
105
|
Switch = Type.Switch
|
|
@@ -67,6 +129,8 @@ class Feature:
|
|
|
67
129
|
id: str
|
|
68
130
|
#: User-friendly short description
|
|
69
131
|
name: str
|
|
132
|
+
#: Type of the feature
|
|
133
|
+
type: Feature.Type
|
|
70
134
|
#: Name of the property that allows accessing the value
|
|
71
135
|
attribute_getter: str | Callable | None = None
|
|
72
136
|
#: Name of the method that allows changing the value
|
|
@@ -77,10 +141,11 @@ class Feature:
|
|
|
77
141
|
icon: str | None = None
|
|
78
142
|
#: Unit, if applicable
|
|
79
143
|
unit: str | None = None
|
|
144
|
+
#: Attribute containing the name of the unit getter property.
|
|
145
|
+
#: If set, this property will be used to set *unit*.
|
|
146
|
+
unit_getter: str | None = None
|
|
80
147
|
#: Category hint for downstreams
|
|
81
148
|
category: Feature.Category = Category.Unset
|
|
82
|
-
#: Type of the feature
|
|
83
|
-
type: Feature.Type = Type.Sensor
|
|
84
149
|
|
|
85
150
|
# Display hints offer a way suggest how the value should be shown to users
|
|
86
151
|
#: Hint to help rounding the sensor values to given after-comma digits
|
|
@@ -115,6 +180,10 @@ class Feature:
|
|
|
115
180
|
if self.choices_getter is not None:
|
|
116
181
|
self.choices = getattr(container, self.choices_getter)
|
|
117
182
|
|
|
183
|
+
# Populate unit, if unit_getter is given
|
|
184
|
+
if self.unit_getter is not None:
|
|
185
|
+
self.unit = getattr(container, self.unit_getter)
|
|
186
|
+
|
|
118
187
|
# Set the category, if unset
|
|
119
188
|
if self.category is Feature.Category.Unset:
|
|
120
189
|
if self.attribute_setter:
|
|
@@ -122,14 +191,19 @@ class Feature:
|
|
|
122
191
|
else:
|
|
123
192
|
self.category = Feature.Category.Info
|
|
124
193
|
|
|
125
|
-
if self.
|
|
194
|
+
if self.type in (
|
|
126
195
|
Feature.Type.Sensor,
|
|
127
196
|
Feature.Type.BinarySensor,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
197
|
+
):
|
|
198
|
+
if self.category == Feature.Category.Config:
|
|
199
|
+
raise ValueError(
|
|
200
|
+
f"Invalid type for configurable feature: {self.name} ({self.id}):"
|
|
201
|
+
f" {self.type}"
|
|
202
|
+
)
|
|
203
|
+
elif self.attribute_setter is not None:
|
|
204
|
+
raise ValueError(
|
|
205
|
+
f"Read-only feat defines attribute_setter: {self.name} ({self.id}):"
|
|
206
|
+
)
|
|
133
207
|
|
|
134
208
|
@property
|
|
135
209
|
def value(self):
|
|
@@ -140,22 +214,24 @@ class Feature:
|
|
|
140
214
|
raise ValueError("Not an action and no attribute_getter set")
|
|
141
215
|
|
|
142
216
|
container = self.container if self.container is not None else self.device
|
|
143
|
-
if
|
|
217
|
+
if callable(self.attribute_getter):
|
|
144
218
|
return self.attribute_getter(container)
|
|
145
219
|
return getattr(container, self.attribute_getter)
|
|
146
220
|
|
|
147
|
-
async def set_value(self, value):
|
|
221
|
+
async def set_value(self, value: int | float | bool | str | Enum | None) -> Any:
|
|
148
222
|
"""Set the value."""
|
|
149
223
|
if self.attribute_setter is None:
|
|
150
224
|
raise ValueError("Tried to set read-only feature.")
|
|
151
225
|
if self.type == Feature.Type.Number: # noqa: SIM102
|
|
226
|
+
if not isinstance(value, (int, float)):
|
|
227
|
+
raise ValueError("value must be a number")
|
|
152
228
|
if value < self.minimum_value or value > self.maximum_value:
|
|
153
229
|
raise ValueError(
|
|
154
230
|
f"Value {value} out of range "
|
|
155
231
|
f"[{self.minimum_value}, {self.maximum_value}]"
|
|
156
232
|
)
|
|
157
233
|
elif self.type == Feature.Type.Choice: # noqa: SIM102
|
|
158
|
-
if value not in self.choices:
|
|
234
|
+
if not self.choices or value not in self.choices:
|
|
159
235
|
raise ValueError(
|
|
160
236
|
f"Unexpected value for {self.name}: {value}"
|
|
161
237
|
f" - allowed: {self.choices}"
|
kasa/httpclient.py
CHANGED
|
@@ -36,7 +36,7 @@ class HttpClient:
|
|
|
36
36
|
|
|
37
37
|
def __init__(self, config: DeviceConfig) -> None:
|
|
38
38
|
self._config = config
|
|
39
|
-
self._client_session: aiohttp.ClientSession = None
|
|
39
|
+
self._client_session: aiohttp.ClientSession | None = None
|
|
40
40
|
self._jar = aiohttp.CookieJar(unsafe=True, quote_cookie=False)
|
|
41
41
|
self._last_url = URL(f"http://{self._config.host}/")
|
|
42
42
|
|
kasa/interfaces/__init__.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Package for interfaces."""
|
|
2
2
|
|
|
3
|
+
from .energy import Energy
|
|
3
4
|
from .fan import Fan
|
|
4
5
|
from .led import Led
|
|
5
6
|
from .light import Light, LightState
|
|
@@ -8,6 +9,7 @@ from .lightpreset import LightPreset
|
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
10
11
|
"Fan",
|
|
12
|
+
"Energy",
|
|
11
13
|
"Led",
|
|
12
14
|
"Light",
|
|
13
15
|
"LightEffect",
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Module for base energy module."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from enum import IntFlag, auto
|
|
7
|
+
from warnings import warn
|
|
8
|
+
|
|
9
|
+
from ..emeterstatus import EmeterStatus
|
|
10
|
+
from ..feature import Feature
|
|
11
|
+
from ..module import Module
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Energy(Module, ABC):
|
|
15
|
+
"""Base interface to represent an Energy module."""
|
|
16
|
+
|
|
17
|
+
class ModuleFeature(IntFlag):
|
|
18
|
+
"""Features supported by the device."""
|
|
19
|
+
|
|
20
|
+
#: Device reports :attr:`voltage` and :attr:`current`
|
|
21
|
+
VOLTAGE_CURRENT = auto()
|
|
22
|
+
#: Device reports :attr:`consumption_total`
|
|
23
|
+
CONSUMPTION_TOTAL = auto()
|
|
24
|
+
#: Device reports periodic stats via :meth:`get_daily_stats`
|
|
25
|
+
#: and :meth:`get_monthly_stats`
|
|
26
|
+
PERIODIC_STATS = auto()
|
|
27
|
+
|
|
28
|
+
_supported: ModuleFeature = ModuleFeature(0)
|
|
29
|
+
|
|
30
|
+
def supports(self, module_feature: ModuleFeature) -> bool:
|
|
31
|
+
"""Return True if module supports the feature."""
|
|
32
|
+
return module_feature in self._supported
|
|
33
|
+
|
|
34
|
+
def _initialize_features(self):
|
|
35
|
+
"""Initialize features."""
|
|
36
|
+
device = self._device
|
|
37
|
+
self._add_feature(
|
|
38
|
+
Feature(
|
|
39
|
+
device,
|
|
40
|
+
name="Current consumption",
|
|
41
|
+
attribute_getter="current_consumption",
|
|
42
|
+
container=self,
|
|
43
|
+
unit="W",
|
|
44
|
+
id="current_consumption",
|
|
45
|
+
precision_hint=1,
|
|
46
|
+
category=Feature.Category.Primary,
|
|
47
|
+
type=Feature.Type.Sensor,
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
self._add_feature(
|
|
51
|
+
Feature(
|
|
52
|
+
device,
|
|
53
|
+
name="Today's consumption",
|
|
54
|
+
attribute_getter="consumption_today",
|
|
55
|
+
container=self,
|
|
56
|
+
unit="kWh",
|
|
57
|
+
id="consumption_today",
|
|
58
|
+
precision_hint=3,
|
|
59
|
+
category=Feature.Category.Info,
|
|
60
|
+
type=Feature.Type.Sensor,
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
self._add_feature(
|
|
64
|
+
Feature(
|
|
65
|
+
device,
|
|
66
|
+
id="consumption_this_month",
|
|
67
|
+
name="This month's consumption",
|
|
68
|
+
attribute_getter="consumption_this_month",
|
|
69
|
+
container=self,
|
|
70
|
+
unit="kWh",
|
|
71
|
+
precision_hint=3,
|
|
72
|
+
category=Feature.Category.Info,
|
|
73
|
+
type=Feature.Type.Sensor,
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
if self.supports(self.ModuleFeature.CONSUMPTION_TOTAL):
|
|
77
|
+
self._add_feature(
|
|
78
|
+
Feature(
|
|
79
|
+
device,
|
|
80
|
+
name="Total consumption since reboot",
|
|
81
|
+
attribute_getter="consumption_total",
|
|
82
|
+
container=self,
|
|
83
|
+
unit="kWh",
|
|
84
|
+
id="consumption_total",
|
|
85
|
+
precision_hint=3,
|
|
86
|
+
category=Feature.Category.Info,
|
|
87
|
+
type=Feature.Type.Sensor,
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
if self.supports(self.ModuleFeature.VOLTAGE_CURRENT):
|
|
91
|
+
self._add_feature(
|
|
92
|
+
Feature(
|
|
93
|
+
device,
|
|
94
|
+
name="Voltage",
|
|
95
|
+
attribute_getter="voltage",
|
|
96
|
+
container=self,
|
|
97
|
+
unit="V",
|
|
98
|
+
id="voltage",
|
|
99
|
+
precision_hint=1,
|
|
100
|
+
category=Feature.Category.Primary,
|
|
101
|
+
type=Feature.Type.Sensor,
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
self._add_feature(
|
|
105
|
+
Feature(
|
|
106
|
+
device,
|
|
107
|
+
name="Current",
|
|
108
|
+
attribute_getter="current",
|
|
109
|
+
container=self,
|
|
110
|
+
unit="A",
|
|
111
|
+
id="current",
|
|
112
|
+
precision_hint=2,
|
|
113
|
+
category=Feature.Category.Primary,
|
|
114
|
+
type=Feature.Type.Sensor,
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
@abstractmethod
|
|
120
|
+
def status(self) -> EmeterStatus:
|
|
121
|
+
"""Return current energy readings."""
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
@abstractmethod
|
|
125
|
+
def current_consumption(self) -> float | None:
|
|
126
|
+
"""Get the current power consumption in Watt."""
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
@abstractmethod
|
|
130
|
+
def consumption_today(self) -> float | None:
|
|
131
|
+
"""Return today's energy consumption in kWh."""
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
@abstractmethod
|
|
135
|
+
def consumption_this_month(self) -> float | None:
|
|
136
|
+
"""Return this month's energy consumption in kWh."""
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
@abstractmethod
|
|
140
|
+
def consumption_total(self) -> float | None:
|
|
141
|
+
"""Return total consumption since last reboot in kWh."""
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
@abstractmethod
|
|
145
|
+
def current(self) -> float | None:
|
|
146
|
+
"""Return the current in A."""
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
@abstractmethod
|
|
150
|
+
def voltage(self) -> float | None:
|
|
151
|
+
"""Get the current voltage in V."""
|
|
152
|
+
|
|
153
|
+
@abstractmethod
|
|
154
|
+
async def get_status(self):
|
|
155
|
+
"""Return real-time statistics."""
|
|
156
|
+
|
|
157
|
+
@abstractmethod
|
|
158
|
+
async def erase_stats(self):
|
|
159
|
+
"""Erase all stats."""
|
|
160
|
+
|
|
161
|
+
@abstractmethod
|
|
162
|
+
async def get_daily_stats(self, *, year=None, month=None, kwh=True) -> dict:
|
|
163
|
+
"""Return daily stats for the given year & month.
|
|
164
|
+
|
|
165
|
+
The return value is a dictionary of {day: energy, ...}.
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
@abstractmethod
|
|
169
|
+
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
|
|
170
|
+
"""Return monthly stats for the given year."""
|
|
171
|
+
|
|
172
|
+
_deprecated_attributes = {
|
|
173
|
+
"emeter_today": "consumption_today",
|
|
174
|
+
"emeter_this_month": "consumption_this_month",
|
|
175
|
+
"realtime": "status",
|
|
176
|
+
"get_realtime": "get_status",
|
|
177
|
+
"erase_emeter_stats": "erase_stats",
|
|
178
|
+
"get_daystat": "get_daily_stats",
|
|
179
|
+
"get_monthstat": "get_monthly_stats",
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
def __getattr__(self, name):
|
|
183
|
+
if attr := self._deprecated_attributes.get(name):
|
|
184
|
+
msg = f"{name} is deprecated, use {attr} instead"
|
|
185
|
+
warn(msg, DeprecationWarning, stacklevel=1)
|
|
186
|
+
return getattr(self, attr)
|
|
187
|
+
raise AttributeError(f"Energy module has no attribute {name!r}")
|
kasa/interfaces/light.py
CHANGED
|
@@ -1,4 +1,64 @@
|
|
|
1
|
-
"""
|
|
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
|
|
kasa/interfaces/lighteffect.py
CHANGED
|
@@ -1,4 +1,44 @@
|
|
|
1
|
-
"""
|
|
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
|
|
kasa/interfaces/lightpreset.py
CHANGED
|
@@ -1,9 +1,77 @@
|
|
|
1
|
-
"""
|
|
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
|
|
74
|
+
from collections.abc import Sequence
|
|
7
75
|
|
|
8
76
|
from ..feature import Feature
|
|
9
77
|
from ..module import Module
|
kasa/iot/iotbulb.py
CHANGED
|
@@ -220,7 +220,7 @@ class IotBulb(IotDevice):
|
|
|
220
220
|
Module.IotAntitheft, Antitheft(self, "smartlife.iot.common.anti_theft")
|
|
221
221
|
)
|
|
222
222
|
self.add_module(Module.IotTime, Time(self, "smartlife.iot.common.timesetting"))
|
|
223
|
-
self.add_module(Module.
|
|
223
|
+
self.add_module(Module.Energy, Emeter(self, self.emeter_type))
|
|
224
224
|
self.add_module(Module.IotCountdown, Countdown(self, "countdown"))
|
|
225
225
|
self.add_module(Module.IotCloud, Cloud(self, "smartlife.iot.common.cloud"))
|
|
226
226
|
self.add_module(Module.Light, Light(self, self.LIGHT_SERVICE))
|