python-homewizard-energy 8.0.0a3__tar.gz → 8.0.0a5__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.0a3 → python_homewizard_energy-8.0.0a5}/PKG-INFO +2 -2
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/__init__.py +4 -4
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/homewizard_energy.py +4 -6
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/models.py +31 -10
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v1/__init__.py +13 -46
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v2/__init__.py +6 -1
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/pyproject.toml +2 -2
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/LICENSE +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/README.md +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/const.py +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/errors.py +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/py.typed +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v1/const.py +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v2/cacert.py +0 -0
- {python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v2/const.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-homewizard-energy
|
|
3
|
-
Version: 8.0.
|
|
3
|
+
Version: 8.0.0a5
|
|
4
4
|
Summary: Asynchronous Python client for the HomeWizard Energy
|
|
5
5
|
Home-page: https://github.com/homewizard/python-homewizard-energy
|
|
6
6
|
License: Apache-2.0
|
|
@@ -16,7 +16,7 @@ Requires-Dist: async-timeout (>=4.0.3,<6.0.0)
|
|
|
16
16
|
Requires-Dist: backoff (>=2.2.1,<3.0.0)
|
|
17
17
|
Requires-Dist: mashumaro (>=3.15,<4.0)
|
|
18
18
|
Requires-Dist: multidict (>=6.0.5,<7.0.0)
|
|
19
|
-
Requires-Dist: orjson (>=3.10
|
|
19
|
+
Requires-Dist: orjson (>=3.10,<4.0)
|
|
20
20
|
Project-URL: Bug Tracker, https://github.com/homewizard/python-homewizard-energy/issues
|
|
21
21
|
Project-URL: Changelog, https://github.com/homewizard/python-homewizard-energy/releases
|
|
22
22
|
Project-URL: Documentation, https://github.com/homewizard/python-homewizard-energy
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/__init__.py
RENAMED
|
@@ -27,10 +27,10 @@ async def has_v2_api(host: str, websession: ClientSession | None = None) -> bool
|
|
|
27
27
|
# v2 api is https only and returns a 401 Unauthorized when no key provided,
|
|
28
28
|
# no connection can be made if the device is not v2
|
|
29
29
|
url = f"https://{host}/api"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
res = await websession.get(url, ssl=False, raise_for_status=False, timeout=5)
|
|
31
|
+
res.close()
|
|
32
|
+
|
|
33
|
+
return res.status == 401
|
|
34
34
|
except Exception: # pylint: disable=broad-except
|
|
35
35
|
# all other status/exceptions means the device is not v2 or not reachable at this time
|
|
36
36
|
return False
|
|
@@ -59,20 +59,18 @@ class HomeWizardEnergy:
|
|
|
59
59
|
except (UnsupportedError, NotImplementedError):
|
|
60
60
|
return None
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
measurement, system, state = await asyncio.gather(
|
|
62
|
+
device, measurement, system, state = await asyncio.gather(
|
|
63
|
+
fetch_data(self.device()),
|
|
66
64
|
fetch_data(self.measurement()),
|
|
67
65
|
fetch_data(self.system()),
|
|
68
66
|
fetch_data(self.state()),
|
|
69
67
|
)
|
|
70
68
|
|
|
71
69
|
return CombinedModels(
|
|
72
|
-
device=
|
|
70
|
+
device=device, measurement=measurement, system=system, state=state
|
|
73
71
|
)
|
|
74
72
|
|
|
75
|
-
async def device(self) -> Device:
|
|
73
|
+
async def device(self, reset_cache: bool = False) -> Device:
|
|
76
74
|
"""Get the device information."""
|
|
77
75
|
raise NotImplementedError
|
|
78
76
|
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/models.py
RENAMED
|
@@ -47,6 +47,31 @@ class CombinedModels:
|
|
|
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
|
|
@@ -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:
|
|
@@ -101,15 +77,12 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
101
77
|
if cloud_enabled is not None:
|
|
102
78
|
# Executing the update
|
|
103
79
|
data = SystemUpdate(cloud_enabled=cloud_enabled).to_dict()
|
|
104
|
-
|
|
80
|
+
_, response = await self._request(
|
|
105
81
|
"api/v1/system", method=METH_PUT, data=data
|
|
106
82
|
)
|
|
107
83
|
|
|
108
84
|
else:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if status != HTTPStatus.OK:
|
|
112
|
-
raise RequestError("Failed to get/set system")
|
|
85
|
+
_, response = await self._request("api/v1/system")
|
|
113
86
|
|
|
114
87
|
system = System.from_json(response)
|
|
115
88
|
return system
|
|
@@ -123,22 +96,19 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
123
96
|
) -> State:
|
|
124
97
|
"""Return or update the state object."""
|
|
125
98
|
|
|
126
|
-
if self._device is not None and self._device.supports_state is False:
|
|
99
|
+
if self._device is not None and self._device.supports_state() is False:
|
|
127
100
|
raise UnsupportedError("State is not supported")
|
|
128
101
|
|
|
129
102
|
if power_on is not None or switch_lock is not None or brightness is not None:
|
|
130
103
|
data = StateUpdate(
|
|
131
104
|
power_on=power_on, switch_lock=switch_lock, brightness=brightness
|
|
132
105
|
).to_dict()
|
|
133
|
-
|
|
106
|
+
_, response = await self._request(
|
|
134
107
|
"api/v1/state", method=METH_PUT, data=data
|
|
135
108
|
)
|
|
136
109
|
|
|
137
110
|
else:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if status != HTTPStatus.OK:
|
|
141
|
-
raise RequestError("Failed to get/set state")
|
|
111
|
+
_, response = await self._request("api/v1/state")
|
|
142
112
|
|
|
143
113
|
state = State.from_json(response)
|
|
144
114
|
return state
|
|
@@ -149,7 +119,7 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
149
119
|
) -> bool:
|
|
150
120
|
"""Send identify request."""
|
|
151
121
|
|
|
152
|
-
if self._device is not None and self._device.
|
|
122
|
+
if self._device is not None and self._device.supports_identify() is False:
|
|
153
123
|
raise UnsupportedError("State is not supported")
|
|
154
124
|
|
|
155
125
|
await self._request("api/v1/identify", method=METH_PUT)
|
|
@@ -194,9 +164,6 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
194
164
|
raise DisabledError(
|
|
195
165
|
"API disabled. API must be enabled in HomeWizard Energy app"
|
|
196
166
|
)
|
|
197
|
-
case HTTPStatus.NO_CONTENT:
|
|
198
|
-
# No content, just return
|
|
199
|
-
return (HTTPStatus.NO_CONTENT, None)
|
|
200
167
|
case HTTPStatus.NOT_FOUND:
|
|
201
168
|
raise NotFoundError("Resource not found")
|
|
202
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "python-homewizard-energy"
|
|
3
|
-
version = "8.0.0-alpha-
|
|
3
|
+
version = "8.0.0-alpha-5"
|
|
4
4
|
description = "Asynchronous Python client for the HomeWizard Energy"
|
|
5
5
|
authors = ["DCSBL"]
|
|
6
6
|
maintainers = ["DCSBL"]
|
|
@@ -21,7 +21,7 @@ aiohttp = ">=3.0.0"
|
|
|
21
21
|
async-timeout = ">=4.0.3,<6.0.0"
|
|
22
22
|
multidict = "^6.0.5" ## To fix aiohttp dependency at python 3.12
|
|
23
23
|
backoff = "^2.2.1"
|
|
24
|
-
orjson = "^3.10
|
|
24
|
+
orjson = "^3.10"
|
|
25
25
|
mashumaro = "^3.15"
|
|
26
26
|
|
|
27
27
|
[tool.poetry.dev-dependencies]
|
|
File without changes
|
|
File without changes
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/const.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/errors.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/py.typed
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v1/const.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v2/cacert.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a3 → python_homewizard_energy-8.0.0a5}/homewizard_energy/v2/const.py
RENAMED
|
File without changes
|