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
kasa/modules/emeter.py
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"""Implementation of the emeter module."""
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from typing import Dict, List, Optional, Union
|
|
4
|
-
|
|
5
|
-
from ..emeterstatus import EmeterStatus
|
|
6
|
-
from .usage import Usage
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class Emeter(Usage):
|
|
10
|
-
"""Emeter module."""
|
|
11
|
-
|
|
12
|
-
@property # type: ignore
|
|
13
|
-
def realtime(self) -> EmeterStatus:
|
|
14
|
-
"""Return current energy readings."""
|
|
15
|
-
return EmeterStatus(self.data["get_realtime"])
|
|
16
|
-
|
|
17
|
-
@property
|
|
18
|
-
def emeter_today(self) -> Optional[float]:
|
|
19
|
-
"""Return today's energy consumption in kWh."""
|
|
20
|
-
raw_data = self.daily_data
|
|
21
|
-
today = datetime.now().day
|
|
22
|
-
data = self._convert_stat_data(raw_data, entry_key="day", key=today)
|
|
23
|
-
return data.get(today)
|
|
24
|
-
|
|
25
|
-
@property
|
|
26
|
-
def emeter_this_month(self) -> Optional[float]:
|
|
27
|
-
"""Return this month's energy consumption in kWh."""
|
|
28
|
-
raw_data = self.monthly_data
|
|
29
|
-
current_month = datetime.now().month
|
|
30
|
-
data = self._convert_stat_data(raw_data, entry_key="month", key=current_month)
|
|
31
|
-
return data.get(current_month)
|
|
32
|
-
|
|
33
|
-
async def erase_stats(self):
|
|
34
|
-
"""Erase all stats.
|
|
35
|
-
|
|
36
|
-
Uses different query than usage meter.
|
|
37
|
-
"""
|
|
38
|
-
return await self.call("erase_emeter_stat")
|
|
39
|
-
|
|
40
|
-
async def get_realtime(self):
|
|
41
|
-
"""Return real-time statistics."""
|
|
42
|
-
return await self.call("get_realtime")
|
|
43
|
-
|
|
44
|
-
async def get_daystat(self, *, year=None, month=None, kwh=True) -> Dict:
|
|
45
|
-
"""Return daily stats for the given year & month.
|
|
46
|
-
|
|
47
|
-
The return value is a dictionary of {day: energy, ...}.
|
|
48
|
-
"""
|
|
49
|
-
data = await self.get_raw_daystat(year=year, month=month)
|
|
50
|
-
data = self._convert_stat_data(data["day_list"], entry_key="day", kwh=kwh)
|
|
51
|
-
return data
|
|
52
|
-
|
|
53
|
-
async def get_monthstat(self, *, year=None, kwh=True) -> Dict:
|
|
54
|
-
"""Return monthly stats for the given year.
|
|
55
|
-
|
|
56
|
-
The return value is a dictionary of {month: energy, ...}.
|
|
57
|
-
"""
|
|
58
|
-
data = await self.get_raw_monthstat(year=year)
|
|
59
|
-
data = self._convert_stat_data(data["month_list"], entry_key="month", kwh=kwh)
|
|
60
|
-
return data
|
|
61
|
-
|
|
62
|
-
def _convert_stat_data(
|
|
63
|
-
self,
|
|
64
|
-
data: List[Dict[str, Union[int, float]]],
|
|
65
|
-
entry_key: str,
|
|
66
|
-
kwh: bool = True,
|
|
67
|
-
key: Optional[int] = None,
|
|
68
|
-
) -> Dict[Union[int, float], Union[int, float]]:
|
|
69
|
-
"""Return emeter information keyed with the day/month.
|
|
70
|
-
|
|
71
|
-
The incoming data is a list of dictionaries::
|
|
72
|
-
|
|
73
|
-
[{'year': int,
|
|
74
|
-
'month': int,
|
|
75
|
-
'day': int, <-- for get_daystat not get_monthstat
|
|
76
|
-
'energy_wh': int, <-- for emeter in some versions (wh)
|
|
77
|
-
'energy': float <-- for emeter in other versions (kwh)
|
|
78
|
-
}, ...]
|
|
79
|
-
|
|
80
|
-
:return: a dictionary keyed by day or month with energy as the value.
|
|
81
|
-
"""
|
|
82
|
-
if not data:
|
|
83
|
-
return {}
|
|
84
|
-
|
|
85
|
-
scale: float = 1
|
|
86
|
-
|
|
87
|
-
if "energy_wh" in data[0]:
|
|
88
|
-
value_key = "energy_wh"
|
|
89
|
-
if kwh:
|
|
90
|
-
scale = 1 / 1000
|
|
91
|
-
else:
|
|
92
|
-
value_key = "energy"
|
|
93
|
-
if not kwh:
|
|
94
|
-
scale = 1000
|
|
95
|
-
|
|
96
|
-
if key is None:
|
|
97
|
-
# Return all the data
|
|
98
|
-
return {entry[entry_key]: entry[value_key] * scale for entry in data}
|
|
99
|
-
|
|
100
|
-
# In this case we want a specific key in the data
|
|
101
|
-
# i.e. the current day or month.
|
|
102
|
-
#
|
|
103
|
-
# Since we usually want the data at the end of the list so we can
|
|
104
|
-
# optimize the search by starting at the end and avoid scaling
|
|
105
|
-
# the data we don't need.
|
|
106
|
-
#
|
|
107
|
-
for entry in reversed(data):
|
|
108
|
-
if entry[entry_key] == key:
|
|
109
|
-
return {entry[entry_key]: entry[value_key] * scale}
|
|
110
|
-
|
|
111
|
-
return {}
|
kasa/smartlightstrip.py
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"""Module for light strips (KL430)."""
|
|
2
|
-
from typing import Any, Dict, List, Optional
|
|
3
|
-
|
|
4
|
-
from .deviceconfig import DeviceConfig
|
|
5
|
-
from .effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
|
|
6
|
-
from .protocol import BaseProtocol
|
|
7
|
-
from .smartbulb import SmartBulb
|
|
8
|
-
from .smartdevice import DeviceType, SmartDeviceException, requires_update
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class SmartLightStrip(SmartBulb):
|
|
12
|
-
"""Representation of a TP-Link Smart light strip.
|
|
13
|
-
|
|
14
|
-
Light strips work similarly to bulbs, but use a different service for controlling,
|
|
15
|
-
and expose some extra information (such as length and active effect).
|
|
16
|
-
This class extends :class:`SmartBulb` interface.
|
|
17
|
-
|
|
18
|
-
Examples:
|
|
19
|
-
>>> import asyncio
|
|
20
|
-
>>> strip = SmartLightStrip("127.0.0.1")
|
|
21
|
-
>>> asyncio.run(strip.update())
|
|
22
|
-
>>> print(strip.alias)
|
|
23
|
-
KL430 pantry lightstrip
|
|
24
|
-
|
|
25
|
-
Getting the length of the strip:
|
|
26
|
-
|
|
27
|
-
>>> strip.length
|
|
28
|
-
16
|
|
29
|
-
|
|
30
|
-
Currently active effect:
|
|
31
|
-
|
|
32
|
-
>>> strip.effect
|
|
33
|
-
{'brightness': 50, 'custom': 0, 'enable': 0, 'id': '', 'name': ''}
|
|
34
|
-
|
|
35
|
-
.. note::
|
|
36
|
-
The device supports some features that are not currently implemented,
|
|
37
|
-
feel free to find out how to control them and create a PR!
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
See :class:`SmartBulb` for more examples.
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
LIGHT_SERVICE = "smartlife.iot.lightStrip"
|
|
44
|
-
SET_LIGHT_METHOD = "set_light_state"
|
|
45
|
-
|
|
46
|
-
def __init__(
|
|
47
|
-
self,
|
|
48
|
-
host: str,
|
|
49
|
-
*,
|
|
50
|
-
config: Optional[DeviceConfig] = None,
|
|
51
|
-
protocol: Optional[BaseProtocol] = None,
|
|
52
|
-
) -> None:
|
|
53
|
-
super().__init__(host=host, config=config, protocol=protocol)
|
|
54
|
-
self._device_type = DeviceType.LightStrip
|
|
55
|
-
|
|
56
|
-
@property # type: ignore
|
|
57
|
-
@requires_update
|
|
58
|
-
def length(self) -> int:
|
|
59
|
-
"""Return length of the strip."""
|
|
60
|
-
return self.sys_info["length"]
|
|
61
|
-
|
|
62
|
-
@property # type: ignore
|
|
63
|
-
@requires_update
|
|
64
|
-
def effect(self) -> Dict:
|
|
65
|
-
"""Return effect state.
|
|
66
|
-
|
|
67
|
-
Example:
|
|
68
|
-
{'brightness': 50,
|
|
69
|
-
'custom': 0,
|
|
70
|
-
'enable': 0,
|
|
71
|
-
'id': '',
|
|
72
|
-
'name': ''}
|
|
73
|
-
"""
|
|
74
|
-
return self.sys_info["lighting_effect_state"]
|
|
75
|
-
|
|
76
|
-
@property # type: ignore
|
|
77
|
-
@requires_update
|
|
78
|
-
def effect_list(self) -> Optional[List[str]]:
|
|
79
|
-
"""Return built-in effects list.
|
|
80
|
-
|
|
81
|
-
Example:
|
|
82
|
-
['Aurora', 'Bubbling Cauldron', ...]
|
|
83
|
-
"""
|
|
84
|
-
return EFFECT_NAMES_V1 if self.has_effects else None
|
|
85
|
-
|
|
86
|
-
@property # type: ignore
|
|
87
|
-
@requires_update
|
|
88
|
-
def state_information(self) -> Dict[str, Any]:
|
|
89
|
-
"""Return strip specific state information."""
|
|
90
|
-
info = super().state_information
|
|
91
|
-
|
|
92
|
-
info["Length"] = self.length
|
|
93
|
-
if self.has_effects:
|
|
94
|
-
info["Effect"] = self.effect["name"]
|
|
95
|
-
|
|
96
|
-
return info
|
|
97
|
-
|
|
98
|
-
@requires_update
|
|
99
|
-
async def set_effect(
|
|
100
|
-
self,
|
|
101
|
-
effect: str,
|
|
102
|
-
*,
|
|
103
|
-
brightness: Optional[int] = None,
|
|
104
|
-
transition: Optional[int] = None,
|
|
105
|
-
) -> None:
|
|
106
|
-
"""Set an effect on the device.
|
|
107
|
-
|
|
108
|
-
If brightness or transition is defined,
|
|
109
|
-
its value will be used instead of the effect-specific default.
|
|
110
|
-
|
|
111
|
-
See :meth:`effect_list` for available effects,
|
|
112
|
-
or use :meth:`set_custom_effect` for custom effects.
|
|
113
|
-
|
|
114
|
-
:param str effect: The effect to set
|
|
115
|
-
:param int brightness: The wanted brightness
|
|
116
|
-
:param int transition: The wanted transition time
|
|
117
|
-
"""
|
|
118
|
-
if effect not in EFFECT_MAPPING_V1:
|
|
119
|
-
raise SmartDeviceException(f"The effect {effect} is not a built in effect.")
|
|
120
|
-
effect_dict = EFFECT_MAPPING_V1[effect]
|
|
121
|
-
if brightness is not None:
|
|
122
|
-
effect_dict["brightness"] = brightness
|
|
123
|
-
if transition is not None:
|
|
124
|
-
effect_dict["transition"] = transition
|
|
125
|
-
|
|
126
|
-
await self.set_custom_effect(effect_dict)
|
|
127
|
-
|
|
128
|
-
@requires_update
|
|
129
|
-
async def set_custom_effect(
|
|
130
|
-
self,
|
|
131
|
-
effect_dict: Dict,
|
|
132
|
-
) -> None:
|
|
133
|
-
"""Set a custom effect on the device.
|
|
134
|
-
|
|
135
|
-
:param str effect_dict: The custom effect dict to set
|
|
136
|
-
"""
|
|
137
|
-
if not self.has_effects:
|
|
138
|
-
raise SmartDeviceException("Bulb does not support effects.")
|
|
139
|
-
await self._query_helper(
|
|
140
|
-
"smartlife.iot.lighting_effect",
|
|
141
|
-
"set_lighting_effect",
|
|
142
|
-
effect_dict,
|
|
143
|
-
)
|
kasa/smartplug.py
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"""Module for smart plugs (HS100, HS110, ..)."""
|
|
2
|
-
import logging
|
|
3
|
-
from typing import Any, Dict, Optional
|
|
4
|
-
|
|
5
|
-
from kasa.deviceconfig import DeviceConfig
|
|
6
|
-
from kasa.modules import Antitheft, Cloud, Schedule, Time, Usage
|
|
7
|
-
from kasa.protocol import BaseProtocol
|
|
8
|
-
from kasa.smartdevice import DeviceType, SmartDevice, requires_update
|
|
9
|
-
|
|
10
|
-
_LOGGER = logging.getLogger(__name__)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class SmartPlug(SmartDevice):
|
|
14
|
-
r"""Representation of a TP-Link Smart Switch.
|
|
15
|
-
|
|
16
|
-
To initialize, you have to await :func:`update()` at least once.
|
|
17
|
-
This will allow accessing the properties using the exposed properties.
|
|
18
|
-
|
|
19
|
-
All changes to the device are done using awaitable methods,
|
|
20
|
-
which will not change the cached values,
|
|
21
|
-
but you must await :func:`update()` separately.
|
|
22
|
-
|
|
23
|
-
Errors reported by the device are raised as :class:`SmartDeviceException`\s,
|
|
24
|
-
and should be handled by the user of the library.
|
|
25
|
-
|
|
26
|
-
Examples:
|
|
27
|
-
>>> import asyncio
|
|
28
|
-
>>> plug = SmartPlug("127.0.0.1")
|
|
29
|
-
>>> asyncio.run(plug.update())
|
|
30
|
-
>>> plug.alias
|
|
31
|
-
Kitchen
|
|
32
|
-
|
|
33
|
-
Setting the LED state:
|
|
34
|
-
|
|
35
|
-
>>> asyncio.run(plug.set_led(True))
|
|
36
|
-
>>> asyncio.run(plug.update())
|
|
37
|
-
>>> plug.led
|
|
38
|
-
True
|
|
39
|
-
|
|
40
|
-
For more examples, see the :class:`SmartDevice` class.
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
def __init__(
|
|
44
|
-
self,
|
|
45
|
-
host: str,
|
|
46
|
-
*,
|
|
47
|
-
config: Optional[DeviceConfig] = None,
|
|
48
|
-
protocol: Optional[BaseProtocol] = None,
|
|
49
|
-
) -> None:
|
|
50
|
-
super().__init__(host=host, config=config, protocol=protocol)
|
|
51
|
-
self._device_type = DeviceType.Plug
|
|
52
|
-
self.add_module("schedule", Schedule(self, "schedule"))
|
|
53
|
-
self.add_module("usage", Usage(self, "schedule"))
|
|
54
|
-
self.add_module("antitheft", Antitheft(self, "anti_theft"))
|
|
55
|
-
self.add_module("time", Time(self, "time"))
|
|
56
|
-
self.add_module("cloud", Cloud(self, "cnCloud"))
|
|
57
|
-
|
|
58
|
-
@property # type: ignore
|
|
59
|
-
@requires_update
|
|
60
|
-
def is_on(self) -> bool:
|
|
61
|
-
"""Return whether device is on."""
|
|
62
|
-
sys_info = self.sys_info
|
|
63
|
-
return bool(sys_info["relay_state"])
|
|
64
|
-
|
|
65
|
-
async def turn_on(self, **kwargs):
|
|
66
|
-
"""Turn the switch on."""
|
|
67
|
-
return await self._query_helper("system", "set_relay_state", {"state": 1})
|
|
68
|
-
|
|
69
|
-
async def turn_off(self, **kwargs):
|
|
70
|
-
"""Turn the switch off."""
|
|
71
|
-
return await self._query_helper("system", "set_relay_state", {"state": 0})
|
|
72
|
-
|
|
73
|
-
@property # type: ignore
|
|
74
|
-
@requires_update
|
|
75
|
-
def led(self) -> bool:
|
|
76
|
-
"""Return the state of the led."""
|
|
77
|
-
sys_info = self.sys_info
|
|
78
|
-
return bool(1 - sys_info["led_off"])
|
|
79
|
-
|
|
80
|
-
async def set_led(self, state: bool):
|
|
81
|
-
"""Set the state of the led (night mode)."""
|
|
82
|
-
return await self._query_helper(
|
|
83
|
-
"system", "set_led_off", {"off": int(not state)}
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
@property # type: ignore
|
|
87
|
-
@requires_update
|
|
88
|
-
def state_information(self) -> Dict[str, Any]:
|
|
89
|
-
"""Return switch-specific state information."""
|
|
90
|
-
info = {"LED state": self.led, "On since": self.on_since}
|
|
91
|
-
return info
|
kasa/tapo/__init__.py
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"""Package for supporting tapo-branded and newer kasa devices."""
|
|
2
|
-
from .childdevice import ChildDevice
|
|
3
|
-
from .tapobulb import TapoBulb
|
|
4
|
-
from .tapodevice import TapoDevice
|
|
5
|
-
from .tapoplug import TapoPlug
|
|
6
|
-
|
|
7
|
-
__all__ = ["TapoDevice", "TapoPlug", "TapoBulb", "ChildDevice"]
|
kasa/tapo/childdevice.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"""Child device implementation."""
|
|
2
|
-
from typing import Dict, Optional
|
|
3
|
-
|
|
4
|
-
from ..deviceconfig import DeviceConfig
|
|
5
|
-
from ..exceptions import SmartDeviceException
|
|
6
|
-
from ..smartprotocol import SmartProtocol, _ChildProtocolWrapper
|
|
7
|
-
from .tapodevice import TapoDevice
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ChildDevice(TapoDevice):
|
|
11
|
-
"""Presentation of a child device.
|
|
12
|
-
|
|
13
|
-
This wraps the protocol communications and sets internal data for the child.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
def __init__(
|
|
17
|
-
self,
|
|
18
|
-
parent: TapoDevice,
|
|
19
|
-
child_id: str,
|
|
20
|
-
config: Optional[DeviceConfig] = None,
|
|
21
|
-
protocol: Optional[SmartProtocol] = None,
|
|
22
|
-
) -> None:
|
|
23
|
-
super().__init__(parent.host, config=parent.config, protocol=parent.protocol)
|
|
24
|
-
self._parent = parent
|
|
25
|
-
self._id = child_id
|
|
26
|
-
self.protocol = _ChildProtocolWrapper(child_id, parent.protocol)
|
|
27
|
-
|
|
28
|
-
async def update(self, update_children: bool = True):
|
|
29
|
-
"""We just set the info here accordingly."""
|
|
30
|
-
|
|
31
|
-
def _get_child_info() -> Dict:
|
|
32
|
-
"""Return the subdevice information for this device."""
|
|
33
|
-
for child in self._parent._last_update["child_info"]["child_device_list"]:
|
|
34
|
-
if child["device_id"] == self._id:
|
|
35
|
-
return child
|
|
36
|
-
|
|
37
|
-
raise SmartDeviceException(
|
|
38
|
-
f"Unable to find child device with id {self._id}"
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
self._last_update = self._sys_info = self._info = _get_child_info()
|
|
42
|
-
|
|
43
|
-
def __repr__(self):
|
|
44
|
-
return f"<ChildDevice {self.alias} of {self._parent}>"
|
kasa/tapo/tapobulb.py
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
"""Module for tapo-branded smart bulbs (L5**)."""
|
|
2
|
-
from typing import Any, Dict, List, Optional
|
|
3
|
-
|
|
4
|
-
from ..exceptions import SmartDeviceException
|
|
5
|
-
from ..smartbulb import HSV, ColorTempRange, SmartBulb, SmartBulbPreset
|
|
6
|
-
from .tapodevice import TapoDevice
|
|
7
|
-
|
|
8
|
-
AVAILABLE_EFFECTS = {
|
|
9
|
-
"L1": "Party",
|
|
10
|
-
"L2": "Relax",
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TapoBulb(TapoDevice, SmartBulb):
|
|
15
|
-
"""Representation of a TP-Link Tapo Bulb.
|
|
16
|
-
|
|
17
|
-
Documentation TBD. See :class:`~kasa.smartbulb.SmartBulb` for now.
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
@property
|
|
21
|
-
def is_color(self) -> bool:
|
|
22
|
-
"""Whether the bulb supports color changes."""
|
|
23
|
-
# TODO: this makes an assumption that only color bulbs report this
|
|
24
|
-
return "hue" in self._info
|
|
25
|
-
|
|
26
|
-
@property
|
|
27
|
-
def is_dimmable(self) -> bool:
|
|
28
|
-
"""Whether the bulb supports brightness changes."""
|
|
29
|
-
# TODO: this makes an assumption that only dimmables report this
|
|
30
|
-
return "brightness" in self._info
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def is_variable_color_temp(self) -> bool:
|
|
34
|
-
"""Whether the bulb supports color temperature changes."""
|
|
35
|
-
ct = self._info.get("color_temp_range")
|
|
36
|
-
# L900 reports [9000, 9000] even when it doesn't support changing the ct
|
|
37
|
-
return ct is not None and ct[0] != ct[1]
|
|
38
|
-
|
|
39
|
-
@property
|
|
40
|
-
def valid_temperature_range(self) -> ColorTempRange:
|
|
41
|
-
"""Return the device-specific white temperature range (in Kelvin).
|
|
42
|
-
|
|
43
|
-
:return: White temperature range in Kelvin (minimum, maximum)
|
|
44
|
-
"""
|
|
45
|
-
if not self.is_variable_color_temp:
|
|
46
|
-
raise SmartDeviceException("Color temperature not supported")
|
|
47
|
-
|
|
48
|
-
ct_range = self._info.get("color_temp_range", [0, 0])
|
|
49
|
-
return ColorTempRange(min=ct_range[0], max=ct_range[1])
|
|
50
|
-
|
|
51
|
-
@property
|
|
52
|
-
def has_effects(self) -> bool:
|
|
53
|
-
"""Return True if the device supports effects."""
|
|
54
|
-
return "dynamic_light_effect_enable" in self._info
|
|
55
|
-
|
|
56
|
-
@property
|
|
57
|
-
def effect(self) -> Dict:
|
|
58
|
-
"""Return effect state.
|
|
59
|
-
|
|
60
|
-
This follows the format used by SmartLightStrip.
|
|
61
|
-
|
|
62
|
-
Example:
|
|
63
|
-
{'brightness': 50,
|
|
64
|
-
'custom': 0,
|
|
65
|
-
'enable': 0,
|
|
66
|
-
'id': '',
|
|
67
|
-
'name': ''}
|
|
68
|
-
"""
|
|
69
|
-
# If no effect is active, dynamic_light_effect_id does not appear in info
|
|
70
|
-
current_effect = self._info.get("dynamic_light_effect_id", "")
|
|
71
|
-
data = {
|
|
72
|
-
"brightness": self.brightness,
|
|
73
|
-
"enable": current_effect != "",
|
|
74
|
-
"id": current_effect,
|
|
75
|
-
"name": AVAILABLE_EFFECTS.get(current_effect, ""),
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return data
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def effect_list(self) -> Optional[List[str]]:
|
|
82
|
-
"""Return built-in effects list.
|
|
83
|
-
|
|
84
|
-
Example:
|
|
85
|
-
['Party', 'Relax', ...]
|
|
86
|
-
"""
|
|
87
|
-
return list(AVAILABLE_EFFECTS.keys()) if self.has_effects else None
|
|
88
|
-
|
|
89
|
-
@property
|
|
90
|
-
def hsv(self) -> HSV:
|
|
91
|
-
"""Return the current HSV state of the bulb.
|
|
92
|
-
|
|
93
|
-
:return: hue, saturation and value (degrees, %, %)
|
|
94
|
-
"""
|
|
95
|
-
if not self.is_color:
|
|
96
|
-
raise SmartDeviceException("Bulb does not support color.")
|
|
97
|
-
|
|
98
|
-
h, s, v = (
|
|
99
|
-
self._info.get("hue", 0),
|
|
100
|
-
self._info.get("saturation", 0),
|
|
101
|
-
self._info.get("brightness", 0),
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
return HSV(hue=h, saturation=s, value=v)
|
|
105
|
-
|
|
106
|
-
@property
|
|
107
|
-
def color_temp(self) -> int:
|
|
108
|
-
"""Whether the bulb supports color temperature changes."""
|
|
109
|
-
if not self.is_variable_color_temp:
|
|
110
|
-
raise SmartDeviceException("Bulb does not support colortemp.")
|
|
111
|
-
|
|
112
|
-
return self._info.get("color_temp", -1)
|
|
113
|
-
|
|
114
|
-
@property
|
|
115
|
-
def brightness(self) -> int:
|
|
116
|
-
"""Return the current brightness in percentage."""
|
|
117
|
-
if not self.is_dimmable: # pragma: no cover
|
|
118
|
-
raise SmartDeviceException("Bulb is not dimmable.")
|
|
119
|
-
|
|
120
|
-
return self._info.get("brightness", -1)
|
|
121
|
-
|
|
122
|
-
async def set_hsv(
|
|
123
|
-
self,
|
|
124
|
-
hue: int,
|
|
125
|
-
saturation: int,
|
|
126
|
-
value: Optional[int] = None,
|
|
127
|
-
*,
|
|
128
|
-
transition: Optional[int] = None,
|
|
129
|
-
) -> Dict:
|
|
130
|
-
"""Set new HSV.
|
|
131
|
-
|
|
132
|
-
Note, transition is not supported and will be ignored.
|
|
133
|
-
|
|
134
|
-
:param int hue: hue in degrees
|
|
135
|
-
:param int saturation: saturation in percentage [0,100]
|
|
136
|
-
:param int value: value in percentage [0, 100]
|
|
137
|
-
:param int transition: transition in milliseconds.
|
|
138
|
-
"""
|
|
139
|
-
if not self.is_color:
|
|
140
|
-
raise SmartDeviceException("Bulb does not support color.")
|
|
141
|
-
|
|
142
|
-
if not isinstance(hue, int) or not (0 <= hue <= 360):
|
|
143
|
-
raise ValueError(f"Invalid hue value: {hue} (valid range: 0-360)")
|
|
144
|
-
|
|
145
|
-
if not isinstance(saturation, int) or not (0 <= saturation <= 100):
|
|
146
|
-
raise ValueError(
|
|
147
|
-
f"Invalid saturation value: {saturation} (valid range: 0-100%)"
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
if value is not None:
|
|
151
|
-
self._raise_for_invalid_brightness(value)
|
|
152
|
-
|
|
153
|
-
request_payload = {
|
|
154
|
-
"color_temp": 0, # If set, color_temp takes precedence over hue&sat
|
|
155
|
-
"hue": hue,
|
|
156
|
-
"saturation": saturation,
|
|
157
|
-
}
|
|
158
|
-
# The device errors on invalid brightness values.
|
|
159
|
-
if value is not None:
|
|
160
|
-
request_payload["brightness"] = value
|
|
161
|
-
|
|
162
|
-
return await self.protocol.query({"set_device_info": {**request_payload}})
|
|
163
|
-
|
|
164
|
-
async def set_color_temp(
|
|
165
|
-
self, temp: int, *, brightness=None, transition: Optional[int] = None
|
|
166
|
-
) -> Dict:
|
|
167
|
-
"""Set the color temperature of the device in kelvin.
|
|
168
|
-
|
|
169
|
-
Note, transition is not supported and will be ignored.
|
|
170
|
-
|
|
171
|
-
:param int temp: The new color temperature, in Kelvin
|
|
172
|
-
:param int transition: transition in milliseconds.
|
|
173
|
-
"""
|
|
174
|
-
# TODO: Note, trying to set brightness at the same time
|
|
175
|
-
# with color_temp causes error -1008
|
|
176
|
-
if not self.is_variable_color_temp:
|
|
177
|
-
raise SmartDeviceException("Bulb does not support colortemp.")
|
|
178
|
-
|
|
179
|
-
valid_temperature_range = self.valid_temperature_range
|
|
180
|
-
if temp < valid_temperature_range[0] or temp > valid_temperature_range[1]:
|
|
181
|
-
raise ValueError(
|
|
182
|
-
"Temperature should be between {} and {}, was {}".format(
|
|
183
|
-
*valid_temperature_range, temp
|
|
184
|
-
)
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
return await self.protocol.query({"set_device_info": {"color_temp": temp}})
|
|
188
|
-
|
|
189
|
-
async def set_brightness(
|
|
190
|
-
self, brightness: int, *, transition: Optional[int] = None
|
|
191
|
-
) -> Dict:
|
|
192
|
-
"""Set the brightness in percentage.
|
|
193
|
-
|
|
194
|
-
Note, transition is not supported and will be ignored.
|
|
195
|
-
|
|
196
|
-
:param int brightness: brightness in percent
|
|
197
|
-
:param int transition: transition in milliseconds.
|
|
198
|
-
"""
|
|
199
|
-
if not self.is_dimmable: # pragma: no cover
|
|
200
|
-
raise SmartDeviceException("Bulb is not dimmable.")
|
|
201
|
-
|
|
202
|
-
return await self.protocol.query(
|
|
203
|
-
{"set_device_info": {"brightness": brightness}}
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
# Default state information, should be made to settings
|
|
207
|
-
"""
|
|
208
|
-
"info": {
|
|
209
|
-
"default_states": {
|
|
210
|
-
"re_power_type": "always_on",
|
|
211
|
-
"type": "last_states",
|
|
212
|
-
"state": {
|
|
213
|
-
"brightness": 36,
|
|
214
|
-
"hue": 0,
|
|
215
|
-
"saturation": 0,
|
|
216
|
-
"color_temp": 2700,
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
"""
|
|
220
|
-
|
|
221
|
-
async def set_effect(
|
|
222
|
-
self,
|
|
223
|
-
effect: str,
|
|
224
|
-
*,
|
|
225
|
-
brightness: Optional[int] = None,
|
|
226
|
-
transition: Optional[int] = None,
|
|
227
|
-
) -> None:
|
|
228
|
-
"""Set an effect on the device."""
|
|
229
|
-
raise NotImplementedError()
|
|
230
|
-
# TODO: the code below does to activate the effect but gives no error
|
|
231
|
-
return await self.protocol.query(
|
|
232
|
-
{
|
|
233
|
-
"set_device_info": {
|
|
234
|
-
"dynamic_light_effect_enable": 1,
|
|
235
|
-
"dynamic_light_effect_id": effect,
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
@property # type: ignore
|
|
241
|
-
def state_information(self) -> Dict[str, Any]:
|
|
242
|
-
"""Return bulb-specific state information."""
|
|
243
|
-
info: Dict[str, Any] = {
|
|
244
|
-
# TODO: re-enable after we don't inherit from smartbulb
|
|
245
|
-
# **super().state_information
|
|
246
|
-
"Is dimmable": self.is_dimmable,
|
|
247
|
-
}
|
|
248
|
-
if self.is_dimmable:
|
|
249
|
-
info["Brightness"] = self.brightness
|
|
250
|
-
if self.is_variable_color_temp:
|
|
251
|
-
info["Color temperature"] = self.color_temp
|
|
252
|
-
info["Valid temperature range"] = self.valid_temperature_range
|
|
253
|
-
if self.is_color:
|
|
254
|
-
info["HSV"] = self.hsv
|
|
255
|
-
info["Presets"] = self.presets
|
|
256
|
-
|
|
257
|
-
return info
|
|
258
|
-
|
|
259
|
-
@property
|
|
260
|
-
def presets(self) -> List[SmartBulbPreset]:
|
|
261
|
-
"""Return a list of available bulb setting presets."""
|
|
262
|
-
return []
|