python-homewizard-energy 8.0.0a4__tar.gz → 8.0.0a6__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.0a4 → python_homewizard_energy-8.0.0a6}/PKG-INFO +2 -2
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/__init__.py +4 -4
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/homewizard_energy.py +20 -1
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/models.py +3 -15
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v1/__init__.py +2 -3
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v2/__init__.py +12 -23
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/pyproject.toml +2 -2
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/LICENSE +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/README.md +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/const.py +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/errors.py +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/py.typed +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v1/const.py +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v2/cacert.py +0 -0
- {python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/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.0a6
|
|
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.0a4 → python_homewizard_energy-8.0.0a6}/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
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import asyncio
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
|
-
from aiohttp.client import ClientSession
|
|
8
|
+
from aiohttp.client import ClientSession, ClientTimeout, TCPConnector
|
|
9
9
|
|
|
10
10
|
from .const import LOGGER
|
|
11
11
|
from .errors import UnsupportedError
|
|
@@ -114,6 +114,25 @@ class HomeWizardEnergy:
|
|
|
114
114
|
if self._session and self._close_session:
|
|
115
115
|
await self._session.close()
|
|
116
116
|
|
|
117
|
+
async def _create_clientsession(self) -> None:
|
|
118
|
+
"""Create a client session."""
|
|
119
|
+
|
|
120
|
+
if self._session is not None:
|
|
121
|
+
raise RuntimeError("Session already exists")
|
|
122
|
+
|
|
123
|
+
connector = TCPConnector(
|
|
124
|
+
enable_cleanup_closed=True,
|
|
125
|
+
limit_per_host=1,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
self._close_session = True
|
|
129
|
+
|
|
130
|
+
self._session = ClientSession(
|
|
131
|
+
connector=connector, timeout=ClientTimeout(total=self._request_timeout)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# self._session = self._create_clientsession(connector, timeout=ClientTimeout(total=self._request_timeout))
|
|
135
|
+
|
|
117
136
|
async def __aenter__(self) -> HomeWizardEnergy:
|
|
118
137
|
"""Async enter.
|
|
119
138
|
|
{python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/models.py
RENAMED
|
@@ -385,8 +385,6 @@ class Measurement(BaseModel):
|
|
|
385
385
|
return d
|
|
386
386
|
|
|
387
387
|
d["protocol_version"] = d.get("smr_version")
|
|
388
|
-
d["meter_model"] = d.get("meter_model")
|
|
389
|
-
d["unique_id"] = d.get("unique_meter_id")
|
|
390
388
|
d["tariff"] = d.get("active_tariff")
|
|
391
389
|
d["energy_import_kwh"] = d.get(
|
|
392
390
|
"total_power_import_kwh", d.get("total_power_import_t1_kwh")
|
|
@@ -427,19 +425,9 @@ class Measurement(BaseModel):
|
|
|
427
425
|
d["power_factor_l2"] = d.get("active_power_factor_l2")
|
|
428
426
|
d["power_factor_l3"] = d.get("active_power_factor_l3")
|
|
429
427
|
d["frequency_hz"] = d.get("active_frequency_hz")
|
|
430
|
-
d["voltage_sag_l1_count"] = d.get("voltage_sag_l1_count")
|
|
431
|
-
d["voltage_sag_l2_count"] = d.get("voltage_sag_l2_count")
|
|
432
|
-
d["voltage_sag_l3_count"] = d.get("voltage_sag_l3_count")
|
|
433
|
-
d["voltage_swell_l1_count"] = d.get("voltage_swell_l1_count")
|
|
434
|
-
d["voltage_swell_l2_count"] = d.get("voltage_swell_l2_count")
|
|
435
|
-
d["voltage_swell_l3_count"] = d.get("voltage_swell_l3_count")
|
|
436
|
-
d["any_power_fail_count"] = d.get("any_power_fail_count")
|
|
437
|
-
d["long_power_fail_count"] = d.get("long_power_fail_count")
|
|
438
428
|
d["average_power_15m_w"] = d.get("active_power_average_w")
|
|
439
429
|
d["monthly_power_peak_w"] = d.get("montly_power_peak_w")
|
|
440
430
|
d["monthly_power_peak_timestamp"] = d.get("montly_power_peak_timestamp")
|
|
441
|
-
d["active_liter_lpm"] = d.get("active_liter_lpm")
|
|
442
|
-
d["total_liter_m3"] = d.get("total_liter_m3")
|
|
443
431
|
d["external_devices"] = d.get("external_devices")
|
|
444
432
|
|
|
445
433
|
return d
|
|
@@ -465,9 +453,9 @@ class ExternalDevice(BaseModel):
|
|
|
465
453
|
type: DeviceType | None = field(
|
|
466
454
|
default=None,
|
|
467
455
|
metadata={
|
|
468
|
-
"deserialize": lambda x: ExternalDevice.DeviceType(
|
|
469
|
-
|
|
470
|
-
|
|
456
|
+
"deserialize": lambda x: ExternalDevice.DeviceType.__members__.get(
|
|
457
|
+
x.upper(), None
|
|
458
|
+
)
|
|
471
459
|
},
|
|
472
460
|
)
|
|
473
461
|
value: float = field()
|
|
@@ -9,7 +9,7 @@ from typing import Any, TypeVar
|
|
|
9
9
|
|
|
10
10
|
import async_timeout
|
|
11
11
|
import backoff
|
|
12
|
-
from aiohttp.client import ClientError, ClientResponseError
|
|
12
|
+
from aiohttp.client import ClientError, ClientResponseError
|
|
13
13
|
from aiohttp.hdrs import METH_GET, METH_PUT
|
|
14
14
|
|
|
15
15
|
from ..const import LOGGER
|
|
@@ -132,8 +132,7 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
|
|
|
132
132
|
"""Make a request to the API."""
|
|
133
133
|
|
|
134
134
|
if self._session is None:
|
|
135
|
-
self.
|
|
136
|
-
self._close_session = True
|
|
135
|
+
await self._create_clientsession()
|
|
137
136
|
|
|
138
137
|
# Construct request
|
|
139
138
|
url = f"http://{self.host}/{path}"
|
|
@@ -11,13 +11,7 @@ from typing import Any, TypeVar
|
|
|
11
11
|
|
|
12
12
|
import async_timeout
|
|
13
13
|
import backoff
|
|
14
|
-
from aiohttp.client import
|
|
15
|
-
ClientError,
|
|
16
|
-
ClientResponseError,
|
|
17
|
-
ClientSession,
|
|
18
|
-
ClientTimeout,
|
|
19
|
-
TCPConnector,
|
|
20
|
-
)
|
|
14
|
+
from aiohttp.client import ClientError, ClientResponseError, ClientSession
|
|
21
15
|
from aiohttp.hdrs import METH_DELETE, METH_GET, METH_POST, METH_PUT
|
|
22
16
|
from mashumaro.exceptions import InvalidFieldValue, MissingField
|
|
23
17
|
|
|
@@ -49,6 +43,9 @@ def authorized_method(
|
|
|
49
43
|
class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
50
44
|
"""Communicate with a HomeWizard Energy device."""
|
|
51
45
|
|
|
46
|
+
_ssl: ssl.SSLContext | bool = False
|
|
47
|
+
_identifier: str | None = None
|
|
48
|
+
|
|
52
49
|
# pylint: disable=too-many-arguments
|
|
53
50
|
# pylint: disable=too-many-positional-arguments
|
|
54
51
|
def __init__(
|
|
@@ -191,7 +188,7 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
|
191
188
|
if name is None:
|
|
192
189
|
self._token = None
|
|
193
190
|
|
|
194
|
-
async def
|
|
191
|
+
async def _get_ssl_context(self) -> ssl.SSLContext:
|
|
195
192
|
"""
|
|
196
193
|
Get a clientsession that is tuned for communication with the HomeWizard Energy Device
|
|
197
194
|
"""
|
|
@@ -208,17 +205,7 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
|
208
205
|
|
|
209
206
|
# Creating an SSL context has some blocking IO so need to run it in the executor
|
|
210
207
|
loop = asyncio.get_running_loop()
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
connector = TCPConnector(
|
|
214
|
-
enable_cleanup_closed=True,
|
|
215
|
-
ssl=context,
|
|
216
|
-
limit_per_host=1,
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
return ClientSession(
|
|
220
|
-
connector=connector, timeout=ClientTimeout(total=self._request_timeout)
|
|
221
|
-
)
|
|
208
|
+
return await loop.run_in_executor(None, _build_ssl_context)
|
|
222
209
|
|
|
223
210
|
@backoff.on_exception(backoff.expo, RequestError, max_tries=3, logger=None)
|
|
224
211
|
async def _request(
|
|
@@ -227,7 +214,10 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
|
227
214
|
"""Make a request to the API."""
|
|
228
215
|
|
|
229
216
|
if self._session is None:
|
|
230
|
-
|
|
217
|
+
await self._create_clientsession()
|
|
218
|
+
|
|
219
|
+
if self._ssl is False:
|
|
220
|
+
self._ssl = await self._get_ssl_context()
|
|
231
221
|
|
|
232
222
|
# Construct request
|
|
233
223
|
url = f"https://{self.host}{path}"
|
|
@@ -246,9 +236,8 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
|
|
|
246
236
|
url,
|
|
247
237
|
json=data,
|
|
248
238
|
headers=headers,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
else None,
|
|
239
|
+
ssl=self._ssl,
|
|
240
|
+
server_hostname=self._identifier,
|
|
252
241
|
)
|
|
253
242
|
LOGGER.debug("%s, %s", resp.status, await resp.text("utf-8"))
|
|
254
243
|
except asyncio.TimeoutError as exception:
|
|
@@ -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-6"
|
|
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.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/const.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/errors.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/py.typed
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v1/const.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v2/cacert.py
RENAMED
|
File without changes
|
{python_homewizard_energy-8.0.0a4 → python_homewizard_energy-8.0.0a6}/homewizard_energy/v2/const.py
RENAMED
|
File without changes
|