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/tapo/tapodevice.py
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
"""Module for a TAPO device."""
|
|
2
|
-
import base64
|
|
3
|
-
import logging
|
|
4
|
-
from datetime import datetime, timedelta, timezone
|
|
5
|
-
from typing import Any, Dict, List, Optional, Set, cast
|
|
6
|
-
|
|
7
|
-
from ..aestransport import AesTransport
|
|
8
|
-
from ..device_type import DeviceType
|
|
9
|
-
from ..deviceconfig import DeviceConfig
|
|
10
|
-
from ..emeterstatus import EmeterStatus
|
|
11
|
-
from ..exceptions import AuthenticationException, SmartDeviceException
|
|
12
|
-
from ..modules import Emeter
|
|
13
|
-
from ..smartdevice import SmartDevice, WifiNetwork
|
|
14
|
-
from ..smartprotocol import SmartProtocol
|
|
15
|
-
|
|
16
|
-
_LOGGER = logging.getLogger(__name__)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class TapoDevice(SmartDevice):
|
|
20
|
-
"""Base class to represent a TAPO device."""
|
|
21
|
-
|
|
22
|
-
def __init__(
|
|
23
|
-
self,
|
|
24
|
-
host: str,
|
|
25
|
-
*,
|
|
26
|
-
config: Optional[DeviceConfig] = None,
|
|
27
|
-
protocol: Optional[SmartProtocol] = None,
|
|
28
|
-
) -> None:
|
|
29
|
-
_protocol = protocol or SmartProtocol(
|
|
30
|
-
transport=AesTransport(config=config or DeviceConfig(host=host)),
|
|
31
|
-
)
|
|
32
|
-
super().__init__(host=host, config=config, protocol=_protocol)
|
|
33
|
-
self.protocol: SmartProtocol
|
|
34
|
-
self._components_raw: Optional[Dict[str, Any]] = None
|
|
35
|
-
self._components: Dict[str, int]
|
|
36
|
-
self._state_information: Dict[str, Any] = {}
|
|
37
|
-
|
|
38
|
-
async def _initialize_children(self):
|
|
39
|
-
children = self._last_update["child_info"]["child_device_list"]
|
|
40
|
-
# TODO: Use the type information to construct children,
|
|
41
|
-
# as hubs can also have them.
|
|
42
|
-
from .childdevice import ChildDevice
|
|
43
|
-
|
|
44
|
-
self.children = [
|
|
45
|
-
ChildDevice(parent=self, child_id=child["device_id"]) for child in children
|
|
46
|
-
]
|
|
47
|
-
self._device_type = DeviceType.Strip
|
|
48
|
-
|
|
49
|
-
async def update(self, update_children: bool = True):
|
|
50
|
-
"""Update the device."""
|
|
51
|
-
if self.credentials is None and self.credentials_hash is None:
|
|
52
|
-
raise AuthenticationException("Tapo plug requires authentication.")
|
|
53
|
-
|
|
54
|
-
if self._components_raw is None:
|
|
55
|
-
resp = await self.protocol.query("component_nego")
|
|
56
|
-
self._components_raw = resp["component_nego"]
|
|
57
|
-
self._components = {
|
|
58
|
-
comp["id"]: comp["ver_code"]
|
|
59
|
-
for comp in self._components_raw["component_list"]
|
|
60
|
-
}
|
|
61
|
-
await self._initialize_modules()
|
|
62
|
-
|
|
63
|
-
extra_reqs: Dict[str, Any] = {}
|
|
64
|
-
|
|
65
|
-
if "child_device" in self._components:
|
|
66
|
-
extra_reqs = {**extra_reqs, "get_child_device_list": None}
|
|
67
|
-
|
|
68
|
-
if "energy_monitoring" in self._components:
|
|
69
|
-
extra_reqs = {
|
|
70
|
-
**extra_reqs,
|
|
71
|
-
"get_energy_usage": None,
|
|
72
|
-
"get_current_power": None,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
req = {
|
|
76
|
-
"get_device_info": None,
|
|
77
|
-
"get_device_usage": None,
|
|
78
|
-
"get_device_time": None,
|
|
79
|
-
**extra_reqs,
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
resp = await self.protocol.query(req)
|
|
83
|
-
|
|
84
|
-
self._info = resp["get_device_info"]
|
|
85
|
-
self._usage = resp["get_device_usage"]
|
|
86
|
-
self._time = resp["get_device_time"]
|
|
87
|
-
# Emeter is not always available, but we set them still for now.
|
|
88
|
-
self._energy = resp.get("get_energy_usage", {})
|
|
89
|
-
self._emeter = resp.get("get_current_power", {})
|
|
90
|
-
|
|
91
|
-
self._last_update = self._data = {
|
|
92
|
-
"components": self._components_raw,
|
|
93
|
-
"info": self._info,
|
|
94
|
-
"usage": self._usage,
|
|
95
|
-
"time": self._time,
|
|
96
|
-
"energy": self._energy,
|
|
97
|
-
"emeter": self._emeter,
|
|
98
|
-
"child_info": resp.get("get_child_device_list", {}),
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if self._last_update["child_info"]:
|
|
102
|
-
if not self.children:
|
|
103
|
-
await self._initialize_children()
|
|
104
|
-
for child in self.children:
|
|
105
|
-
await child.update()
|
|
106
|
-
|
|
107
|
-
_LOGGER.debug("Got an update: %s", self._data)
|
|
108
|
-
|
|
109
|
-
async def _initialize_modules(self):
|
|
110
|
-
"""Initialize modules based on component negotiation response."""
|
|
111
|
-
if "energy_monitoring" in self._components:
|
|
112
|
-
self.emeter_type = "emeter"
|
|
113
|
-
self.modules["emeter"] = Emeter(self, self.emeter_type)
|
|
114
|
-
|
|
115
|
-
@property
|
|
116
|
-
def sys_info(self) -> Dict[str, Any]:
|
|
117
|
-
"""Returns the device info."""
|
|
118
|
-
return self._info # type: ignore
|
|
119
|
-
|
|
120
|
-
@property
|
|
121
|
-
def model(self) -> str:
|
|
122
|
-
"""Returns the device model."""
|
|
123
|
-
return str(self._info.get("model"))
|
|
124
|
-
|
|
125
|
-
@property
|
|
126
|
-
def alias(self) -> Optional[str]:
|
|
127
|
-
"""Returns the device alias or nickname."""
|
|
128
|
-
if self._info and (nickname := self._info.get("nickname")):
|
|
129
|
-
return base64.b64decode(nickname).decode()
|
|
130
|
-
else:
|
|
131
|
-
return None
|
|
132
|
-
|
|
133
|
-
@property
|
|
134
|
-
def time(self) -> datetime:
|
|
135
|
-
"""Return the time."""
|
|
136
|
-
td = timedelta(minutes=cast(float, self._time.get("time_diff")))
|
|
137
|
-
if self._time.get("region"):
|
|
138
|
-
tz = timezone(td, str(self._time.get("region")))
|
|
139
|
-
else:
|
|
140
|
-
# in case the device returns a blank region this will result in the
|
|
141
|
-
# tzname being a UTC offset
|
|
142
|
-
tz = timezone(td)
|
|
143
|
-
return datetime.fromtimestamp(
|
|
144
|
-
cast(float, self._time.get("timestamp")),
|
|
145
|
-
tz=tz,
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
@property
|
|
149
|
-
def timezone(self) -> Dict:
|
|
150
|
-
"""Return the timezone and time_difference."""
|
|
151
|
-
ti = self.time
|
|
152
|
-
return {"timezone": ti.tzname()}
|
|
153
|
-
|
|
154
|
-
@property
|
|
155
|
-
def hw_info(self) -> Dict:
|
|
156
|
-
"""Return hardware info for the device."""
|
|
157
|
-
return {
|
|
158
|
-
"sw_ver": self._info.get("fw_ver"),
|
|
159
|
-
"hw_ver": self._info.get("hw_ver"),
|
|
160
|
-
"mac": self._info.get("mac"),
|
|
161
|
-
"type": self._info.get("type"),
|
|
162
|
-
"hwId": self._info.get("device_id"),
|
|
163
|
-
"dev_name": self.alias,
|
|
164
|
-
"oemId": self._info.get("oem_id"),
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@property
|
|
168
|
-
def location(self) -> Dict:
|
|
169
|
-
"""Return the device location."""
|
|
170
|
-
loc = {
|
|
171
|
-
"latitude": cast(float, self._info.get("latitude", 0)) / 10_000,
|
|
172
|
-
"longitude": cast(float, self._info.get("longitude", 0)) / 10_000,
|
|
173
|
-
}
|
|
174
|
-
return loc
|
|
175
|
-
|
|
176
|
-
@property
|
|
177
|
-
def rssi(self) -> Optional[int]:
|
|
178
|
-
"""Return the rssi."""
|
|
179
|
-
rssi = self._info.get("rssi")
|
|
180
|
-
return int(rssi) if rssi else None
|
|
181
|
-
|
|
182
|
-
@property
|
|
183
|
-
def mac(self) -> str:
|
|
184
|
-
"""Return the mac formatted with colons."""
|
|
185
|
-
return str(self._info.get("mac")).replace("-", ":")
|
|
186
|
-
|
|
187
|
-
@property
|
|
188
|
-
def device_id(self) -> str:
|
|
189
|
-
"""Return the device id."""
|
|
190
|
-
return str(self._info.get("device_id"))
|
|
191
|
-
|
|
192
|
-
@property
|
|
193
|
-
def internal_state(self) -> Any:
|
|
194
|
-
"""Return all the internal state data."""
|
|
195
|
-
return self._data
|
|
196
|
-
|
|
197
|
-
async def _query_helper(
|
|
198
|
-
self, target: str, cmd: str, arg: Optional[Dict] = None, child_ids=None
|
|
199
|
-
) -> Any:
|
|
200
|
-
res = await self.protocol.query({cmd: arg})
|
|
201
|
-
|
|
202
|
-
return res
|
|
203
|
-
|
|
204
|
-
@property
|
|
205
|
-
def state_information(self) -> Dict[str, Any]:
|
|
206
|
-
"""Return the key state information."""
|
|
207
|
-
return {
|
|
208
|
-
"overheated": self._info.get("overheated"),
|
|
209
|
-
"signal_level": self._info.get("signal_level"),
|
|
210
|
-
"SSID": base64.b64decode(str(self._info.get("ssid"))).decode(),
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
@property
|
|
214
|
-
def features(self) -> Set[str]:
|
|
215
|
-
"""Return the list of supported features."""
|
|
216
|
-
# TODO:
|
|
217
|
-
return set()
|
|
218
|
-
|
|
219
|
-
@property
|
|
220
|
-
def has_emeter(self) -> bool:
|
|
221
|
-
"""Return if the device has emeter."""
|
|
222
|
-
return "energy_monitoring" in self._components
|
|
223
|
-
|
|
224
|
-
@property
|
|
225
|
-
def is_on(self) -> bool:
|
|
226
|
-
"""Return true if the device is on."""
|
|
227
|
-
return bool(self._info.get("device_on"))
|
|
228
|
-
|
|
229
|
-
async def turn_on(self, **kwargs):
|
|
230
|
-
"""Turn on the device."""
|
|
231
|
-
await self.protocol.query({"set_device_info": {"device_on": True}})
|
|
232
|
-
|
|
233
|
-
async def turn_off(self, **kwargs):
|
|
234
|
-
"""Turn off the device."""
|
|
235
|
-
await self.protocol.query({"set_device_info": {"device_on": False}})
|
|
236
|
-
|
|
237
|
-
def update_from_discover_info(self, info):
|
|
238
|
-
"""Update state from info from the discover call."""
|
|
239
|
-
self._discovery_info = info
|
|
240
|
-
self._info = info
|
|
241
|
-
|
|
242
|
-
async def get_emeter_realtime(self) -> EmeterStatus:
|
|
243
|
-
"""Retrieve current energy readings."""
|
|
244
|
-
self._verify_emeter()
|
|
245
|
-
resp = await self.protocol.query("get_energy_usage")
|
|
246
|
-
self._energy = resp["get_energy_usage"]
|
|
247
|
-
return self.emeter_realtime
|
|
248
|
-
|
|
249
|
-
def _convert_energy_data(self, data, scale) -> Optional[float]:
|
|
250
|
-
"""Return adjusted emeter information."""
|
|
251
|
-
return data if not data else data * scale
|
|
252
|
-
|
|
253
|
-
@property
|
|
254
|
-
def emeter_realtime(self) -> EmeterStatus:
|
|
255
|
-
"""Get the emeter status."""
|
|
256
|
-
return EmeterStatus(
|
|
257
|
-
{
|
|
258
|
-
"power_mw": self._energy.get("current_power"),
|
|
259
|
-
"total": self._convert_energy_data(
|
|
260
|
-
self._energy.get("today_energy"), 1 / 1000
|
|
261
|
-
),
|
|
262
|
-
}
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
@property
|
|
266
|
-
def emeter_this_month(self) -> Optional[float]:
|
|
267
|
-
"""Get the emeter value for this month."""
|
|
268
|
-
return self._convert_energy_data(self._energy.get("month_energy"), 1 / 1000)
|
|
269
|
-
|
|
270
|
-
@property
|
|
271
|
-
def emeter_today(self) -> Optional[float]:
|
|
272
|
-
"""Get the emeter value for today."""
|
|
273
|
-
return self._convert_energy_data(self._energy.get("today_energy"), 1 / 1000)
|
|
274
|
-
|
|
275
|
-
async def wifi_scan(self) -> List[WifiNetwork]:
|
|
276
|
-
"""Scan for available wifi networks."""
|
|
277
|
-
|
|
278
|
-
def _net_for_scan_info(res):
|
|
279
|
-
return WifiNetwork(
|
|
280
|
-
ssid=base64.b64decode(res["ssid"]).decode(),
|
|
281
|
-
cipher_type=res["cipher_type"],
|
|
282
|
-
key_type=res["key_type"],
|
|
283
|
-
channel=res["channel"],
|
|
284
|
-
signal_level=res["signal_level"],
|
|
285
|
-
bssid=res["bssid"],
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
async def _query_networks(networks=None, start_index=0):
|
|
289
|
-
_LOGGER.debug("Querying networks using start_index=%s", start_index)
|
|
290
|
-
if networks is None:
|
|
291
|
-
networks = []
|
|
292
|
-
|
|
293
|
-
resp = await self.protocol.query(
|
|
294
|
-
{"get_wireless_scan_info": {"start_index": start_index}}
|
|
295
|
-
)
|
|
296
|
-
network_list = [
|
|
297
|
-
_net_for_scan_info(net)
|
|
298
|
-
for net in resp["get_wireless_scan_info"]["ap_list"]
|
|
299
|
-
]
|
|
300
|
-
networks.extend(network_list)
|
|
301
|
-
|
|
302
|
-
if resp["get_wireless_scan_info"].get("sum", 0) > start_index + 10:
|
|
303
|
-
return await _query_networks(networks, start_index=start_index + 10)
|
|
304
|
-
|
|
305
|
-
return networks
|
|
306
|
-
|
|
307
|
-
return await _query_networks()
|
|
308
|
-
|
|
309
|
-
async def wifi_join(self, ssid: str, password: str, keytype: str = "wpa2_psk"):
|
|
310
|
-
"""Join the given wifi network.
|
|
311
|
-
|
|
312
|
-
This method returns nothing as the device tries to activate the new
|
|
313
|
-
settings immediately instead of responding to the request.
|
|
314
|
-
|
|
315
|
-
If joining the network fails, the device will return to the previous state
|
|
316
|
-
after some delay.
|
|
317
|
-
"""
|
|
318
|
-
if not self.credentials:
|
|
319
|
-
raise AuthenticationException("Device requires authentication.")
|
|
320
|
-
|
|
321
|
-
payload = {
|
|
322
|
-
"account": {
|
|
323
|
-
"username": base64.b64encode(
|
|
324
|
-
self.credentials.username.encode()
|
|
325
|
-
).decode(),
|
|
326
|
-
"password": base64.b64encode(
|
|
327
|
-
self.credentials.password.encode()
|
|
328
|
-
).decode(),
|
|
329
|
-
},
|
|
330
|
-
"wireless": {
|
|
331
|
-
"key_type": keytype,
|
|
332
|
-
"password": base64.b64encode(password.encode()).decode(),
|
|
333
|
-
"ssid": base64.b64encode(ssid.encode()).decode(),
|
|
334
|
-
},
|
|
335
|
-
"time": self.internal_state["time"],
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
# The device does not respond to the request but changes the settings
|
|
339
|
-
# immediately which causes us to timeout.
|
|
340
|
-
# Thus, We limit retries and suppress the raised exception as useless.
|
|
341
|
-
try:
|
|
342
|
-
return await self.protocol.query({"set_qs_info": payload}, retry_count=0)
|
|
343
|
-
except SmartDeviceException as ex:
|
|
344
|
-
if ex.error_code: # Re-raise on device-reported errors
|
|
345
|
-
raise
|
|
346
|
-
|
|
347
|
-
_LOGGER.debug("Received an expected for wifi join, but this is expected")
|
|
348
|
-
|
|
349
|
-
async def update_credentials(self, username: str, password: str):
|
|
350
|
-
"""Update device credentials.
|
|
351
|
-
|
|
352
|
-
This will replace the existing authentication credentials on the device.
|
|
353
|
-
"""
|
|
354
|
-
t = self.internal_state["time"]
|
|
355
|
-
payload = {
|
|
356
|
-
"account": {
|
|
357
|
-
"username": base64.b64encode(username.encode()).decode(),
|
|
358
|
-
"password": base64.b64encode(password.encode()).decode(),
|
|
359
|
-
},
|
|
360
|
-
"time": t,
|
|
361
|
-
}
|
|
362
|
-
return await self.protocol.query({"set_qs_info": payload})
|
|
363
|
-
|
|
364
|
-
async def set_alias(self, alias: str):
|
|
365
|
-
"""Set the device name (alias)."""
|
|
366
|
-
return await self.protocol.query(
|
|
367
|
-
{"set_device_info": {"nickname": base64.b64encode(alias.encode()).decode()}}
|
|
368
|
-
)
|
|
369
|
-
|
|
370
|
-
async def reboot(self, delay: int = 1) -> None:
|
|
371
|
-
"""Reboot the device.
|
|
372
|
-
|
|
373
|
-
Note that giving a delay of zero causes this to block,
|
|
374
|
-
as the device reboots immediately without responding to the call.
|
|
375
|
-
"""
|
|
376
|
-
await self.protocol.query({"device_reboot": {"delay": delay}})
|
|
377
|
-
|
|
378
|
-
async def factory_reset(self) -> None:
|
|
379
|
-
"""Reset device back to factory settings.
|
|
380
|
-
|
|
381
|
-
Note, this does not downgrade the firmware.
|
|
382
|
-
"""
|
|
383
|
-
await self.protocol.query("device_reset")
|
kasa/tapo/tapoplug.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"""Module for a TAPO Plug."""
|
|
2
|
-
import logging
|
|
3
|
-
from datetime import datetime, timedelta
|
|
4
|
-
from typing import Any, Dict, Optional, cast
|
|
5
|
-
|
|
6
|
-
from ..deviceconfig import DeviceConfig
|
|
7
|
-
from ..smartdevice import DeviceType
|
|
8
|
-
from ..smartprotocol import SmartProtocol
|
|
9
|
-
from .tapodevice import TapoDevice
|
|
10
|
-
|
|
11
|
-
_LOGGER = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TapoPlug(TapoDevice):
|
|
15
|
-
"""Class to represent a TAPO Plug."""
|
|
16
|
-
|
|
17
|
-
def __init__(
|
|
18
|
-
self,
|
|
19
|
-
host: str,
|
|
20
|
-
*,
|
|
21
|
-
config: Optional[DeviceConfig] = None,
|
|
22
|
-
protocol: Optional[SmartProtocol] = None,
|
|
23
|
-
) -> None:
|
|
24
|
-
super().__init__(host=host, config=config, protocol=protocol)
|
|
25
|
-
self._device_type = DeviceType.Plug
|
|
26
|
-
|
|
27
|
-
@property
|
|
28
|
-
def state_information(self) -> Dict[str, Any]:
|
|
29
|
-
"""Return the key state information."""
|
|
30
|
-
return {
|
|
31
|
-
**super().state_information,
|
|
32
|
-
**{
|
|
33
|
-
"On since": self.on_since,
|
|
34
|
-
"auto_off_status": self._info.get("auto_off_status"),
|
|
35
|
-
"auto_off_remain_time": self._info.get("auto_off_remain_time"),
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@property
|
|
40
|
-
def on_since(self) -> Optional[datetime]:
|
|
41
|
-
"""Return the time that the device was turned on or None if turned off."""
|
|
42
|
-
if not self._info.get("device_on"):
|
|
43
|
-
return None
|
|
44
|
-
on_time = cast(float, self._info.get("on_time"))
|
|
45
|
-
return datetime.now().replace(microsecond=0) - timedelta(seconds=on_time)
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"emeter": {
|
|
3
|
-
"get_realtime": {
|
|
4
|
-
"err_code": -1,
|
|
5
|
-
"err_msg": "module not support"
|
|
6
|
-
}
|
|
7
|
-
},
|
|
8
|
-
"smartlife.iot.common.emeter": {
|
|
9
|
-
"err_code": -1,
|
|
10
|
-
"err_msg": "module not support"
|
|
11
|
-
},
|
|
12
|
-
"smartlife.iot.dimmer": {
|
|
13
|
-
"err_code": -1,
|
|
14
|
-
"err_msg": "module not support"
|
|
15
|
-
},
|
|
16
|
-
"smartlife.iot.smartbulb.lightingservice": {
|
|
17
|
-
"err_code": -1,
|
|
18
|
-
"err_msg": "module not support"
|
|
19
|
-
},
|
|
20
|
-
"system": {
|
|
21
|
-
"get_sysinfo": {
|
|
22
|
-
"active_mode": "schedule",
|
|
23
|
-
"alias": "Mock hs105",
|
|
24
|
-
"dev_name": "Smart Wi-Fi Plug Mini",
|
|
25
|
-
"deviceId": "F0723FAFC1FA27FC755B9F228A2297D921FEBCD1",
|
|
26
|
-
"err_code": 0,
|
|
27
|
-
"feature": "TIM",
|
|
28
|
-
"hwId": "51E17031929D5FEF9147091AD67B954A",
|
|
29
|
-
"hw_ver": "1.0",
|
|
30
|
-
"icon_hash": "",
|
|
31
|
-
"INVALIDlatitude": 79.7779,
|
|
32
|
-
"latitude_i": 79.7779,
|
|
33
|
-
"led_off": 0,
|
|
34
|
-
"INVALIDlongitude": 90.8844,
|
|
35
|
-
"longitude_i": 90.8844,
|
|
36
|
-
"mac": "50:c7:bf:ac:c0:6a",
|
|
37
|
-
"model": "HS105(US)",
|
|
38
|
-
"oemId": "990ADB7AEDE871C41D1B7613D1FE7A76",
|
|
39
|
-
"on_time": 0,
|
|
40
|
-
"relay_state": 0,
|
|
41
|
-
"rssi": -65,
|
|
42
|
-
"sw_ver": "1.2.9 Build 170808 Rel.145916",
|
|
43
|
-
"type": "IOT.SMARTPLUGSWITCH",
|
|
44
|
-
"updating": 0
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"emeter": {
|
|
3
|
-
"get_realtime": {
|
|
4
|
-
"current_ma": 125,
|
|
5
|
-
"err_code": 0,
|
|
6
|
-
"power_mw": 3140,
|
|
7
|
-
"total_wh": 51493,
|
|
8
|
-
"voltage_mv": 122049
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"smartlife.iot.common.emeter": {
|
|
12
|
-
"err_code": -1,
|
|
13
|
-
"err_msg": "module not support"
|
|
14
|
-
},
|
|
15
|
-
"smartlife.iot.dimmer": {
|
|
16
|
-
"err_code": -1,
|
|
17
|
-
"err_msg": "module not support"
|
|
18
|
-
},
|
|
19
|
-
"smartlife.iot.smartbulb.lightingservice": {
|
|
20
|
-
"err_code": -1,
|
|
21
|
-
"err_msg": "module not support"
|
|
22
|
-
},
|
|
23
|
-
"system": {
|
|
24
|
-
"get_sysinfo": {
|
|
25
|
-
"active_mode": "schedule",
|
|
26
|
-
"alias": "Mock hs110v2",
|
|
27
|
-
"dev_name": "Smart Wi-Fi Plug With Energy Monitoring",
|
|
28
|
-
"deviceId": "A466BCDB5026318939145B7CC7EF18D8C1D3A954",
|
|
29
|
-
"err_code": 0,
|
|
30
|
-
"feature": "TIM:ENE",
|
|
31
|
-
"hwId": "1F7FABB46373CA51E3AFDE5930ECBB36",
|
|
32
|
-
"hw_ver": "2.0",
|
|
33
|
-
"icon_hash": "",
|
|
34
|
-
"INVALIDlatitude": -60.4599,
|
|
35
|
-
"latitude_i": -60.4599,
|
|
36
|
-
"led_off": 0,
|
|
37
|
-
"INVALIDlongitude": 76.1249,
|
|
38
|
-
"longitude_i": 76.1249,
|
|
39
|
-
"mac": "50:c7:bf:b9:40:08",
|
|
40
|
-
"model": "HS110(EU)",
|
|
41
|
-
"oemId": "BB668B949FA4559655F1187DD56622BD",
|
|
42
|
-
"on_time": 0,
|
|
43
|
-
"relay_state": 0,
|
|
44
|
-
"rssi": -65,
|
|
45
|
-
"sw_ver": "1.5.2 Build 180130 Rel.085820",
|
|
46
|
-
"type": "IOT.SMARTPLUGSWITCH",
|
|
47
|
-
"updating": 0
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"emeter": {
|
|
3
|
-
"get_realtime": {
|
|
4
|
-
"current": 0.1256,
|
|
5
|
-
"err_code": 0,
|
|
6
|
-
"power": 3.14,
|
|
7
|
-
"total": 51.493,
|
|
8
|
-
"voltage": 122.049119
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"smartlife.iot.common.emeter": {
|
|
12
|
-
"err_code": -1,
|
|
13
|
-
"err_msg": "module not support"
|
|
14
|
-
},
|
|
15
|
-
"smartlife.iot.dimmer": {
|
|
16
|
-
"err_code": -1,
|
|
17
|
-
"err_msg": "module not support"
|
|
18
|
-
},
|
|
19
|
-
"smartlife.iot.smartbulb.lightingservice": {
|
|
20
|
-
"err_code": -1,
|
|
21
|
-
"err_msg": "module not support"
|
|
22
|
-
},
|
|
23
|
-
"system": {
|
|
24
|
-
"get_sysinfo": {
|
|
25
|
-
"active_mode": "schedule",
|
|
26
|
-
"alias": "Mock hs110",
|
|
27
|
-
"dev_name": "Wi-Fi Smart Plug With Energy Monitoring",
|
|
28
|
-
"deviceId": "11A5FD4A0FA1FCE5468F55D23CE77D1753A93E11",
|
|
29
|
-
"err_code": 0,
|
|
30
|
-
"feature": "TIM:ENE",
|
|
31
|
-
"hwId": "6C56A17315351DD0EDE0BDB1D9EBBD66",
|
|
32
|
-
"hw_ver": "1.0",
|
|
33
|
-
"icon_hash": "",
|
|
34
|
-
"latitude": 82.2866,
|
|
35
|
-
"latitude_i": 82.2866,
|
|
36
|
-
"led_off": 0,
|
|
37
|
-
"longitude": 10.0036,
|
|
38
|
-
"longitude_i": 10.0036,
|
|
39
|
-
"mac": "50:c7:bf:66:29:29",
|
|
40
|
-
"model": "HS110(US)",
|
|
41
|
-
"oemId": "F7DFC14D43DA806B55DB66D21F212B60",
|
|
42
|
-
"on_time": 0,
|
|
43
|
-
"relay_state": 0,
|
|
44
|
-
"rssi": -65,
|
|
45
|
-
"sw_ver": "1.0.8 Build 151113 Rel.24658",
|
|
46
|
-
"type": "IOT.SMARTPLUGSWITCH",
|
|
47
|
-
"updating": 0
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"emeter": {
|
|
3
|
-
"get_realtime": {
|
|
4
|
-
"err_code": -1,
|
|
5
|
-
"err_msg": "module not support"
|
|
6
|
-
}
|
|
7
|
-
},
|
|
8
|
-
"smartlife.iot.common.emeter": {
|
|
9
|
-
"err_code": -1,
|
|
10
|
-
"err_msg": "module not support"
|
|
11
|
-
},
|
|
12
|
-
"smartlife.iot.dimmer": {
|
|
13
|
-
"err_code": -1,
|
|
14
|
-
"err_msg": "module not support"
|
|
15
|
-
},
|
|
16
|
-
"smartlife.iot.smartbulb.lightingservice": {
|
|
17
|
-
"err_code": -1,
|
|
18
|
-
"err_msg": "module not support"
|
|
19
|
-
},
|
|
20
|
-
"system": {
|
|
21
|
-
"get_sysinfo": {
|
|
22
|
-
"active_mode": "schedule",
|
|
23
|
-
"alias": "Mock hs200",
|
|
24
|
-
"dev_name": "Wi-Fi Smart Light Switch",
|
|
25
|
-
"deviceId": "EC565185337CF59A4C9A73442AAD5F11C6E91716",
|
|
26
|
-
"err_code": 0,
|
|
27
|
-
"feature": "TIM",
|
|
28
|
-
"hwId": "4B5DB5E42F13728107D075EF5C3ECFA1",
|
|
29
|
-
"hw_ver": "1.0",
|
|
30
|
-
"icon_hash": "",
|
|
31
|
-
"latitude": 58.7882,
|
|
32
|
-
"latitude_i": 58.7882,
|
|
33
|
-
"led_off": 0,
|
|
34
|
-
"longitude": 107.7225,
|
|
35
|
-
"longitude_i": 107.7225,
|
|
36
|
-
"mac": "50:c7:bf:95:4b:45",
|
|
37
|
-
"model": "HS200(US)",
|
|
38
|
-
"oemId": "D2A5D690B25980755216FD684AF8CD88",
|
|
39
|
-
"on_time": 0,
|
|
40
|
-
"relay_state": 0,
|
|
41
|
-
"rssi": -65,
|
|
42
|
-
"sw_ver": "1.1.0 Build 160521 Rel.085826",
|
|
43
|
-
"type": "IOT.SMARTPLUGSWITCH",
|
|
44
|
-
"updating": 0
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|