python-homewizard-energy 10.0.0b2__tar.gz → 10.1.0__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 (16) hide show
  1. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/PKG-INFO +1 -2
  2. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/models.py +37 -16
  3. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/v1/__init__.py +2 -3
  4. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/v2/__init__.py +2 -3
  5. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/pyproject.toml +2 -3
  6. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/LICENSE +0 -0
  7. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/README.md +0 -0
  8. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/__init__.py +0 -0
  9. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/const.py +0 -0
  10. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/errors.py +0 -0
  11. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/homewizard_energy.py +0 -0
  12. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/py.typed +0 -0
  13. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/utils.py +0 -0
  14. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/v1/const.py +0 -0
  15. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/v2/cacert.py +0 -0
  16. {python_homewizard_energy-10.0.0b2 → python_homewizard_energy-10.1.0}/homewizard_energy/v2/const.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-homewizard-energy
3
- Version: 10.0.0b2
3
+ Version: 10.1.0
4
4
  Summary: Asynchronous Python client for the HomeWizard Energy
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -13,7 +13,6 @@ Classifier: Programming Language :: Python :: 3.12
13
13
  Classifier: Programming Language :: Python :: 3.13
14
14
  Classifier: Programming Language :: Python :: 3.14
15
15
  Requires-Dist: aiohttp (>=3.0.0)
16
- Requires-Dist: async-timeout (>=4.0.3,<6.0.0)
17
16
  Requires-Dist: awesomeversion (>=24.6.0)
18
17
  Requires-Dist: backoff (>=2.2.1,<3.0.0)
19
18
  Requires-Dist: mashumaro (>=3.15,<4.0)
@@ -203,6 +203,9 @@ class Device(BaseModel):
203
203
  Batteries.Mode.ZERO_DISCHARGE_ONLY,
204
204
  ]
205
205
 
206
+ if self.api_version >= AwesomeVersion("2.3.0"):
207
+ modes += [Batteries.Mode.PREDICTIVE]
208
+
206
209
  return modes
207
210
 
208
211
 
@@ -667,6 +670,8 @@ class BatteriesUpdate(UpdateBaseModel):
667
670
  )
668
671
  case Batteries.Mode.TO_FULL:
669
672
  return BatteriesUpdate(mode=Batteries.Mode.TO_FULL)
673
+ case Batteries.Mode.PREDICTIVE:
674
+ return BatteriesUpdate(mode=Batteries.Mode.PREDICTIVE)
670
675
  case Batteries.Mode.STANDBY:
671
676
  return BatteriesUpdate(mode=Batteries.Mode.STANDBY, permissions=[])
672
677
 
@@ -686,6 +691,7 @@ class Batteries(BaseModel):
686
691
 
687
692
  ZERO = "zero"
688
693
  TO_FULL = "to_full"
694
+ PREDICTIVE = "predictive"
689
695
  STANDBY = "standby"
690
696
  ZERO_CHARGE_ONLY = "zero_charge_only"
691
697
  ZERO_DISCHARGE_ONLY = "zero_discharge_only"
@@ -701,8 +707,8 @@ class Batteries(BaseModel):
701
707
  "deserialize": lambda x: Batteries.Mode.__members__.get(x.upper(), None)
702
708
  },
703
709
  )
