python-homewizard-energy 8.0.0a2__tar.gz → 8.0.0a4__tar.gz
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.
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/PKG-INFO +1 -1
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/__init__.py +2 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/homewizard_energy.py +11 -17
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/models.py +33 -12
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v1/__init__.py +50 -68
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/__init__.py +19 -4
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/pyproject.toml +1 -1
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/LICENSE +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/README.md +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/const.py +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/errors.py +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/py.typed +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v1/const.py +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/cacert.py +0 -0
- {python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/const.py +0 -0
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/__init__.py
RENAMED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
from aiohttp import ClientSession
|
|
4
4
|
|
|
5
5
|
from .errors import DisabledError, InvalidStateError, RequestError, UnsupportedError
|
|
6
|
+
from .homewizard_energy import HomeWizardEnergy
|
|
6
7
|
from .v1 import HomeWizardEnergyV1
|
|
7
8
|
from .v2 import HomeWizardEnergyV2
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
10
11
|
"DisabledError",
|
|
12
|
+
"HomeWizardEnergy",
|
|
11
13
|
"HomeWizardEnergyV1",
|
|
12
14
|
"HomeWizardEnergyV2",
|
|
13
15
|
"InvalidStateError",
|
|
@@ -9,15 +9,7 @@ from aiohttp.client import ClientSession
|
|
|
9
9
|
|
|
10
10
|
from .const import LOGGER
|
|
11
11
|
from .errors import UnsupportedError
|
|
12
|
-
from .models import
|
|
13
|
-
CombinedModels,
|
|
14
|
-
Device,
|
|
15
|
-
Measurement,
|
|
16
|
-
State,
|
|
17
|
-
StateUpdate,
|
|
18
|
-
System,
|
|
19
|
-
SystemUpdate,
|
|
20
|
-
)
|
|
12
|
+
from .models import CombinedModels, Device, Measurement, State, System
|
|
21
13
|
|
|
22
14
|
|
|
23
15
|
class HomeWizardEnergy:
|
|
@@ -67,20 +59,18 @@ class HomeWizardEnergy:
|
|
|
67
59
|
except (UnsupportedError, NotImplementedError):
|
|
68
60
|
return None
|
|
69
61
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
measurement, system, state = await asyncio.gather(
|
|
62
|
+
device, measurement, system, state = await asyncio.gather(
|
|
63
|
+
fetch_data(self.device()),
|
|
74
64
|
fetch_data(self.measurement()),
|
|
75
65
|
fetch_data(self.system()),
|
|
76
66
|
fetch_data(self.state()),
|
|
77
67
|
)
|
|
78
68
|
|
|
79
69
|
return CombinedModels(
|
|
80
|
-
device=
|
|
70
|
+
device=device, measurement=measurement, system=system, state=state
|
|
81
71
|
)
|
|
82
72
|
|
|
83
|
-
async def device(self) -> Device:
|
|
73
|
+
async def device(self, reset_cache: bool = False) -> Device:
|
|
84
74
|
"""Get the device information."""
|
|
85
75
|
raise NotImplementedError
|
|
86
76
|
|
|
@@ -90,14 +80,18 @@ class HomeWizardEnergy:
|
|
|
90
80
|
|
|
91
81
|
async def system(
|
|
92
82
|
self,
|
|
93
|
-
|
|
83
|
+
cloud_enabled: bool | None = None,
|
|
84
|
+
status_led_brightness_pct: int | None = None,
|
|
85
|
+
api_v1_enabled: bool | None = None,
|
|
94
86
|
) -> System:
|
|
95
87
|
"""Get/set the system."""
|
|
96
88
|
raise NotImplementedError
|
|
97
89
|
|
|
98
90
|
async def state(
|
|
99
91
|
self,
|
|
100
|
-
|
|
92
|
+
power_on: bool | None = None,
|
|
93
|
+
switch_lock: bool | None = None,
|
|
94
|
+
brightness: int | None = None,
|
|
101
95
|
) -> State:
|
|
102
96
|
"""Get/set the state."""
|
|
103
97
|
raise UnsupportedError("State is not supported")
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/models.py
RENAMED
|
@@ -43,10 +43,35 @@ class CombinedModels:
|
|
|
43
43
|
"""All values."""
|
|
44
44
|
|
|
45
45
|
device: Device
|
|
46
|
-
measurement: Measurement
|
|
46
|
+
measurement: Measurement
|
|
47
47
|
state: State | None
|
|
48
48
|
system: System | None
|
|
49
49
|
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
device: Device,
|
|
53
|
+
measurement: Measurement,
|
|
54
|
+
state: State | None,
|
|
55
|
+
system: System | None,
|
|
56
|
+
):
|
|
57
|
+
self.device = device
|
|
58
|
+
self.measurement = measurement
|
|
59
|
+
self.state = state
|
|
60
|
+
self.system = system
|
|
61
|
+
|
|
62
|
+
# Move things around for backwards compatibility
|
|
63
|
+
## measurement.wifi_ssid -> system.wifi_ssid
|
|
64
|
+
if self.measurement is not None and self.measurement.wifi_ssid is not None:
|
|
65
|
+
if self.system is None:
|
|
66
|
+
self.system = System()
|
|
67
|
+
self.system.wifi_ssid = self.measurement.wifi_ssid
|
|
68
|
+
|
|
69
|
+
## state.brightness -> system.status_led_brightness_pct
|
|
70
|
+
if self.state is not None and self.state.brightness is not None:
|
|
71
|
+
if self.system is None:
|
|
72
|
+
self.system = System()
|
|
73
|
+
self.system.status_led_brightness_pct = (self.state.brightness / 255) * 100
|
|
74
|
+
|
|
50
75
|
|
|
51
76
|
def get_verification_hostname(model: str, serial_number: str) -> str:
|
|
52
77
|
"""Helper method to convert device model and serial to identifier
|
|
@@ -86,7 +111,7 @@ class Device(BaseModel):
|
|
|
86
111
|
"""Return if the device supports state."""
|
|
87
112
|
return self.product_type == Model.ENERGY_SOCKET
|
|
88
113
|
|
|
89
|
-
def
|
|
114
|
+
def supports_identify(self) -> bool:
|
|
90
115
|
"""Return if the device supports identify."""
|
|
91
116
|
return self.product_type not in (
|
|
92
117
|
Model.ENERGY_METER_1_PHASE,
|
|
@@ -320,7 +345,7 @@ class Measurement(BaseModel):
|
|
|
320
345
|
return rv
|
|
321
346
|
|
|
322
347
|
@staticmethod
|
|
323
|
-
def to_datetime(timestamp: str | int
|
|
348
|
+
def to_datetime(timestamp: str | int) -> datetime:
|
|
324
349
|
"""Convert DSRM gas-timestamp to datetime object.
|
|
325
350
|
|
|
326
351
|
Args:
|
|
@@ -329,10 +354,6 @@ class Measurement(BaseModel):
|
|
|
329
354
|
Returns:
|
|
330
355
|
A datetime object.
|
|
331
356
|
"""
|
|
332
|
-
|
|
333
|
-
if timestamp is None:
|
|
334
|
-
return None
|
|
335
|
-
|
|
336
357
|
if isinstance(timestamp, int):
|
|
337
358
|
# V1 API uses int for timestamp
|
|
338
359
|
return datetime.strptime(str(timestamp), "%y%m%d%H%M%S")
|
|
@@ -424,7 +445,7 @@ class Measurement(BaseModel):
|
|
|
424
445
|
return d
|
|
425
446
|
|
|
426
447
|
|
|
427
|
-
@dataclass
|
|
448
|
+
@dataclass(kw_only=True)
|
|
428
449
|
class ExternalDevice(BaseModel):
|
|
429
450
|
"""Represents externally connected device."""
|
|
430
451
|
|
|
@@ -438,7 +459,7 @@ class ExternalDevice(BaseModel):
|
|
|
438
459
|
INLET_HEAT_METER = "inlet_heat_meter"
|
|
439
460
|
|
|
440
461
|
unique_id: datetime = field(
|
|
441
|
-
|
|
462
|
+
metadata={"deserialize": lambda x: Measurement.hex_to_readable(x)}
|
|
442
463
|
)
|
|
443
464
|
|
|
444
465
|
type: DeviceType | None = field(
|
|
@@ -449,10 +470,10 @@ class ExternalDevice(BaseModel):
|
|
|
449
470
|
else None
|
|
450
471
|
},
|
|
451
472
|
)
|
|
452
|
-
value: float = field(
|
|
453
|
-
unit: str = field(
|
|
473
|
+
value: float = field()
|
|
474
|
+
unit: str = field()
|
|
454
475
|
timestamp: datetime = field(
|
|
455
|
-
|
|
476
|
+
metadata={"deserialize": lambda x: Measurement.to_datetime(x)}
|
|
456
477
|
)
|
|
457
478
|
|
|
458
479
|
|
|
@@ -15,15 +15,7 @@ from aiohttp.hdrs import METH_GET, METH_PUT
|
|
|
15
15
|
from ..const import LOGGER
|
|
16
16
|
from ..errors import DisabledError, NotFoundError, RequestError, UnsupportedError
|
|
17
17
|
from ..homewizard_energy import HomeWizardEnergy
|
|
18
|
-
from ..models import
|
|
19
|
-
CombinedModels,
|
|
20
|
-
Device,
|
|
21
|
-
Measurement,
|
|
22
|
-
State,
|
|
23
|
-
StateUpdate,
|
|
24
|
-
System,
|
|
25
|
-
SystemUpdate,
|
|
26
|
-
)
|
|
18
|
+
from ..models import Device, Measurement, State, StateUpdate, System, SystemUpdate
|
|
27
19
|
|
|
28
20
|
T = TypeVar("T")
|
|
29
21
|
|
|
@@ -46,33 +38,17 @@ def optional_method(
|
|
|
46
38
|
class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
47
39
|
"""Communicate with a HomeWizard Energy device."""
|
|
48
40
|
|
|
49
|
-
async def
|
|
50
|
-
"""
|
|
51
|
-
|
|
52
|
-
models: CombinedModels = await super().combined()
|
|
53
|
-
|
|
54
|
-
# Move things around for backwards compatibility
|
|
55
|
-
## measurement.wifi_ssid -> system.wifi_ssid
|
|
56
|
-
if models.measurement is not None and models.measurement.wifi_ssid is not None:
|
|
57
|
-
if models.system is None:
|
|
58
|
-
models.system = System()
|
|
59
|
-
models.system.wifi_ssid = models.measurement.wifi_ssid
|
|
60
|
-
|
|
61
|
-
## state.brightness -> system.status_led_brightness_pct
|
|
62
|
-
if models.state is not None and models.state.brightness is not None:
|
|
63
|
-
if models.system is None:
|
|
64
|
-
models.system = System()
|
|
65
|
-
models.system.status_led_brightness_pct = (
|
|
66
|
-
models.state.brightness / 255
|
|
67
|
-
) * 100
|
|
41
|
+
async def device(self, reset_cache: bool = False) -> Device:
|
|
42
|
+
"""Return the device object."""
|
|
68
43
|
|
|
69
|
-
|
|
44
|
+
if self._device is not None and not reset_cache:
|
|
45
|
+
return self._device
|
|
70
46
|
|
|
71
|
-
async def device(self) -> Device:
|
|
72
|
-
"""Return the device object."""
|
|
73
47
|
_, response = await self._request("api")
|
|
74
48
|
device = Device.from_json(response)
|
|
75
49
|
|
|
50
|
+
# Cache device object
|
|
51
|
+
self._device = device
|
|
76
52
|
return device
|
|
77
53
|
|
|
78
54
|
async def measurement(self) -> Measurement:
|
|
@@ -81,52 +57,61 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
81
57
|
return Measurement.from_json(response)
|
|
82
58
|
|
|
83
59
|
@optional_method
|
|
84
|
-
async def
|
|
85
|
-
|
|
60
|
+
async def system(
|
|
61
|
+
self,
|
|
62
|
+
cloud_enabled: bool | None = None,
|
|
63
|
+
status_led_brightness_pct: int | None = None,
|
|
64
|
+
api_v1_enabled: bool | None = None,
|
|
65
|
+
) -> System:
|
|
66
|
+
"""Return the system object."""
|
|
86
67
|
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
# Legacy: raise on unsupported field
|
|
69
|
+
if api_v1_enabled is not None:
|
|
70
|
+
raise UnsupportedError("Setting api_v1_enabled is not supported in v1")
|
|
89
71
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
72
|
+
# Legacy: route 'status_led_brightness_pct' to state
|
|
73
|
+
if status_led_brightness_pct is not None:
|
|
74
|
+
state = await self.state(brightness=status_led_brightness_pct * 2.55)
|
|
75
|
+
return System(status_led_brightness_pct=state.brightness / 2.55)
|
|
76
|
+
|
|
77
|
+
if cloud_enabled is not None:
|
|
78
|
+
# Executing the update
|
|
79
|
+
data = SystemUpdate(cloud_enabled=cloud_enabled).to_dict()
|
|
80
|
+
_, response = await self._request(
|
|
81
|
+
"api/v1/system", method=METH_PUT, data=data
|
|
94
82
|
)
|
|
95
83
|
|
|
96
84
|
else:
|
|
97
|
-
|
|
85
|
+
_, response = await self._request("api/v1/system")
|
|
98
86
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
state = State.from_json(response)
|
|
103
|
-
return state
|
|
87
|
+
system = System.from_json(response)
|
|
88
|
+
return system
|
|
104
89
|
|
|
105
90
|
@optional_method
|
|
106
|
-
async def
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
raise UnsupportedError(
|
|
114
|
-
"Setting status_led_brightness_pct and api_v1_enabled is not supported in v1"
|
|
115
|
-
)
|
|
91
|
+
async def state(
|
|
92
|
+
self,
|
|
93
|
+
power_on: bool | None = None,
|
|
94
|
+
switch_lock: bool | None = None,
|
|
95
|
+
brightness: int | None = None,
|
|
96
|
+
) -> State:
|
|
97
|
+
"""Return or update the state object."""
|
|
116
98
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
99
|
+
if self._device is not None and self._device.supports_state() is False:
|
|
100
|
+
raise UnsupportedError("State is not supported")
|
|
101
|
+
|
|
102
|
+
if power_on is not None or switch_lock is not None or brightness is not None:
|
|
103
|
+
data = StateUpdate(
|
|
104
|
+
power_on=power_on, switch_lock=switch_lock, brightness=brightness
|
|
105
|
+
).to_dict()
|
|
106
|
+
_, response = await self._request(
|
|
107
|
+
"api/v1/state", method=METH_PUT, data=data
|
|
120
108
|
)
|
|
121
109
|
|
|
122
110
|
else:
|
|
123
|
-
|
|
111
|
+
_, response = await self._request("api/v1/state")
|
|
124
112
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
system = System.from_json(response)
|
|
129
|
-
return system
|
|
113
|
+
state = State.from_json(response)
|
|
114
|
+
return state
|
|
130
115
|
|
|
131
116
|
@optional_method
|
|
132
117
|
async def identify(
|
|
@@ -134,7 +119,7 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
134
119
|
) -> bool:
|
|
135
120
|
"""Send identify request."""
|
|
136
121
|
|
|
137
|
-
if self._device is not None and self._device.
|
|
122
|
+
if self._device is not None and self._device.supports_identify() is False:
|
|
138
123
|
raise UnsupportedError("State is not supported")
|
|
139
124
|
|
|
140
125
|
await self._request("api/v1/identify", method=METH_PUT)
|
|
@@ -179,9 +164,6 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
179
164
|
raise DisabledError(
|
|
180
165
|
"API disabled. API must be enabled in HomeWizard Energy app"
|
|
181
166
|
)
|
|
182
|
-
case HTTPStatus.NO_CONTENT:
|
|
183
|
-
# No content, just return
|
|
184
|
-
return (HTTPStatus.NO_CONTENT, None)
|
|
185
167
|
case HTTPStatus.NOT_FOUND:
|
|
186
168
|
raise NotFoundError("Resource not found")
|
|
187
169
|
case HTTPStatus.OK:
|
|
@@ -72,11 +72,16 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
|
72
72
|
self._token = token
|
|
73
73
|
|
|
74
74
|
@authorized_method
|
|
75
|
-
async def device(self) -> Device:
|
|
75
|
+
async def device(self, reset_cache: bool = False) -> Device:
|
|
76
76
|
"""Return the device object."""
|
|
77
|
+
if self._device is not None and not reset_cache:
|
|
78
|
+
return self._device
|
|
79
|
+
|
|
77
80
|
_, response = await self._request("/api")
|
|
78
81
|
device = Device.from_json(response)
|
|
79
82
|
|
|
83
|
+
# Cache device object
|
|
84
|
+
self._device = device
|
|
80
85
|
return device
|
|
81
86
|
|
|
82
87
|
@authorized_method
|
|
@@ -90,12 +95,22 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
|
90
95
|
@authorized_method
|
|
91
96
|
async def system(
|
|
92
97
|
self,
|
|
93
|
-
|
|
98
|
+
cloud_enabled: bool | None = None,
|
|
99
|
+
status_led_brightness_pct: int | None = None,
|
|
100
|
+
api_v1_enabled: bool | None = None,
|
|
94
101
|
) -> System:
|
|
95
102
|
"""Return the system object."""
|
|
96
103
|
|
|
97
|
-
if
|
|
98
|
-
|
|
104
|
+
if (
|
|
105
|
+
cloud_enabled is not None
|
|
106
|
+
or status_led_brightness_pct is not None
|
|
107
|
+
or api_v1_enabled is not None
|
|
108
|
+
):
|
|
109
|
+
data = SystemUpdate(
|
|
110
|
+
cloud_enabled=cloud_enabled,
|
|
111
|
+
status_led_brightness_pct=status_led_brightness_pct,
|
|
112
|
+
api_v1_enabled=api_v1_enabled,
|
|
113
|
+
).to_dict()
|
|
99
114
|
status, response = await self._request(
|
|
100
115
|
"/api/system", method=METH_PUT, data=data
|
|
101
116
|
)
|
|
File without changes
|
|
File without changes
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/const.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/errors.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/py.typed
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v1/const.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/cacert.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a2 → python_homewizard_energy-8.0.0a4}/homewizard_energy/v2/const.py
RENAMED
|
File without changes
|