python-homewizard-energy 9.3.0__tar.gz → 10.0.1__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-9.3.0 → python_homewizard_energy-10.0.1}/PKG-INFO +5 -3
  2. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/README.md +1 -1
  3. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/homewizard_energy.py +1 -1
  4. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/models.py +121 -1
  5. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/v2/__init__.py +1 -3
  6. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/pyproject.toml +15 -15
  7. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/LICENSE +0 -0
  8. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/__init__.py +0 -0
  9. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/const.py +0 -0
  10. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/errors.py +0 -0
  11. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/py.typed +0 -0
  12. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/utils.py +0 -0
  13. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/v1/__init__.py +0 -0
  14. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/v1/const.py +0 -0
  15. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/v2/cacert.py +0 -0
  16. {python_homewizard_energy-9.3.0 → python_homewizard_energy-10.0.1}/homewizard_energy/v2/const.py +0 -0
@@ -1,8 +1,9 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: python-homewizard-energy
3
- Version: 9.3.0
3
+ Version: 10.0.1
4
4
  Summary: Asynchronous Python client for the HomeWizard Energy
5
5
  License: Apache-2.0
6
+ License-File: LICENSE
6
7
  Author: DCSBL
7
8
  Maintainer: DCSBL
8
9
  Requires-Python: >=3.12,<4.0
@@ -10,6 +11,7 @@ Classifier: License :: OSI Approved :: Apache Software License
10
11
  Classifier: Programming Language :: Python :: 3
11
12
  Classifier: Programming Language :: Python :: 3.12
12
13
  Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
13
15
  Requires-Dist: aiohttp (>=3.0.0)
14
16
  Requires-Dist: async-timeout (>=4.0.3,<6.0.0)
15
17
  Requires-Dist: awesomeversion (>=24.6.0)
@@ -83,7 +85,7 @@ asyncio.run(main())
83
85
  Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
84
86
 
85
87
  ## Requirements
