python-homewizard-energy 7.0.0b1__tar.gz → 7.1.0b2__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.
Files changed (17) hide show
  1. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/PKG-INFO +1 -1
  2. python_homewizard_energy-7.1.0b2/homewizard_energy/__init__.py +37 -0
  3. python_homewizard_energy-7.1.0b2/homewizard_energy/models.py +168 -0
  4. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/v1/__init__.py +2 -1
  5. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/v1/models.py +1 -34
  6. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/v2/__init__.py +2 -1
  7. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/v2/models.py +6 -34
  8. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/pyproject.toml +6 -6
  9. python_homewizard_energy-7.0.0b1/homewizard_energy/__init__.py +0 -14
  10. python_homewizard_energy-7.0.0b1/homewizard_energy/brand.py +0 -95
  11. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/LICENSE +0 -0
  12. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/README.md +0 -0
  13. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/errors.py +0 -0
  14. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/py.typed +0 -0
  15. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/v1/const.py +0 -0
  16. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/homewizard_energy/v2/cacert.py +0 -0
  17. {python_homewizard_energy-7.0.0b1 → python_homewizard_energy-7.1.0b2}/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: 7.0.0b1
3
+ Version: 7.1.0b2
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
@@ -0,0 +1,37 @@
1
+ """HomeWizard Energy API library."""
2
+
3
+ from aiohttp import ClientSession
4
+
5
+ from .errors import DisabledError, InvalidStateError, RequestError, UnsupportedError
6
+ from .v1 import HomeWizardEnergyV1
7
+ from .v2 import HomeWizardEnergyV2
8
+
9
+ __all__ = [
10
+ "DisabledError",
11
+ "HomeWizardEnergyV1",
12
+ "HomeWizardEnergyV2",
13
+ "InvalidStateError",
14
+ "RequestError",
15
+ "UnsupportedError",
16
+ ]
17
+
18
+
19
+ async def has_v2_api(host: str, websession: ClientSession | None = None) -> bool:
20
+ """Check if the device has support for the v2 api."""
21
+ websession_provided = websession is not None
22
+ if websession is None:
23
+ websession = ClientSession()
24
+ try:
25
+ # v2 api is https only and returns a 401 Unauthorized when no key provided,
26
+ # no connection can be made if the device is not v2
27
+ url = f"https://{host}/api"
28
+ async with websession.get(
29
+ url, ssl=False, raise_for_status=False, timeout=15
30
+ ) as res:
31
+ return res.status == 401
32
+ except Exception: # pylint: disable=broad-except
33
+ # all other status/exceptions means the device is not v2 or not reachable at this time
34
+ return False
35
+ finally:
36
+ if not websession_provided:
37
+ await websession.close()
@@ -0,0 +1,168 @@
1
+ """Common models for HomeWizard Energy API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ MODELS = {
8
+ "HWE-P1": "p1dongle",
9
+ "HWE-SKT": "energysocket",
10
+ "HWE-WTR": "watermeter",
11
+ "HWE-DSP": "display",
12
+ "HWE-KWH1": "energymeter",
13
+ "SDM230-wifi": "energymeter",
14
+ "HWE-KWH3": "energymeter",
15
+ "SDM630-wifi": "energymeter",
16
+ "HWE-BAT": "battery",
17
+ }
18
+
19
+
20
+ def get_verification_hostname(model: str, serial_number: str) -> str:
21
+ """Helper method to convert device model and serial to identifier
22
+
23
+ The identifier is used to verify the device in the HomeWizard Energy API via HTTPS.
24
+ """
25
+
26
+ if model not in MODELS:
27
+ raise ValueError(f"Unsupported model: {model}")
28
+
29
+ return f"appliance/{MODELS[model]}/{serial_number}"
30
+
31
+
32
+ @dataclass
33
+ class Device:
34
+ """Represent Device config."""
35
+
36
+ product: Product | None
37
+ product_name: str | None
38
+ product_type: str | None
39
+ serial: str | None
40
+ api_version: str | None
41
+ firmware_version: str | None
42
+ id: str | None
43
+
44
+ @staticmethod
45
+ def from_dict(data: dict[str, str]) -> Device:
46
+ """Return Device object from API response.
47
+
48
+ This model is common for both v1 and v2 API.
49
+
50
+ Args:
51
+ data: The data from the HomeWizard Energy `api` API.
52
+
53
+ Returns:
54
+ A Device object.
55
+ """
56
+
57
+ try:
58
+ _id = get_verification_hostname(
59
+ data.get("product_type"), data.get("serial")
60
+ )
61
+ except ValueError:
62
+ _id = None
63
+
64
+ return Device(
65
+ product=Product.from_type(data.get("product_type")),
66
+ product_name=data.get("product_name"),
67
+ product_type=data.get("product_type"),
68
+ serial=data.get("serial"),
69
+ api_version=data.get("api_version"),
70
+ firmware_version=data.get("firmware_version"),
71
+ id=_id,
72
+ )
73
+
74
+
75
+ @dataclass(frozen=True)
76
+ class Product:
77
+ """Represent a product."""
78
+
79
+ model: str
80
+ name: str | None
81
+ url: str | None
82
+ description: str | None
83
+
84
+ def __str__(self):
85
+ """Return a string representation of the product."""
86
+ return f"HomeWizard {self.name} - {self.model}"
87
+
88
+ def __hash__(self):
89
+ """Hash a product for unit-test snapshots."""
90
+ return hash((self.model, self.name, self.url, self.description))
91
+
92
+ def __eq__(self, other):
93
+ """Compare two products."""
94
+ if isinstance(other, Product):
95
+ return (
96
+ self.model == other.model
97
+ and self.name == other.name
98
+ and self.url == other.url
99
+ and self.description == other.description
100
+ )
101
+ return False
102
+
103
+ @staticmethod
104
+ def from_type(product_type: str, _: str | None = None) -> Product | None:
105
+ """Return a Product object from a type.
106
+
107
+ :param type: The type of the product.
108
+ :param locale: The locale to use for the description. Currently ignored. Should be an ISO 639-1 language code.
109
+ """
110
+
111
+ # pylint: disable=unused-argument
112
+
113
+ for product in PRODUCTS:
114
+ if product.model == product_type:
115
+ return product
116
+ return None
117
+
118
+
119
+ PRODUCTS = {
120
+ Product(
121
+ "HWE-P1",
122
+ "Wi-Fi P1 Meter",
123
+ "https://www.homewizard.com/p1-meter/",
124
+ "The HomeWizard P1 Meter gives you detailed insight in your electricity-, gas consumption and solar surplus.",
125
+ ),
126
+ Product(
127
+ "HWE-SKT",
128
+ "Wi-Fi Energy Socket",
129
+ "https://www.homewizard.com/energy-socket/",
130
+ "Measure and switch every device.",
131
+ ),
132
+ Product(
133
+ "HWE-WTR",
134
+ "Wi-Fi Watermeter",
135
+ "https://www.homewizard.com/watermeter/",
136
+ "Real-time water consumption insights",
137
+ ),
138
+ Product(
139
+ "HWE-KWH1",
140
+ "Wi-Fi kWh Meter 1-phase",
141
+ "https://www.homewizard.com/kwh-meter/",
142
+ "Measure solar panels, car chargers and more.",
143
+ ),
144
+ Product(
145
+ "HWE-KWH3",
146
+ "Wi-Fi kWh Meter 3-phase",
147
+ "https://www.homewizard.com/kwh-meter/",
148
+ "Measure solar panels, car chargers and more.",
149
+ ),
150
+ Product(
151
+ "SDM230-wifi",
152
+ "Wi-Fi kWh Meter 1-phase",
153
+ "https://www.homewizard.com/kwh-meter/",
154
+ "Measure solar panels, car chargers and more.",
155
+ ),
156
+ Product(
157
+ "SDM630-wifi",
158
+ "Wi-Fi kWh Meter 3-phase",
159
+ "https://www.homewizard.com/kwh-meter/",
160
+ "Measure solar panels, car chargers and more.",
161
+ ),
162
+ Product(
163
+ "HWE-BAT",
164
+ "Plug-In Battery",
165
+ "https://www.homewizard.com/plug-in-battery/",
166
+ "Solar energy, day and night.",
167
+ ),
168
+ }
@@ -20,8 +20,9 @@ from homewizard_energy.errors import (
20
20
  UnsupportedError,
21
21
  )
22
22
 
23
+ from ..models import Device
23
24
  from .const import SUPPORTED_API_VERSION
24
- from .models import Data, Device, State, System
25
+ from .models import Data, State, System
25
26
 
26
27
  _LOGGER = logging.getLogger(__name__)
27
28
 
@@ -1,4 +1,4 @@
1
- """Models for HomeWizard Energy."""
1
+ """Models for HomeWizard Energy v1."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -8,39 +8,6 @@ from datetime import datetime
8
8
  from enum import Enum