704
- permissions: list[Permissions] = field(
705
- default_factory=list,
710
+ permissions: list[Permissions] | None = field(
711
+ default=None,
706
712
  metadata={
707
713
  "deserialize": lambda lst: [
708
714
  perm
@@ -710,6 +716,8 @@ class Batteries(BaseModel):
710
716
  if (perm := Batteries.Permissions.__members__.get(item.upper(), None))
711
717
  is not None
712
718
  ]
719
+ if lst is not None
720
+ else None
713
721
  },
714
722
  )
715
723
  power_w: float = field()
@@ -720,21 +728,34 @@ class Batteries(BaseModel):
720
728
 
721
729
  @classmethod
722
730
  def __post_deserialize__(cls, obj: Batteries) -> Batteries:
723
- """Set correct mode based on permissions after deserialization."""
731
+ """Set correct mode based on permissions after deserialization.
732
+ If permissions is missing and mode is ZERO, keep mode as ZERO for backwards compatibility.
733
+ If permissions is present (even if empty), apply the mapping logic.
734
+ """
724
735
  # Only adjust if mode is ZERO
725
- if obj.mode == cls.Mode.ZERO:
726
- perms = set(obj.permissions)
727
- if perms == {cls.Permissions.CHARGE_ALLOWED}:
728
- obj.mode = cls.Mode.ZERO_CHARGE_ONLY
729
- elif perms == {cls.Permissions.DISCHARGE_ALLOWED}:
730
- obj.mode = cls.Mode.ZERO_DISCHARGE_ONLY
731
- elif perms == {
732
- cls.Permissions.CHARGE_ALLOWED,
733
- cls.Permissions.DISCHARGE_ALLOWED,
734
- }:
735
- obj.mode = cls.Mode.ZERO
736
- elif perms == set():
737
- obj.mode = cls.Mode.STANDBY
736
+ if obj.mode != cls.Mode.ZERO:
737
+ return obj
738
+
739
+ # Detect if 'permissions' was present in the original data
740
+ # If using mashumaro, the original dict is not available here, so we infer:
741
+ # If permissions is None, treat as 'not provided'. If it's an empty list, treat as 'provided but empty'.
742
+ if obj.permissions is None:
743
+ # Permissions not provided, keep mode as ZERO (backwards compatibility)
744
+ return obj
745
+
746
+ perms = set(obj.permissions)
747
+ if perms == {cls.Permissions.CHARGE_ALLOWED}:
748
+ obj.mode = cls.Mode.ZERO_CHARGE_ONLY
749
+ elif perms == {cls.Permissions.DISCHARGE_ALLOWED}:
750
+ obj.mode = cls.Mode.ZERO_DISCHARGE_ONLY
751
+ elif perms == {
752
+ cls.Permissions.CHARGE_ALLOWED,
753
+ cls.Permissions.DISCHARGE_ALLOWED,
754
+ }:
755
+ obj.mode = cls.Mode.ZERO
756
+ elif perms == set():
757
+ obj.mode = cls.Mode.STANDBY
758
+
738
759
  return obj
739
760
 
740
761
 
@@ -7,7 +7,6 @@ from collections.abc import Callable, Coroutine
7
7
  from http import HTTPStatus
8
8
  from typing import Any, TypeVar
9
9
 
10
- import async_timeout
11
10
  import backoff
12
11
  from aiohttp.client import ClientError, ClientResponseError
13
12
  from aiohttp.hdrs import METH_GET, METH_PUT
@@ -153,7 +152,7 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
153
152
  LOGGER.debug("%s, %s, %s", method, url, data)
154
153
 
155
154
  try:
156
- async with async_timeout.timeout(self._request_timeout):
155
+ async with asyncio.timeout(self._request_timeout):
157
156
  resp = await self._session.request(
158
157
  method,
159
158
  url,
@@ -161,7 +160,7 @@ class HomeWizardEnergyV1(HomeWizardEnergy):
161
160
  headers=headers,
162
161
  )
163
162
  LOGGER.debug("%s, %s", resp.status, await resp.text("utf-8"))
164
- except asyncio.TimeoutError as exception:
163
+ except TimeoutError as exception:
165
164
  raise RequestError(
166
165
  f"Timeout occurred while connecting to the HomeWizard Energy device at {self.host}"
167
166
  ) from exception
@@ -9,7 +9,6 @@ from collections.abc import Callable, Coroutine
9
9
  from http import HTTPStatus
10
10
  from typing import Any, TypeVar
11
11
 
12
- import async_timeout
13
12
  import backoff
14
13
  from aiohttp.client import ClientError, ClientResponseError, ClientSession
15
14
  from aiohttp.hdrs import METH_DELETE, METH_GET, METH_POST, METH_PUT
@@ -287,7 +286,7 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
287
286
  LOGGER.debug("%s, %s, %s", method, url, data)
288
287
 
289
288
  try:
290
- async with async_timeout.timeout(self._request_timeout):
289
+ async with asyncio.timeout(self._request_timeout):
291
290
  async with self._lock:
292
291
  resp = await self._session.request(
293
292
  method,
@@ -298,7 +297,7 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
298
297
  server_hostname=self._identifier,
299
298
  )
300
299
  LOGGER.debug("%s, %s", resp.status, await resp.text("utf-8"))
301
- except asyncio.TimeoutError as exception:
300
+ except TimeoutError as exception:
302
301
  raise RequestError(
303
302
  f"Timeout occurred while connecting to the HomeWizard Energy device at {self.host}"
304
303
  ) from exception
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-homewizard-energy"
3
- version = "10.0.0-beta-2"
3
+ version = "10.1.0"
4
4
  description = "Asynchronous Python client for the HomeWizard Energy"
5
5
  authors = ["DCSBL"]
6
6
  maintainers = ["DCSBL"]
@@ -18,7 +18,6 @@ packages = [
18
18
  [tool.poetry.dependencies]
19
19
  python = "^3.12"
20
20
  aiohttp = ">=3.0.0"
21
- async-timeout = ">=4.0.3,<6.0.0"
22
21
  multidict = "^6.0.5" ## To fix aiohttp dependency at python 3.12
23
22
  backoff = "^2.2.1"
24
23
  orjson = "^3.10"
@@ -33,7 +32,7 @@ isort = "^6.1.0"
33
32
  pre-commit = "^4.5.0"
34
33
  pre-commit-hooks = "^6.0.0"
35
34
  pylint = "^4.0.4"
36
- pytest = "^8.4.2"
35
+ pytest = "^9.0.3"
37
36
  pytest-asyncio = "^1.3.0"
38
37
  pytest-cov = "^7.0.0"
39
38
  yamllint = "^1.37.1"