86
- - Python 3.10 or higher
88
+ - Python 3.12 or higher
87
89
  - [Poetry](https://python-poetry.org/docs/#installing-with-pipx)
88
90
 
89
91
  ## Installation and setup
@@ -57,7 +57,7 @@ asyncio.run(main())
57
57
  Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
58
58
 
59
59
  ## Requirements
60
- - Python 3.10 or higher
60
+ - Python 3.12 or higher
61
61
  - [Poetry](https://python-poetry.org/docs/#installing-with-pipx)
62
62
 
63
63
  ## Installation and setup
@@ -137,7 +137,7 @@ class HomeWizardEnergy:
137
137
  LOGGER.debug("Creating clientsession")
138
138
 
139
139
  if self._session is not None:
140
- raise RuntimeError("Session already exists")
140
+ raise RuntimeError("Session already exists") # pragma: no cover
141
141
 
142
142
  connector = TCPConnector(
143
143
  enable_cleanup_closed=True,
@@ -186,6 +186,25 @@ class Device(BaseModel):
186
186
  Model.ENERGY_METER_EASTRON_SDM630,
187
187
  )
188
188
 
189
+ def supported_battery_modes(self) -> list[Batteries.Mode] | None:
190
+ """Return list of supported battery modes."""
191
+ if not self.supports_batteries():
192
+ return None
193
+
194
+ modes = [
195
+ Batteries.Mode.STANDBY,
196
+ Batteries.Mode.TO_FULL,
197
+ Batteries.Mode.ZERO,
198
+ ]
199
+
200
+ if self.api_version >= AwesomeVersion("2.2.0"):
201
+ modes += [
202
+ Batteries.Mode.ZERO_CHARGE_ONLY,
203
+ Batteries.Mode.ZERO_DISCHARGE_ONLY,
204
+ ]
205
+
206
+ return modes
207
+
189
208
 
190
209
  @dataclass(kw_only=True)
191
210
  class Measurement(BaseModel):
@@ -609,6 +628,49 @@ class BatteriesUpdate(UpdateBaseModel):
609
628
  """Represent Batteries update config."""
610
629
 
611
630
  mode: Batteries.Mode | None = field(default=None)
631
+ permissions: list[Batteries.Permissions] | None = field(default=None)
632
+
633
+ @staticmethod
634
+ def from_mode(
635
+ mode: Batteries.Mode,
636
+ ) -> BatteriesUpdate:
637
+ """Convert userfacing mode to API mode.
638
+
639
+ Args:
640
+ mode: Userfacing mode to convert.
641
+ Returns:
642
+ BatteriesUpdate object with API mode and permissions.
643
+ """
644
+
645
+ match mode:
646
+ case Batteries.Mode.ZERO:
647
+ return BatteriesUpdate(
648
+ mode=Batteries.Mode.ZERO,
649
+ permissions=[
650
+ Batteries.Permissions.CHARGE_ALLOWED,
651
+ Batteries.Permissions.DISCHARGE_ALLOWED,
652
+ ],
653
+ )
654
+ case Batteries.Mode.ZERO_CHARGE_ONLY:
655
+ return BatteriesUpdate(
656
+ mode=Batteries.Mode.ZERO,
657
+ permissions=[
658
+ Batteries.Permissions.CHARGE_ALLOWED,
659
+ ],
660
+ )
661
+ case Batteries.Mode.ZERO_DISCHARGE_ONLY:
662
+ return BatteriesUpdate(
663
+ mode=Batteries.Mode.ZERO,
664
+ permissions=[
665
+ Batteries.Permissions.DISCHARGE_ALLOWED,
666
+ ],
667
+ )
668
+ case Batteries.Mode.TO_FULL:
669
+ return BatteriesUpdate(mode=Batteries.Mode.TO_FULL)
670
+ case Batteries.Mode.STANDBY:
671
+ return BatteriesUpdate(mode=Batteries.Mode.STANDBY, permissions=[])
672
+
673
+ raise ValueError(f"Unsupported Batteries.Mode: {mode!r}")
612
674
 
613
675
 
614
676
  @dataclass(kw_only=True)
@@ -616,21 +678,79 @@ class Batteries(BaseModel):
616
678
  """Represent Batteries config."""
617
679
 
618
680
  class Mode(StrEnum):
619
- """Device type allocations."""
681
+ """Device type allocations.
682
+
683
+ This is the list of modes shown to the user. 'zero_charge_only' and 'zero_discharge_only' are
684
+ mapped to 'zero' in the API via the Permissions parameter
685
+ """
620
686
 
621
687
  ZERO = "zero"
622
688
  TO_FULL = "to_full"
623
689
  STANDBY = "standby"
690
+ ZERO_CHARGE_ONLY = "zero_charge_only"
691
+ ZERO_DISCHARGE_ONLY = "zero_discharge_only"
692
+
693
+ class Permissions(StrEnum):
694
+ """Device permission allocations."""
695
+
696
+ CHARGE_ALLOWED = "charge_allowed"
697
+ DISCHARGE_ALLOWED = "discharge_allowed"
624
698
 
625
699
  mode: Mode = field(
626
700
  metadata={
627
701
  "deserialize": lambda x: Batteries.Mode.__members__.get(x.upper(), None)
628
702
  },
629
703
  )
704
+ permissions: list[Permissions] | None = field(
705
+ default=None,
706
+ metadata={
707
+ "deserialize": lambda lst: [
708
+ perm
709
+ for item in lst
710
+ if (perm := Batteries.Permissions.__members__.get(item.upper(), None))
711
+ is not None
712
+ ]
713
+ if lst is not None
714
+ else None
715
+ },
716
+ )
630
717
  power_w: float = field()
631
718
  target_power_w: float = field()
632
719
  max_consumption_w: float = field()
633
720
  max_production_w: float = field()
721
+ battery_count: int | None = field(default=None)
722
+
723
+ @classmethod
724
+ def __post_deserialize__(cls, obj: Batteries) -> Batteries:
725
+ """Set correct mode based on permissions after deserialization.
726
+ If permissions is missing and mode is ZERO, keep mode as ZERO for backwards compatibility.
727
+ If permissions is present (even if empty), apply the mapping logic.
728
+ """
729
+ # Only adjust if mode is ZERO
730
+ if obj.mode != cls.Mode.ZERO:
731
+ return obj
732
+
733
+ # Detect if 'permissions' was present in the original data
734
+ # If using mashumaro, the original dict is not available here, so we infer:
735
+ # If permissions is None, treat as 'not provided'. If it's an empty list, treat as 'provided but empty'.
736
+ if obj.permissions is None:
737
+ # Permissions not provided, keep mode as ZERO (backwards compatibility)
738
+ return obj
739
+
740
+ perms = set(obj.permissions)
741
+ if perms == {cls.Permissions.CHARGE_ALLOWED}:
742
+ obj.mode = cls.Mode.ZERO_CHARGE_ONLY
743
+ elif perms == {cls.Permissions.DISCHARGE_ALLOWED}:
744
+ obj.mode = cls.Mode.ZERO_DISCHARGE_ONLY
745
+ elif perms == {
746
+ cls.Permissions.CHARGE_ALLOWED,
747
+ cls.Permissions.DISCHARGE_ALLOWED,
748
+ }:
749
+ obj.mode = cls.Mode.ZERO
750
+ elif perms == set():
751
+ obj.mode = cls.Mode.STANDBY
752
+
753
+ return obj
634
754
 
635
755
 
636
756
  @dataclass(kw_only=True)
@@ -159,9 +159,7 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
159
159
 
160
160
  try:
161
161
  if mode is not None:
162
- data = BatteriesUpdate(
163
- mode=mode,
164
- ).to_dict()
162
+ data = BatteriesUpdate.from_mode(mode).to_dict()
165
163
  status, response = await self._request(
166
164
  "/api/batteries", method=METH_PUT, data=data
167
165
  )
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-homewizard-energy"
3
- version = "9.3.0"
3
+ version = "10.0.1"
4
4
  description = "Asynchronous Python client for the HomeWizard Energy"
5
5
  authors = ["DCSBL"]
6
6
  maintainers = ["DCSBL"]
@@ -29,29 +29,29 @@ awesomeversion = ">=24.6.0"
29
29
  aresponses = "^3.0.0"
30
30
  flake8 = "^4.0.1"
31
31
  flake8-docstrings = "^1.7.0"
32
- isort = "^6.0.1"
33
- pre-commit = "^4.2.0"
34
- pre-commit-hooks = "^5.0.0"
35
- pylint = "^3.3.7"
36
- pytest = "^8.4.1"
37
- pytest-asyncio = "^1.1.0"
38
- pytest-cov = "^6.2.1"
32
+ isort = "^6.1.0"
33
+ pre-commit = "^4.5.0"
34
+ pre-commit-hooks = "^6.0.0"
35
+ pylint = "^4.0.4"
36
+ pytest = "^8.4.2"
37
+ pytest-asyncio = "^1.3.0"
38
+ pytest-cov = "^7.0.0"
39
39
  yamllint = "^1.37.1"
40
- pyupgrade = "^3.20.0"
40
+ pyupgrade = "^3.21.2"
41
41
  flake8-simplify = "^0.22.0"
42
42
  vulture = "^2.13"
43
43
  flake8-bandit = "^3.0.0"
44
44
  flake8-bugbear = "^23.3.12"
45
- flake8-builtins = "^2.5.0"
46
- flake8-comprehensions = "^3.15.0"
45
+ flake8-builtins = "^3.1.0"
46
+ flake8-comprehensions = "^3.17.0"
47
47
  flake8-eradicate = "^1.2.1"
48
48
  flake8-markdown = "^0.3.0"
49
- ruff = "0.12.7"
49
+ ruff = "0.14.7"
50
50
  darglint = "^1.8.1"
51
- safety = "^3.6.0"
51
+ safety = "^3.7.0"
52
52
  codespell = "^2.4.1"
53
- bandit = "^1.8.6"
54
- syrupy = "^4.9.1"
53
+ bandit = "^1.9.2"
54
+ syrupy = "^5.0.0"
55
55
 
56
56
  [tool.poetry.urls]
57
57
  "Bug Tracker" = "https://github.com/homewizard/python-homewizard-energy/issues"