9
9
  from typing import Any
10
10
 
11
- from homewizard_energy.brand import Product, from_type
12
-
13
-
14
- @dataclass
15
- class Device:
16
- """Represent Device config."""
17
-
18
- product: Product | None
19
- product_name: str | None
20
- product_type: str | None
21
- serial: str | None
22
- api_version: str | None
23
- firmware_version: str | None
24
-
25
- @staticmethod
26
- def from_dict(data: dict[str, str]) -> Device:
27
- """Return Device object from API response.
28
-
29
- Args:
30
- data: The data from the HomeWizard Energy `api` API.
31
-
32
- Returns:
33
- A Device object.
34
- """
35
- return Device(
36
- product=from_type(data.get("product_type")),
37
- product_name=data.get("product_name"),
38
- product_type=data.get("product_type"),
39
- serial=data.get("serial"),
40
- api_version=data.get("api_version"),
41
- firmware_version=data.get("firmware_version"),
42
- )
43
-
44
11
 
45
12
  @dataclass
46
13
  class Data:
@@ -27,8 +27,9 @@ from homewizard_energy.errors import (
27
27
  UnauthorizedError,
28
28
  )
29
29
 
30
+ from ..models import Device
30
31
  from .cacert import CACERT
31
- from .models import Device, Measurement, System, SystemUpdate
32
+ from .models import Measurement, System, SystemUpdate
32
33
 
