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/iot/modules/emeter.py
CHANGED
|
@@ -4,130 +4,71 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
|
|
7
|
-
from ... import Device
|
|
8
7
|
from ...emeterstatus import EmeterStatus
|
|
9
|
-
from ...
|
|
8
|
+
from ...interfaces.energy import Energy as EnergyInterface
|
|
10
9
|
from .usage import Usage
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
class Emeter(Usage):
|
|
12
|
+
class Emeter(Usage, EnergyInterface):
|
|
14
13
|
"""Emeter module."""
|
|
15
14
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
unit="W",
|
|
25
|
-
id="current_power_w", # for homeassistant backwards compat
|
|
26
|
-
precision_hint=1,
|
|
27
|
-
category=Feature.Category.Primary,
|
|
15
|
+
def _post_update_hook(self) -> None:
|
|
16
|
+
self._supported = EnergyInterface.ModuleFeature.PERIODIC_STATS
|
|
17
|
+
if (
|
|
18
|
+
"voltage_mv" in self.data["get_realtime"]
|
|
19
|
+
or "voltage" in self.data["get_realtime"]
|
|
20
|
+
):
|
|
21
|
+
self._supported = (
|
|
22
|
+
self._supported | EnergyInterface.ModuleFeature.VOLTAGE_CURRENT
|
|
28
23
|
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
container=self,
|
|
36
|
-
unit="kWh",
|
|
37
|
-
id="today_energy_kwh", # for homeassistant backwards compat
|
|
38
|
-
precision_hint=3,
|
|
39
|
-
category=Feature.Category.Info,
|
|
24
|
+
if (
|
|
25
|
+
"total_wh" in self.data["get_realtime"]
|
|
26
|
+
or "total" in self.data["get_realtime"]
|
|
27
|
+
):
|
|
28
|
+
self._supported = (
|
|
29
|
+
self._supported | EnergyInterface.ModuleFeature.CONSUMPTION_TOTAL
|
|
40
30
|
)
|
|
41
|
-
)
|
|
42
|
-
self._add_feature(
|
|
43
|
-
Feature(
|
|
44
|
-
device,
|
|
45
|
-
id="consumption_this_month",
|
|
46
|
-
name="This month's consumption",
|
|
47
|
-
attribute_getter="emeter_this_month",
|
|
48
|
-
container=self,
|
|
49
|
-
unit="kWh",
|
|
50
|
-
precision_hint=3,
|
|
51
|
-
category=Feature.Category.Info,
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
self._add_feature(
|
|
55
|
-
Feature(
|
|
56
|
-
device,
|
|
57
|
-
name="Total consumption since reboot",
|
|
58
|
-
attribute_getter="emeter_total",
|
|
59
|
-
container=self,
|
|
60
|
-
unit="kWh",
|
|
61
|
-
id="total_energy_kwh", # for homeassistant backwards compat
|
|
62
|
-
precision_hint=3,
|
|
63
|
-
category=Feature.Category.Info,
|
|
64
|
-
)
|
|
65
|
-
)
|
|
66
|
-
self._add_feature(
|
|
67
|
-
Feature(
|
|
68
|
-
device,
|
|
69
|
-
name="Voltage",
|
|
70
|
-
attribute_getter="voltage",
|
|
71
|
-
container=self,
|
|
72
|
-
unit="V",
|
|
73
|
-
id="voltage", # for homeassistant backwards compat
|
|
74
|
-
precision_hint=1,
|
|
75
|
-
category=Feature.Category.Primary,
|
|
76
|
-
)
|
|
77
|
-
)
|
|
78
|
-
self._add_feature(
|
|
79
|
-
Feature(
|
|
80
|
-
device,
|
|
81
|
-
name="Current",
|
|
82
|
-
attribute_getter="current",
|
|
83
|
-
container=self,
|
|
84
|
-
unit="A",
|
|
85
|
-
id="current_a", # for homeassistant backwards compat
|
|
86
|
-
precision_hint=2,
|
|
87
|
-
category=Feature.Category.Primary,
|
|
88
|
-
)
|
|
89
|
-
)
|
|
90
31
|
|
|
91
32
|
@property # type: ignore
|
|
92
|
-
def
|
|
33
|
+
def status(self) -> EmeterStatus:
|
|
93
34
|
"""Return current energy readings."""
|
|
94
35
|
return EmeterStatus(self.data["get_realtime"])
|
|
95
36
|
|
|
96
37
|
@property
|
|
97
|
-
def
|
|
38
|
+
def consumption_today(self) -> float | None:
|
|
98
39
|
"""Return today's energy consumption in kWh."""
|
|
99
40
|
raw_data = self.daily_data
|
|
100
41
|
today = datetime.now().day
|
|
101
42
|
data = self._convert_stat_data(raw_data, entry_key="day", key=today)
|
|
102
|
-
return data.get(today)
|
|
43
|
+
return data.get(today, 0.0)
|
|
103
44
|
|
|
104
45
|
@property
|
|
105
|
-
def
|
|
46
|
+
def consumption_this_month(self) -> float | None:
|
|
106
47
|
"""Return this month's energy consumption in kWh."""
|
|
107
48
|
raw_data = self.monthly_data
|
|
108
49
|
current_month = datetime.now().month
|
|
109
50
|
data = self._convert_stat_data(raw_data, entry_key="month", key=current_month)
|
|
110
|
-
return data.get(current_month)
|
|
51
|
+
return data.get(current_month, 0.0)
|
|
111
52
|
|
|
112
53
|
@property
|
|
113
54
|
def current_consumption(self) -> float | None:
|
|
114
55
|
"""Get the current power consumption in Watt."""
|
|
115
|
-
return self.
|
|
56
|
+
return self.status.power
|
|
116
57
|
|
|
117
58
|
@property
|
|
118
|
-
def
|
|
59
|
+
def consumption_total(self) -> float | None:
|
|
119
60
|
"""Return total consumption since last reboot in kWh."""
|
|
120
|
-
return self.
|
|
61
|
+
return self.status.total
|
|
121
62
|
|
|
122
63
|
@property
|
|
123
64
|
def current(self) -> float | None:
|
|
124
65
|
"""Return the current in A."""
|
|
125
|
-
return self.
|
|
66
|
+
return self.status.current
|
|
126
67
|
|
|
127
68
|
@property
|
|
128
69
|
def voltage(self) -> float | None:
|
|
129
70
|
"""Get the current voltage in V."""
|
|
130
|
-
return self.
|
|
71
|
+
return self.status.voltage
|
|
131
72
|
|
|
132
73
|
async def erase_stats(self):
|
|
133
74
|
"""Erase all stats.
|
|
@@ -136,11 +77,11 @@ class Emeter(Usage):
|
|
|
136
77
|
"""
|
|
137
78
|
return await self.call("erase_emeter_stat")
|
|
138
79
|
|
|
139
|
-
async def
|
|
80
|
+
async def get_status(self) -> EmeterStatus:
|
|
140
81
|
"""Return real-time statistics."""
|
|
141
|
-
return await self.call("get_realtime")
|
|
82
|
+
return EmeterStatus(await self.call("get_realtime"))
|
|
142
83
|
|
|
143
|
-
async def
|
|
84
|
+
async def get_daily_stats(self, *, year=None, month=None, kwh=True) -> dict:
|
|
144
85
|
"""Return daily stats for the given year & month.
|
|
145
86
|
|
|
146
87
|
The return value is a dictionary of {day: energy, ...}.
|
|
@@ -149,7 +90,7 @@ class Emeter(Usage):
|
|
|
149
90
|
data = self._convert_stat_data(data["day_list"], entry_key="day", kwh=kwh)
|
|
150
91
|
return data
|
|
151
92
|
|
|
152
|
-
async def
|
|
93
|
+
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
|
|
153
94
|
"""Return monthly stats for the given year.
|
|
154
95
|
|
|
155
96
|
The return value is a dictionary of {month: energy, ...}.
|
kasa/iot/modules/led.py
CHANGED
|
@@ -30,3 +30,8 @@ class Led(IotModule, LedInterface):
|
|
|
30
30
|
async def set_led(self, state: bool):
|
|
31
31
|
"""Set the state of the led (night mode)."""
|
|
32
32
|
return await self.call("set_led_off", {"off": int(not state)})
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def is_supported(self) -> bool:
|
|
36
|
+
"""Return whether the module is supported by the device."""
|
|
37
|
+
return "led_off" in self.data
|
kasa/iot/modules/lightpreset.py
CHANGED
kasa/module.py
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Interact with modules.
|
|
2
|
+
|
|
3
|
+
Modules are implemented by devices to encapsulate sets of functionality like
|
|
4
|
+
Light, AutoOff, Firmware etc.
|
|
5
|
+
|
|
6
|
+
>>> from kasa import Discover, Module
|
|
7
|
+
>>>
|
|
8
|
+
>>> dev = await Discover.discover_single(
|
|
9
|
+
>>> "127.0.0.3",
|
|
10
|
+
>>> username="user@example.com",
|
|
11
|
+
>>> password="great_password"
|
|
12
|
+
>>> )
|
|
13
|
+
>>> await dev.update()
|
|
14
|
+
>>> print(dev.alias)
|
|
15
|
+
Living Room Bulb
|
|
16
|
+
|
|
17
|
+
To see whether a device supports functionality check for the existence of the module:
|
|
18
|
+
|
|
19
|
+
>>> if light := dev.modules.get("Light"):
|
|
20
|
+
>>> print(light.hsv)
|
|
21
|
+
HSV(hue=0, saturation=100, value=100)
|
|
22
|
+
|
|
23
|
+
If you know or expect the module to exist you can access by index:
|
|
24
|
+
|
|
25
|
+
>>> light_preset = dev.modules["LightPreset"]
|
|
26
|
+
>>> print(light_preset.preset_list)
|
|
27
|
+
['Not set', 'Light preset 1', 'Light preset 2', 'Light preset 3',\
|
|
28
|
+
'Light preset 4', 'Light preset 5', 'Light preset 6', 'Light preset 7']
|
|
29
|
+
|
|
30
|
+
Modules support typing via the Module names in Module:
|
|
31
|
+
|
|
32
|
+
>>> from typing_extensions import reveal_type, TYPE_CHECKING
|
|
33
|
+
>>> light_effect = dev.modules.get("LightEffect")
|
|
34
|
+
>>> light_effect_typed = dev.modules.get(Module.LightEffect)
|
|
35
|
+
>>> if TYPE_CHECKING:
|
|
36
|
+
>>> reveal_type(light_effect) # Static checker will reveal: str
|
|
37
|
+
>>> reveal_type(light_effect_typed) # Static checker will reveal: LightEffect
|
|
38
|
+
|
|
39
|
+
"""
|
|
2
40
|
|
|
3
41
|
from __future__ import annotations
|
|
4
42
|
|
|
@@ -33,6 +71,8 @@ class Module(ABC):
|
|
|
33
71
|
"""
|
|
34
72
|
|
|
35
73
|
# Common Modules
|
|
74
|
+
Energy: Final[ModuleName[interfaces.Energy]] = ModuleName("Energy")
|
|
75
|
+
Fan: Final[ModuleName[interfaces.Fan]] = ModuleName("Fan")
|
|
36
76
|
LightEffect: Final[ModuleName[interfaces.LightEffect]] = ModuleName("LightEffect")
|
|
37
77
|
Led: Final[ModuleName[interfaces.Led]] = ModuleName("Led")
|
|
38
78
|
Light: Final[ModuleName[interfaces.Light]] = ModuleName("Light")
|
|
@@ -42,7 +82,6 @@ class Module(ABC):
|
|
|
42
82
|
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = ModuleName("ambient")
|
|
43
83
|
IotAntitheft: Final[ModuleName[iot.Antitheft]] = ModuleName("anti_theft")
|
|
44
84
|
IotCountdown: Final[ModuleName[iot.Countdown]] = ModuleName("countdown")
|
|
45
|
-
IotEmeter: Final[ModuleName[iot.Emeter]] = ModuleName("emeter")
|
|
46
85
|
IotMotion: Final[ModuleName[iot.Motion]] = ModuleName("motion")
|
|
47
86
|
IotSchedule: Final[ModuleName[iot.Schedule]] = ModuleName("schedule")
|
|
48
87
|
IotUsage: Final[ModuleName[iot.Usage]] = ModuleName("usage")
|
|
@@ -62,8 +101,6 @@ class Module(ABC):
|
|
|
62
101
|
)
|
|
63
102
|
ContactSensor: Final[ModuleName[smart.ContactSensor]] = ModuleName("ContactSensor")
|
|
64
103
|
DeviceModule: Final[ModuleName[smart.DeviceModule]] = ModuleName("DeviceModule")
|
|
65
|
-
Energy: Final[ModuleName[smart.Energy]] = ModuleName("Energy")
|
|
66
|
-
Fan: Final[ModuleName[smart.Fan]] = ModuleName("Fan")
|
|
67
104
|
Firmware: Final[ModuleName[smart.Firmware]] = ModuleName("Firmware")
|
|
68
105
|
FrostProtection: Final[ModuleName[smart.FrostProtection]] = ModuleName(
|
|
69
106
|
"FrostProtection"
|
kasa/smart/modules/alarm.py
CHANGED
kasa/smart/modules/autooff.py
CHANGED
|
@@ -40,11 +40,12 @@ class AutoOff(SmartModule):
|
|
|
40
40
|
Feature(
|
|
41
41
|
self._device,
|
|
42
42
|
id="auto_off_minutes",
|
|
43
|
-
name="Auto off
|
|
43
|
+
name="Auto off in",
|
|
44
44
|
container=self,
|
|
45
45
|
attribute_getter="delay",
|
|
46
46
|
attribute_setter="set_delay",
|
|
47
47
|
type=Feature.Type.Number,
|
|
48
|
+
unit="min", # ha-friendly unit, see UnitOfTime.MINUTES
|
|
48
49
|
)
|
|
49
50
|
)
|
|
50
51
|
self._add_feature(
|
|
@@ -55,6 +56,7 @@ class AutoOff(SmartModule):
|
|
|
55
56
|
container=self,
|
|
56
57
|
attribute_getter="auto_off_at",
|
|
57
58
|
category=Feature.Category.Info,
|
|
59
|
+
type=Feature.Type.Sensor,
|
|
58
60
|
)
|
|
59
61
|
)
|
|
60
62
|
|
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Interact with child devices.
|
|
2
|
+
|
|
3
|
+
>>> from kasa import Discover
|
|
4
|
+
>>>
|
|
5
|
+
>>> dev = await Discover.discover_single(
|
|
6
|
+
>>> "127.0.0.1",
|
|
7
|
+
>>> username="user@example.com",
|
|
8
|
+
>>> password="great_password"
|
|
9
|
+
>>> )
|
|
10
|
+
>>> await dev.update()
|
|
11
|
+
>>> print(dev.alias)
|
|
12
|
+
Bedroom Power Strip
|
|
13
|
+
|
|
14
|
+
All methods act on the whole strip:
|
|
15
|
+
|
|
16
|
+
>>> for plug in dev.children:
|
|
17
|
+
>>> print(f"{plug.alias}: {plug.is_on}")
|
|
18
|
+
Plug 1: True
|
|
19
|
+
Plug 2: False
|
|
20
|
+
Plug 3: False
|
|
21
|
+
>>> dev.is_on
|
|
22
|
+
True
|
|
23
|
+
>>> await dev.turn_off()
|
|
24
|
+
>>> await dev.update()
|
|
25
|
+
|
|
26
|
+
Accessing individual plugs can be done using the `children` property:
|
|
27
|
+
|
|
28
|
+
>>> len(dev.children)
|
|
29
|
+
3
|
|
30
|
+
>>> for plug in dev.children:
|
|
31
|
+
>>> print(f"{plug.alias}: {plug.is_on}")
|
|
32
|
+
Plug 1: False
|
|
33
|
+
Plug 2: False
|
|
34
|
+
Plug 3: False
|
|
35
|
+
>>> await dev.children[1].turn_on()
|
|
36
|
+
>>> await dev.update()
|
|
37
|
+
>>> dev.is_on
|
|
38
|
+
True
|
|
39
|
+
"""
|
|
2
40
|
|
|
3
41
|
from ..smartmodule import SmartModule
|
|
4
42
|
|
kasa/smart/modules/energy.py
CHANGED
|
@@ -2,60 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
6
|
-
|
|
7
5
|
from ...emeterstatus import EmeterStatus
|
|
8
|
-
from ...
|
|
6
|
+
from ...exceptions import KasaException
|
|
7
|
+
from ...interfaces.energy import Energy as EnergyInterface
|
|
9
8
|
from ..smartmodule import SmartModule
|
|
10
9
|
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from ..smartdevice import SmartDevice
|
|
13
|
-
|
|
14
10
|
|
|
15
|
-
class Energy(SmartModule):
|
|
11
|
+
class Energy(SmartModule, EnergyInterface):
|
|
16
12
|
"""Implementation of energy monitoring module."""
|
|
17
13
|
|
|
18
14
|
REQUIRED_COMPONENT = "energy_monitoring"
|
|
19
15
|
|
|
20
|
-
def __init__(self, device: SmartDevice, module: str):
|
|
21
|
-
super().__init__(device, module)
|
|
22
|
-
self._add_feature(
|
|
23
|
-
Feature(
|
|
24
|
-
device,
|
|
25
|
-
"consumption_current",
|
|
26
|
-
name="Current consumption",
|
|
27
|
-
attribute_getter="current_power",
|
|
28
|
-
container=self,
|
|
29
|
-
unit="W",
|
|
30
|
-
precision_hint=1,
|
|
31
|
-
category=Feature.Category.Primary,
|
|
32
|
-
)
|
|
33
|
-
)
|
|
34
|
-
self._add_feature(
|
|
35
|
-
Feature(
|
|
36
|
-
device,
|
|
37
|
-
"consumption_today",
|
|
38
|
-
name="Today's consumption",
|
|
39
|
-
attribute_getter="emeter_today",
|
|
40
|
-
container=self,
|
|
41
|
-
unit="Wh",
|
|
42
|
-
precision_hint=2,
|
|
43
|
-
category=Feature.Category.Info,
|
|
44
|
-
)
|
|
45
|
-
)
|
|
46
|
-
self._add_feature(
|
|
47
|
-
Feature(
|
|
48
|
-
device,
|
|
49
|
-
"consumption_this_month",
|
|
50
|
-
name="This month's consumption",
|
|
51
|
-
attribute_getter="emeter_this_month",
|
|
52
|
-
container=self,
|
|
53
|
-
unit="Wh",
|
|
54
|
-
precision_hint=2,
|
|
55
|
-
category=Feature.Category.Info,
|
|
56
|
-
)
|
|
57
|
-
)
|
|
58
|
-
|
|
59
16
|
def query(self) -> dict:
|
|
60
17
|
"""Query to execute during the update cycle."""
|
|
61
18
|
req = {
|
|
@@ -66,9 +23,9 @@ class Energy(SmartModule):
|
|
|
66
23
|
return req
|
|
67
24
|
|
|
68
25
|
@property
|
|
69
|
-
def
|
|
26
|
+
def current_consumption(self) -> float | None:
|
|
70
27
|
"""Current power in watts."""
|
|
71
|
-
if power := self.energy.get("current_power"):
|
|
28
|
+
if (power := self.energy.get("current_power")) is not None:
|
|
72
29
|
return power / 1_000
|
|
73
30
|
return None
|
|
74
31
|
|
|
@@ -79,23 +36,64 @@ class Energy(SmartModule):
|
|
|
79
36
|
return en
|
|
80
37
|
return self.data
|
|
81
38
|
|
|
82
|
-
|
|
83
|
-
def emeter_realtime(self):
|
|
84
|
-
"""Get the emeter status."""
|
|
85
|
-
# TODO: Perhaps we should get rid of emeterstatus altogether for smartdevices
|
|
39
|
+
def _get_status_from_energy(self, energy) -> EmeterStatus:
|
|
86
40
|
return EmeterStatus(
|
|
87
41
|
{
|
|
88
|
-
"power_mw":
|
|
89
|
-
"total":
|
|
42
|
+
"power_mw": energy.get("current_power"),
|
|
43
|
+
"total": energy.get("today_energy") / 1_000,
|
|
90
44
|
}
|
|
91
45
|
)
|
|
92
46
|
|
|
93
47
|
@property
|
|
94
|
-
def
|
|
95
|
-
"""Get the emeter
|
|
96
|
-
return self.energy
|
|
48
|
+
def status(self):
|
|
49
|
+
"""Get the emeter status."""
|
|
50
|
+
return self._get_status_from_energy(self.energy)
|
|
51
|
+
|
|
52
|
+
async def get_status(self):
|
|
53
|
+
"""Return real-time statistics."""
|
|
54
|
+
res = await self.call("get_energy_usage")
|
|
55
|
+
return self._get_status_from_energy(res["get_energy_usage"])
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def consumption_this_month(self) -> float | None:
|
|
59
|
+
"""Get the emeter value for this month in kWh."""
|
|
60
|
+
return self.energy.get("month_energy") / 1_000
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def consumption_today(self) -> float | None:
|
|
64
|
+
"""Get the emeter value for today in kWh."""
|
|
65
|
+
return self.energy.get("today_energy") / 1_000
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def consumption_total(self) -> float | None:
|
|
69
|
+
"""Return total consumption since last reboot in kWh."""
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def current(self) -> float | None:
|
|
74
|
+
"""Return the current in A."""
|
|
75
|
+
return None
|
|
97
76
|
|
|
98
77
|
@property
|
|
99
|
-
def
|
|
100
|
-
"""Get the
|
|
101
|
-
return
|
|
78
|
+
def voltage(self) -> float | None:
|
|
79
|
+
"""Get the current voltage in V."""
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
async def _deprecated_get_realtime(self) -> EmeterStatus:
|
|
83
|
+
"""Retrieve current energy readings."""
|
|
84
|
+
return self.status
|
|
85
|
+
|
|
86
|
+
async def erase_stats(self):
|
|
87
|
+
"""Erase all stats."""
|
|
88
|
+
raise KasaException("Device does not support periodic statistics")
|
|
89
|
+
|
|
90
|
+
async def get_daily_stats(self, *, year=None, month=None, kwh=True) -> dict:
|
|
91
|
+
"""Return daily stats for the given year & month.
|
|
92
|
+
|
|
93
|
+
The return value is a dictionary of {day: energy, ...}.
|
|
94
|
+
"""
|
|
95
|
+
raise KasaException("Device does not support periodic statistics")
|
|
96
|
+
|
|
97
|
+
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
|
|
98
|
+
"""Return monthly stats for the given year."""
|
|
99
|
+
raise KasaException("Device does not support periodic statistics")
|
kasa/smart/modules/firmware.py
CHANGED
|
@@ -4,8 +4,9 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import logging
|
|
7
|
+
from collections.abc import Coroutine
|
|
7
8
|
from datetime import date
|
|
8
|
-
from typing import TYPE_CHECKING, Any, Callable,
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Callable, Optional
|
|
9
10
|
|
|
10
11
|
# When support for cpython older than 3.11 is dropped
|
|
11
12
|
# async_timeout can be replaced with asyncio.timeout
|
|
@@ -100,6 +101,7 @@ class Firmware(SmartModule):
|
|
|
100
101
|
container=self,
|
|
101
102
|
attribute_getter="current_firmware",
|
|
102
103
|
category=Feature.Category.Debug,
|
|
104
|
+
type=Feature.Type.Sensor,
|
|
103
105
|
)
|
|
104
106
|
)
|
|
105
107
|
self._add_feature(
|
|
@@ -110,6 +112,7 @@ class Firmware(SmartModule):
|
|
|
110
112
|
container=self,
|
|
111
113
|
attribute_getter="latest_firmware",
|
|
112
114
|
category=Feature.Category.Debug,
|
|
115
|
+
type=Feature.Type.Sensor,
|
|
113
116
|
)
|
|
114
117
|
)
|
|
115
118
|
|
|
@@ -2,15 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
6
|
-
|
|
7
|
-
from ...feature import Feature
|
|
8
5
|
from ..smartmodule import SmartModule
|
|
9
6
|
|
|
10
|
-
# TODO: this may not be necessary with __future__.annotations
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from ..smartdevice import SmartDevice
|
|
13
|
-
|
|
14
7
|
|
|
15
8
|
class FrostProtection(SmartModule):
|
|
16
9
|
"""Implementation for frost protection module.
|
|
@@ -19,23 +12,8 @@ class FrostProtection(SmartModule):
|
|
|
19
12
|
"""
|
|
20
13
|
|
|
21
14
|
REQUIRED_COMPONENT = "frost_protection"
|
|
22
|
-
# TODO: the information required for current features do not require this query
|
|
23
15
|
QUERY_GETTER_NAME = "get_frost_protection"
|
|
24
16
|
|
|
25
|
-
def __init__(self, device: SmartDevice, module: str):
|
|
26
|
-
super().__init__(device, module)
|
|
27
|
-
self._add_feature(
|
|
28
|
-
Feature(
|
|
29
|
-
device,
|
|
30
|
-
"frost_protection_enabled",
|
|
31
|
-
name="Frost protection enabled",
|
|
32
|
-
container=self,
|
|
33
|
-
attribute_getter="enabled",
|
|
34
|
-
attribute_setter="set_enabled",
|
|
35
|
-
type=Feature.Type.Switch,
|
|
36
|
-
)
|
|
37
|
-
)
|
|
38
|
-
|
|
39
17
|
@property
|
|
40
18
|
def enabled(self) -> bool:
|
|
41
19
|
"""Return True if frost protection is on."""
|
kasa/smart/modules/led.py
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from collections.abc import Sequence
|
|
5
6
|
from dataclasses import asdict
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
7
8
|
|
|
8
9
|
from ...interfaces import LightPreset as LightPresetInterface
|
|
9
10
|
from ...interfaces import LightState
|
|
@@ -2,16 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
5
7
|
from ...interfaces.lighteffect import LightEffect as LightEffectInterface
|
|
6
8
|
from ..effects import EFFECT_MAPPING, EFFECT_NAMES
|
|
7
9
|
from ..smartmodule import SmartModule
|
|
8
10
|
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from ..smartdevice import SmartDevice
|
|
13
|
+
|
|
9
14
|
|
|
10
15
|
class LightStripEffect(SmartModule, LightEffectInterface):
|
|
11
16
|
"""Implementation of dynamic light effects."""
|
|
12
17
|
|
|
13
18
|
REQUIRED_COMPONENT = "light_strip_lighting_effect"
|
|
14
19
|
|
|
20
|
+
def __init__(self, device: SmartDevice, module: str):
|
|
21
|
+
super().__init__(device, module)
|
|
22
|
+
effect_list = [self.LIGHT_EFFECTS_OFF]
|
|
23
|
+
effect_list.extend(EFFECT_NAMES)
|
|
24
|
+
self._effect_list = effect_list
|
|
25
|
+
|
|
15
26
|
@property
|
|
16
27
|
def name(self) -> str:
|
|
17
28
|
"""Name of the module.
|
|
@@ -37,7 +48,8 @@ class LightStripEffect(SmartModule, LightEffectInterface):
|
|
|
37
48
|
"""
|
|
38
49
|
eff = self.data["lighting_effect"]
|
|
39
50
|
name = eff["name"]
|
|
40
|
-
|
|
51
|
+
# When devices are unpaired effect name is softAP which is not in our list
|
|
52
|
+
if eff["enable"] and name in self._effect_list:
|
|
41
53
|
return name
|
|
42
54
|
return self.LIGHT_EFFECTS_OFF
|
|
43
55
|
|
|
@@ -48,9 +60,7 @@ class LightStripEffect(SmartModule, LightEffectInterface):
|
|
|
48
60
|
Example:
|
|
49
61
|
['Aurora', 'Bubbling Cauldron', ...]
|
|
50
62
|
"""
|
|
51
|
-
|
|
52
|
-
effect_list.extend(EFFECT_NAMES)
|
|
53
|
-
return effect_list
|
|
63
|
+
return self._effect_list
|
|
54
64
|
|
|
55
65
|
async def set_effect(
|
|
56
66
|
self,
|
|
@@ -181,3 +181,11 @@ class LightTransition(SmartModule):
|
|
|
181
181
|
return {}
|
|
182
182
|
else:
|
|
183
183
|
return {self.QUERY_GETTER_NAME: None}
|
|
184
|
+
|
|
185
|
+
async def _check_supported(self):
|
|
186
|
+
"""Additional check to see if the module is supported by the device."""
|
|
187
|
+
# TODO Temporarily disabled on child light devices until module fixed
|
|
188
|
+
# to support updates
|
|
189
|
+
if self._device._parent is not None:
|
|
190
|
+
return False
|
|
191
|
+
return "brightness" in self._device.sys_info
|