33
34
  _LOGGER = logging.getLogger(__name__)
34
35
 
@@ -1,4 +1,4 @@
1
- """Models for HomeWizard Energy."""
1
+ """Models for HomeWizard Energy v2."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -7,39 +7,6 @@ from datetime import datetime
7
7
  from enum import Enum
8
8
  from typing import Any
9
9
 
10
- from homewizard_energy.brand import Product, from_type
11
-
12
-
13
- @dataclass
14
- class Device:
15
- """Represent Device config."""
16
-
17
- product: Product | None
18
- product_name: str | None
19
- product_type: str | None
20
- serial: str | None
21
- api_version: str | None
22
- firmware_version: str | None
23
-
24
- @staticmethod
25
- def from_dict(data: dict[str, str]) -> Device:
26
- """Return Device object from API response.
27
-
28
- Args:
29
- data: The data from the HomeWizard Energy `api` API.
30
-
31
- Returns:
32
- A Device object.
33
- """
34
- return Device(
35
- product=from_type(data.get("product_type")),
36
- product_name=data.get("product_name"),
37
- product_type=data.get("product_type"),
38
- serial=data.get("serial"),
39
- api_version=data.get("api_version"),
40
- firmware_version=data.get("firmware_version"),
41
- )
42
-
43
10
 
44
11
  @dataclass
45
12
  class Measurement:
@@ -78,6 +45,9 @@ class Measurement:
78
45
 
79
46
  frequency_hz: float | None
80
47
 
48
+ cycles: int | None
49
+ state_of_charge_pct: float | None
50
+
81
51
  voltage_sag_l1_count: int | None
82
52
  voltage_sag_l2_count: int | None
83
53
  voltage_sag_l3_count: int | None
@@ -183,6 +153,8 @@ class Measurement:
183
153
  current_l2_a=data.get("current_l2_a"),
184
154
  current_l3_a=data.get("current_l3_a"),
185
155
  frequency_hz=data.get("frequency_hz"),
156
+ cycles=data.get("cycles"),
157
+ state_of_charge_pct=data.get("state_of_charge_pct"),
186
158
  voltage_sag_l1_count=data.get("voltage_sag_l1_count"),
187
159
  voltage_sag_l2_count=data.get("voltage_sag_l2_count"),
188
160
  voltage_sag_l3_count=data.get("voltage_sag_l3_count"),
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-homewizard-energy"
3
- version = "7.0.0-beta-1"
3
+ version = "7.1.0-beta-2"
4
4
  description = "Asynchronous Python client for the HomeWizard Energy"
5
5
  authors = ["DCSBL"]
6
6
  maintainers = ["DCSBL"]
@@ -27,12 +27,12 @@ aresponses = "^3.0.0"
27
27
  flake8 = "^4.0.1"
28
28
  flake8-docstrings = "^1.7.0"
29
29
  isort = "^5.13.2"
30
- pre-commit = "^3.7.1"
31
- pre-commit-hooks = "^4.6.0"
32
- pylint = "^3.3.1"
30
+ pre-commit = "^4.0.1"
31
+ pre-commit-hooks = "^5.0.0"
32
+ pylint = "^3.3.3"
33
33
  pytest = "^8.3.3"
34
34
  pytest-asyncio = "^0.24.0"
35
- pytest-cov = "^5.0.0"
35
+ pytest-cov = "^6.0.0"
36
36
  yamllint = "^1.35.1"
37
37
  pyupgrade = "^3.19.0"
38
38
  flake8-simplify = "^0.21.0"
@@ -43,7 +43,7 @@ flake8-builtins = "^2.5.0"
43
43
  flake8-comprehensions = "^3.15.0"
44
44
  flake8-eradicate = "^1.2.1"
45
45
  flake8-markdown = "^0.3.0"
46
- ruff = "0.7.1"
46
+ ruff = "0.8.1"
47
47
  darglint = "^1.8.1"
48
48
  safety = "^3.2.10"
49
49
  codespell = "^2.3.0"
@@ -1,14 +0,0 @@
1
- """HomeWizard Energy API library."""
2
-
3
- from .errors import DisabledError, InvalidStateError, RequestError, UnsupportedError
4
- from .v1 import HomeWizardEnergyV1
5
- from .v2 import HomeWizardEnergyV2
6
-
7
- __all__ = [
8
- "DisabledError",
9
- "HomeWizardEnergyV1",
10
- "HomeWizardEnergyV2",
11
- "InvalidStateError",
12
- "RequestError",
13
- "UnsupportedError",
14
- ]
@@ -1,95 +0,0 @@
1
- """Brand specific information for HomeWizard Energy."""
2
-
3
- from __future__ import annotations
4
-
5
- from dataclasses import dataclass
6
-
7
-
8
- @dataclass(frozen=True)
9
- class Product:
10
- """Represent a product."""
11
-
12
- model: str
13
- name: str | None
14
- url: str | None
15
- description: str | None
16
-
17
- def __str__(self):
18
- """Return a string representation of the product."""
19
- return f"HomeWizard {self.name} - {self.model}"
20
-
21
- def __hash__(self):
22
- """Hash a product for unit-test snapshots."""
23
- return hash((self.model, self.name, self.url, self.description))
24
-
25
- def __eq__(self, other):
26
- """Compare two products."""
27
- if isinstance(other, Product):
28
- return (
29
- self.model == other.model
30
- and self.name == other.name
31
- and self.url == other.url
32
- and self.description == other.description
33
- )
34
- return False
35
-
36
-
37
- PRODUCTS = {
38
- Product(
39
- "HWE-P1",
40
- "Wi-Fi P1 Meter",
41
- "https://www.homewizard.com/p1-meter/",
42
- "The HomeWizard P1 Meter gives you detailed insight in your electricity-, gas consumption and solar surplus.",
43
- ),
44
- Product(
45
- "HWE-SKT",
46
- "Wi-Fi Energy Socket",
47
- "https://www.homewizard.com/energy-socket/",
48
- "Measure and switch every device.",
49
- ),
50
- Product(
51
- "HWE-WTR",
52
- "Wi-Fi Watermeter",
53
- "https://www.homewizard.com/watermeter/",
54
- "Real-time water consumption insights",
55
- ),
56
- Product(
57
- "HWE-KWH1",
58
- "Wi-Fi kWh Meter 1-phase",
59
- "https://www.homewizard.com/kwh-meter/",
60
- "Measure solar panels, car chargers and more.",
61
- ),
62
- Product(
63
- "HWE-KWH3",
64
- "Wi-Fi kWh Meter 3-phase",
65
- "https://www.homewizard.com/kwh-meter/",
66
- "Measure solar panels, car chargers and more.",
67
- ),
68
- Product(
69
- "SDM230-wifi",
70
- "Wi-Fi kWh Meter 1-phase",
71
- "https://www.homewizard.com/kwh-meter/",
72
- "Measure solar panels, car chargers and more.",
73
- ),
74
- Product(
75
- "SDM630-wifi",
76
- "Wi-Fi kWh Meter 3-phase",
77
- "https://www.homewizard.com/kwh-meter/",
78
- "Measure solar panels, car chargers and more.",
79
- ),
80
- }
81
-
82
-
83
- def from_type(product_type: str, _: str | None = None) -> Product | None:
84
- """Return a Product object from a type.
85
-
86
- :param type: The type of the product.
87
- :param locale: The locale to use for the description. Currently ignored. Should be an ISO 639-1 language code.
88
- """
89
-
90
- # pylint: disable=unused-argument
91
-
92
- for product in PRODUCTS:
93
- if product.model == product_type:
94
- return product
95
- return None