PyViCare 2.64.0__tar.gz → 2.66.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 (38) hide show
  1. {pyvicare-2.64.0 → pyvicare-2.66.0}/PKG-INFO +23 -6
  2. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareAbstractOAuthManager.py +1 -0
  3. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareCachedServiceBase.py +9 -2
  4. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareDevice.py +54 -0
  5. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareElectricalEnergySystem.py +67 -1
  6. pyvicare-2.66.0/PyViCare/PyViCareEvent.py +105 -0
  7. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareFuelCell.py +32 -4
  8. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareHeatPump.py +87 -2
  9. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareHeatingDevice.py +312 -18
  10. pyvicare-2.66.0/PyViCare/PyViCareService.py +192 -0
  11. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareVentilationDevice.py +28 -0
  12. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareWaterTreatment.py +8 -0
  13. {pyvicare-2.64.0 → pyvicare-2.66.0}/README.md +21 -5
  14. {pyvicare-2.64.0 → pyvicare-2.66.0}/pyproject.toml +4 -3
  15. pyvicare-2.64.0/PyViCare/PyViCareService.py +0 -75
  16. {pyvicare-2.64.0 → pyvicare-2.66.0}/.gitignore +0 -0
  17. {pyvicare-2.64.0 → pyvicare-2.66.0}/LICENSE +0 -0
  18. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/Feature.py +0 -0
  19. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCare.py +0 -0
  20. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareBrowserOAuthManager.py +0 -0
  21. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareCachedService.py +0 -0
  22. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareCachedServiceViaGateway.py +0 -0
  23. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareDeviceConfig.py +0 -0
  24. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareFloorHeating.py +0 -0
  25. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareGateway.py +0 -0
  26. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareGazBoiler.py +0 -0
  27. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareHeatCurveCalculation.py +0 -0
  28. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareHybrid.py +0 -0
  29. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareOAuthManager.py +0 -0
  30. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareOilBoiler.py +0 -0
  31. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCarePelletsBoiler.py +0 -0
  32. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareRadiatorActuator.py +0 -0
  33. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareRepeater.py +0 -0
  34. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareRoomControl.py +0 -0
  35. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareRoomSensor.py +0 -0
  36. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareServiceViaGateway.py +0 -0
  37. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/PyViCareUtils.py +0 -0
  38. {pyvicare-2.64.0 → pyvicare-2.66.0}/PyViCare/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: PyViCare
3
- Version: 2.64.0
3
+ Version: 2.66.0
4
4
  Summary: Library to communicate with the Viessmann ViCare API.
5
5
  Project-URL: Homepage, https://github.com/openviess/PyViCare
6
6
  Project-URL: Repository, https://github.com/openviess/PyViCare
@@ -22,6 +22,7 @@ Classifier: Programming Language :: Python :: 3.11
22
22
  Classifier: Programming Language :: Python :: 3.12
23
23
  Classifier: Programming Language :: Python :: 3.13
24
24
  Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Programming Language :: Python :: 3.15
25
26
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
27
  Requires-Python: >=3.11
27
28
  Requires-Dist: authlib>1.2.0
@@ -80,6 +81,23 @@ Depending on the device, some features are not available/supported. This results
80
81
 
81
82
  Tip: You can use Pythons [contextlib.suppress](https://docs.python.org/3/library/contextlib.html#contextlib.suppress) to handle it gracefully.
82
83
 
84
+ ### Error events
85
+
86
+ `getDeviceErrors()` reads a feature that some gateways do not offer. The event
87
+ history keeps those errors, including the ones that already cleared:
88
+
89
+ ```python
90
+ for event in device.getErrorEvents(limit=10):
91
+ state = "active" if event.active else "cleared"
92
+ print(event.event_timestamp, state, event.error_code, event.error_description)
93
+ ```
94
+
95
+ `active=True` is the raise, `active=False` the clear, so the event of an error
96
+ code with the latest `event_timestamp` is its current state. `getErrorEvents()`
97
+ asks the API for its gateway serial and filters the page by device id, so
98
+ `limit` counts that gateway's events. Paging and other event types are on
99
+ `device.service.fetch_events()`.
100
+
83
101
  ## Types of heatings
84
102
 
85
103
  - Use `asGazBoiler` for gas heatings
@@ -123,13 +141,12 @@ print(circuit.getHeatingCurveSlope())
123
141
  print(circuit.getActiveProgram())
124
142
  print(circuit.getPrograms())
125
143
 
126
- print(circuit.getCurrentDesiredTemperature())
127
- print(circuit.getDesiredTemperatureForProgram("comfort"))
144
+ print(circuit.getActiveProgramTemperature())
145
+ print(circuit.getComfortTemperature())
128
146
  print(circuit.getActiveMode())
129
147
 
130
- print(circuit.getDesiredTemperatureForProgram("comfort"))
131
- print(circuit.setProgramTemperature("comfort",21))
132
- print(circuit.activateProgram("comfort"))
148
+ print(circuit.setComfortTemperature(21))
149
+ print(circuit.activateComfort())
133
150
  print(circuit.deactivateComfort())
134
151
 
135
152
  burner = t.burners[0] #select burner
@@ -136,6 +136,7 @@ class AbstractViCareOAuthManager:
136
136
  f"{API_BASE_URL}{url}", data, headers=headers)
137
137
  self.__raise_on_non_json_error(raw_response)
138
138
  response = raw_response.json()
139
+ logger.debug("Response to post request: %s", response)
139
140
  self.__handle_expired_token(response)
140
141
  self.__handle_rate_limit(response)
141
142
  self.__handle_command_error(response)
@@ -30,6 +30,11 @@ class ViCareCachedServiceBase(ViCareService):
30
30
  self._cacheTime: datetime | None = None
31
31
  self._cacheError: Exception | None = None
32
32
  self._cacheLock = threading.Lock()
33
+ self._lastFetchTime: datetime | None = None
34
+
35
+ @property
36
+ def cache_time(self):
37
+ return self._cacheTime
33
38
 
34
39
  def getProperty(self, accessor: ViCareDeviceAccessor, property_name: str) -> Any:
35
40
  data = self._get_or_update_cache(accessor)
@@ -53,7 +58,7 @@ class ViCareCachedServiceBase(ViCareService):
53
58
  # to avoid consuming all the api calls if the api is down
54
59
  # see https://github.com/home-assistant/core/issues/67052
55
60
  # we simply return the old cache in this case
56
- self._cacheTime = ViCareTimer().now()
61
+ self._lastFetchTime = ViCareTimer().now()
57
62
  self._cacheError = None
58
63
 
59
64
  try:
@@ -78,6 +83,7 @@ class ViCareCachedServiceBase(ViCareService):
78
83
  raise
79
84
 
80
85
  self._cache = data
86
+ self._cacheTime = self._lastFetchTime
81
87
  elif self._cache is None and self._cacheError is not None:
82
88
  # The fetch that opened this window failed and left nothing to
83
89
  # read. Replaying its error keeps every other reader from
@@ -87,13 +93,14 @@ class ViCareCachedServiceBase(ViCareService):
87
93
  return self._cache
88
94
 
89
95
  def is_cache_invalid(self) -> bool:
90
- return self._cacheTime is None or (ViCareTimer().now() - self._cacheTime).seconds > self._cacheDuration
96
+ return self._lastFetchTime is None or (ViCareTimer().now() - self._lastFetchTime).seconds > self._cacheDuration
91
97
 
92
98
  def clear_cache(self):
93
99
  with self._cacheLock:
94
100
  self._cache = None
95
101
  self._cacheTime = None
96
102
  self._cacheError = None
103
+ self._lastFetchTime = None
97
104
 
98
105
  def _fetch_uncached(self, accessor: ViCareDeviceAccessor) -> Any:
99
106
  raise NotImplementedError
@@ -1,5 +1,7 @@
1
+ from datetime import date, datetime
1
2
  from typing import Any
2
3
 
4
+ from PyViCare.PyViCareEvent import EVENT_TYPE_DEVICE_ERROR, ViCareEvent
3
5
  from PyViCare.PyViCareService import ViCareDeviceAccessor, ViCareService, hasRoles
4
6
  from PyViCare.PyViCareUtils import (
5
7
  PyViCareNotSupportedFeatureError,
@@ -34,6 +36,58 @@ class Device:
34
36
  def getDeviceErrors(self) -> list[Any]:
35
37
  return list[Any](self.getProperty("device.messages.errors.raw")["properties"]["entries"]["value"])
36
38
 
39
+ # Power consumption limitation (§14a EnWG):
40
+ @handleNotSupported
41
+ def getPowerConsumptionLimit(self) -> int:
42
+ return int(self.getProperty("device.power.statusReport.consumption")["properties"]["limit"]["value"])
43
+
44
+ @handleNotSupported
45
+ def getPowerConsumptionLimitUnit(self) -> str:
46
+ return str(self.getProperty("device.power.statusReport.consumption")["properties"]["limit"]["unit"])
47
+
48
+ @handleNotSupported
49
+ def getPowerConsumptionLimitStatus(self) -> str:
50
+ return str(self.getProperty("device.power.statusReport.consumption")["properties"]["status"]["value"])
51
+
52
+ @handleNotSupported
53
+ def getPowerConsumptionLimitationSource(self) -> str:
54
+ return str(self.getProperty("device.power.consumption.limitation")["properties"]["value"]["value"])
55
+
56
+ # Power production limitation (feed-in):
57
+ @handleNotSupported
58
+ def getPowerProductionLimit(self) -> int:
59
+ return int(self.getProperty("device.power.statusReport.production")["properties"]["limit"]["value"])
60
+
61
+ @handleNotSupported
62
+ def getPowerProductionLimitUnit(self) -> str:
63
+ return str(self.getProperty("device.power.statusReport.production")["properties"]["limit"]["unit"])
64
+
65
+ @handleNotSupported
66
+ def getPowerProductionLimitStatus(self) -> str:
67
+ return str(self.getProperty("device.power.statusReport.production")["properties"]["status"]["value"])
68
+
69
+ def getErrorEvents(self,
70
+ *,
71
+ last_days: int | None = None,
72
+ since: datetime | None = None,
73
+ on_date: date | None = None,
74
+ limit: int | None = 10) -> list[ViCareEvent]:
75
+ """Device errors of this device, in the order the API returns them.
76
+
77
+ The API is asked for this gateway (`gatewaySerials`) and the page is
78
+ then filtered by device id, so `limit` counts this gateway's events.
79
+
80
+ An error comes as two events: `active` is True when it was raised and
81
+ False when it was cleared. For paging and other event types use
82
+ `service.fetch_events()`.
83
+ """
84
+ page = self.service.fetch_events(
85
+ self.accessor, EVENT_TYPE_DEVICE_ERROR,
86
+ last_days=last_days, since=since, on_date=on_date,
87
+ gateway_serials=self.accessor.serial, limit=limit)
88
+ return [event for event in page.events
89
+ if event.device_id == self.accessor.device_id]
90
+
37
91
  def isLegacyDevice(self) -> bool:
38
92
  return hasRoles(["type:legacy"], self.roles)
39
93
 
@@ -1,5 +1,5 @@
1
1
  from PyViCare.PyViCareDevice import Device
2
- from PyViCare.PyViCareUtils import handleNotSupported
2
+ from PyViCare.PyViCareUtils import handleAPICommandErrors, handleNotSupported
3
3
 
4
4
 
5
5
  class ElectricalEnergySystem(Device):
@@ -52,6 +52,54 @@ class ElectricalEnergySystem(Device):
52
52
  "value"
53
53
  ]
54
54
 
55
+ @handleNotSupported
56
+ def getPhotovoltaicInstalledPeakPower(self):
57
+ return self.getProperty("photovoltaic.installedPeakPower")["properties"][
58
+ "value"
59
+ ]["value"]
60
+
61
+ @handleNotSupported
62
+ def getPhotovoltaicInstalledPeakPowerUnit(self):
63
+ return self.getProperty("photovoltaic.installedPeakPower")["properties"][
64
+ "value"
65
+ ]["unit"]
66
+
67
+ @handleNotSupported
68
+ def getPhotovoltaicStrings(self):
69
+ return self.getProperty("photovoltaic.string")["properties"]["enabled"][
70
+ "value"
71
+ ]
72
+
73
+ @handleNotSupported
74
+ def getPhotovoltaicStringName(self, string):
75
+ return self.getProperty(f"photovoltaic.string.{string}")["properties"][
76
+ "name"
77
+ ]["value"]
78
+
79
+ @handleNotSupported
80
+ def getPhotovoltaicStringPower(self, string):
81
+ return self.getProperty(f"photovoltaic.string.{string}.power")["properties"][
82
+ "value"
83
+ ]["value"]
84
+
85
+ @handleNotSupported
86
+ def getPhotovoltaicStringPowerUnit(self, string):
87
+ return self.getProperty(f"photovoltaic.string.{string}.power")["properties"][
88
+ "value"
89
+ ]["unit"]
90
+
91
+ @handleNotSupported
92
+ def getPhotovoltaicStringVoltage(self, string):
93
+ return self.getProperty(f"photovoltaic.string.{string}.voltage")["properties"][
94
+ "value"
95
+ ]["value"]
96
+
97
+ @handleNotSupported
98
+ def getPhotovoltaicStringCurrent(self, string):
99
+ return self.getProperty(f"photovoltaic.string.{string}.electricity")[
100
+ "properties"
101
+ ]["value"]["value"]
102
+
55
103
  @handleNotSupported
56
104
  def getPhotovoltaicProductionCurrent(self):
57
105
  return self.getProperty("photovoltaic.production.current")[
@@ -185,3 +233,21 @@ class ElectricalEnergySystem(Device):
185
233
  return self.getProperty("ess.operationState")["properties"]["value"][
186
234
  "value"
187
235
  ]
236
+
237
+ @handleNotSupported
238
+ def getElectricalEnergySystemBatteryControlMode(self):
239
+ return self.getProperty("ess.battery.control.mode.active")["properties"][
240
+ "value"
241
+ ]["value"]
242
+
243
+ @handleNotSupported
244
+ def getElectricalEnergySystemBatteryControlModes(self):
245
+ return self.getProperty("ess.battery.control.mode.active")["commands"][
246
+ "setMode"
247
+ ]["params"]["value"]["constraints"]["enum"]
248
+
249
+ @handleAPICommandErrors
250
+ def setElectricalEnergySystemBatteryControlMode(self, mode: str):
251
+ return self.setProperty(
252
+ "ess.battery.control.mode.active", "setMode", {"value": mode}
253
+ )
@@ -0,0 +1,105 @@
1
+ """Events from the Viessmann event history.
2
+
3
+ The event history keeps past device errors. The ``device.messages.errors.raw``
4
+ feature is missing on some gateways, and ``heating.burners.0.errorStatus`` only
5
+ holds the current value.
6
+
7
+ A device error appears as two events: one with ``active`` set to True when the
8
+ fault was raised, one with ``active`` set to False when it was cleared. The
9
+ newest event of an error code tells you whether that error still stands.
10
+ """
11
+
12
+ from datetime import datetime
13
+ from typing import Any
14
+
15
+ EVENT_TYPE_DEVICE_ERROR = "device-error"
16
+
17
+ # Event types of the EventHistory-v2 service (from its OpenAPI document):
18
+ #
19
+ # gateway scoped, selected with the gatewaySerials parameter:
20
+ # device-error, device-message-info, device-message-service,
21
+ # device-message-status, device-message-warning, feature-changed,
22
+ # firmware-update-status, gateway-online, gateway-reset-command,
23
+ # device-bmu-serial-changed, device-boiler-serial-changed,
24
+ # src-status-changed, remote-diagnose-session-opened,
25
+ # remote-diagnose-session-closed
26
+ # installation scoped:
27
+ # installation-address-changed, invitation-accepted,
28
+ # invitation-terminated, geofencing-activation-changed,
29
+ # diy-heating-rod-run-too-long, diy-heating-curve-not-optimal,
30
+ # diy-dhw-schedule-not-optimal, dynamic-smart-tip,
31
+ # snapshot-restore-status-changed
32
+ #
33
+ # The API does not validate the value: an unknown type returns an empty list
34
+ # instead of an error, and names are matched exactly. Several values can be
35
+ # combined with commas, the API ORs them.
36
+
37
+
38
+ def _as_dict(value: Any) -> dict[str, Any]:
39
+ return value if isinstance(value, dict) else {}
40
+
41
+
42
+ def _as_str(value: Any) -> str | None:
43
+ return value if isinstance(value, str) else None
44
+
45
+
46
+ def _as_bool(value: Any) -> bool:
47
+ return value is True
48
+
49
+
50
+ def _as_datetime(value: Any) -> datetime | None:
51
+ if not isinstance(value, str):
52
+ return None
53
+
54
+ try:
55
+ return datetime.fromisoformat(value)
56
+ except ValueError:
57
+ return None
58
+
59
+
60
+ class ViCareEvent:
61
+ """One entry of the event history."""
62
+
63
+ # pylint: disable=too-many-instance-attributes
64
+ def __init__(self, raw: dict[str, Any]) -> None:
65
+ body = _as_dict(raw.get("body"))
66
+
67
+ self.raw = raw
68
+ self.event_type = _as_str(raw.get("eventType")) or ""
69
+ self.gateway_serial = _as_str(raw.get("gatewaySerial"))
70
+ self.device_id = _as_str(body.get("deviceId"))
71
+ self.error_code = _as_str(body.get("errorCode"))
72
+ self.error_description = _as_str(body.get("errorDescription"))
73
+ self.error_event_type = _as_str(body.get("errorEventType"))
74
+ self.equipment_type = _as_str(body.get("equipmentType"))
75
+ self.model_id = _as_str(body.get("modelId"))
76
+ self.active = _as_bool(body.get("active"))
77
+ self.event_timestamp = _as_datetime(raw.get("eventTimestamp"))
78
+ self.created_at = _as_datetime(raw.get("createdAt"))
79
+ self.origin = _as_str(raw.get("origin"))
80
+
81
+ def __repr__(self) -> str:
82
+ return (
83
+ f"ViCareEvent({self.event_type}, error={self.error_code}, "
84
+ f"active={self.active}, at={self.event_timestamp})"
85
+ )
86
+
87
+
88
+ class ViCareEventPage:
89
+ """One page of the event history, with the cursor for the next page."""
90
+
91
+ def __init__(self, events: list[ViCareEvent], next_cursor: str | None, raw: dict[str, Any]) -> None:
92
+ self.events = events
93
+ self.next_cursor = next_cursor
94
+ self.raw = raw
95
+
96
+ @classmethod
97
+ def from_payload(cls, payload: dict[str, Any]) -> "ViCareEventPage":
98
+ data = payload.get("data")
99
+ entries = data if isinstance(data, list) else []
100
+ events = [ViCareEvent(entry) for entry in entries if isinstance(entry, dict)]
101
+ cursor = _as_str(_as_dict(payload.get("cursor")).get("next")) or None
102
+ return cls(events, cursor, payload)
103
+
104
+ def __repr__(self) -> str:
105
+ return f"ViCareEventPage({len(self.events)} events, next={self.next_cursor!r})"
@@ -165,10 +165,6 @@ class FuelCell(HeatingDevice):
165
165
  def getDomesticHotWaterMinTemperatureLevel(self):
166
166
  return self.getProperty("heating.dhw.temperature.levels")["properties"]["min"]["value"]
167
167
 
168
- @handleNotSupported
169
- def getHydraulicSeparatorTemperature(self):
170
- return self.getProperty("heating.sensors.temperature.hydraulicSeparator")["properties"]["value"]["value"]
171
-
172
168
  # ---- Actual FuelCell-relevant methods (they require paid "Advanced" API plan):
173
169
 
174
170
  @handleNotSupported
@@ -298,6 +294,38 @@ class FuelCell(HeatingDevice):
298
294
  # Returns flow supply temperature at the fuel cell as float
299
295
  return float(self.getProperty("fuelCell.sensors.temperature.supply")["properties"]["value"]["value"])
300
296
 
297
+ @handleNotSupported
298
+ def getFuelCellPredictedPowerConsumptionUnit(self) -> str:
299
+ return str(self.getProperty("fuelCell.managers.energy.prediction.power.consumption")["properties"]["value"]["unit"])
300
+
301
+ @handleNotSupported
302
+ def getFuelCellPredictedPowerConsumption(self) -> float:
303
+ return float(self.getProperty("fuelCell.managers.energy.prediction.power.consumption")["properties"]["value"]["value"])
304
+
305
+ @handleNotSupported
306
+ def getFuelCellPredictedRuntimeUnit(self) -> str:
307
+ return str(self.getProperty("fuelCell.managers.energy.prediction.runtime")["properties"]["value"]["unit"])
308
+
309
+ @handleNotSupported
310
+ def getFuelCellPredictedRuntime(self) -> float:
311
+ return float(self.getProperty("fuelCell.managers.energy.prediction.runtime")["properties"]["value"]["value"])
312
+
313
+ @handleNotSupported
314
+ def getFuelCellTimeTillNextStartUnit(self) -> str:
315
+ return str(self.getProperty("fuelCell.managers.energy.timeTillNextStart")["properties"]["value"]["unit"])
316
+
317
+ @handleNotSupported
318
+ def getFuelCellTimeTillNextStart(self) -> float:
319
+ return float(self.getProperty("fuelCell.managers.energy.timeTillNextStart")["properties"]["value"]["value"])
320
+
321
+ @handleNotSupported
322
+ def getFuelCellPredictedHeatingDeficitUnit(self) -> str:
323
+ return str(self.getProperty("fuelCell.prediction.heating.deficit")["properties"]["value"]["unit"])
324
+
325
+ @handleNotSupported
326
+ def getFuelCellPredictedHeatingDeficit(self) -> float:
327
+ return float(self.getProperty("fuelCell.prediction.heating.deficit")["properties"]["value"]["value"])
328
+
301
329
  @handleNotSupported
302
330
  def getFuelCellOperationHours(self) -> int:
303
331
  # Returns the operation hours of the fuel cell
@@ -1,6 +1,8 @@
1
+ # pylint: disable=too-many-lines
1
2
  from __future__ import annotations
2
3
 
3
4
  from contextlib import suppress
5
+ from itertools import count
4
6
  from typing import Any
5
7
 
6
8
  from deprecated import deprecated
@@ -48,6 +50,26 @@ class HeatPump(HeatingDevice, VentilationDevice):
48
50
  def getInverter(self, inverter) -> Inverter:
49
51
  return Inverter(self, inverter)
50
52
 
53
+ @property
54
+ def fans(self) -> list[Fan]:
55
+ return [self.getFan(x) for x in self.getAvailableFans()]
56
+
57
+ def getFan(self, fan: str) -> Fan:
58
+ return Fan(self, fan)
59
+
60
+ @handleNotSupported
61
+ def getAvailableFans(self) -> list[str]:
62
+ fan_count = 0
63
+ for fan in count():
64
+ try:
65
+ self.getProperty(f"heating.primaryCircuit.fans.{fan}.current")
66
+ fan_count += 1
67
+ except PyViCareNotSupportedFeatureError:
68
+ break
69
+ if fan_count == 0:
70
+ raise PyViCareNotSupportedFeatureError("heating.primaryCircuit.fans.0.current")
71
+ return [str(x) for x in range(fan_count)]
72
+
51
73
  @handleNotSupported
52
74
  def getBufferMainTemperature(self):
53
75
  return self.getProperty("heating.bufferCylinder.sensors.temperature.main")["properties"]["value"]["value"]
@@ -182,6 +204,51 @@ class HeatPump(HeatingDevice, VentilationDevice):
182
204
  def getPowerSummaryConsumptionDomesticHotWaterLastYear(self):
183
205
  return self.getProperty("heating.power.consumption.summary.dhw")["properties"]["lastYear"]["value"]
184
206
 
207
+ # Current values of the whole heat pump, Compressor has the per-compressor ones:
208
+ @handleNotSupported
209
+ def getHeatProductionCurrent(self) -> float:
210
+ return float(self.getProperty("heating.heat.production.current")["properties"]["value"]["value"])
211
+
212
+ @handleNotSupported
213
+ def getHeatProductionCurrentUnit(self) -> str:
214
+ return str(self.getProperty("heating.heat.production.current")["properties"]["value"]["unit"])
215
+
216
+ @handleNotSupported
217
+ def getPowerConsumptionCurrent(self) -> float:
218
+ return float(self.getProperty("heating.power.consumption.current")["properties"]["value"]["value"])
219
+
220
+ @handleNotSupported
221
+ def getPowerConsumptionCurrentUnit(self) -> str:
222
+ return str(self.getProperty("heating.power.consumption.current")["properties"]["value"]["unit"])
223
+
224
+ @handleNotSupported
225
+ def getDefrostingActive(self) -> bool:
226
+ return bool(self.getProperty("heating.outdoor.defrosting")["properties"]["active"]["value"])
227
+
228
+ @handleNotSupported
229
+ def getFourThreeWayValvePosition(self) -> str:
230
+ return str(self.getProperty("heating.valves.fourThreeWay.position")["properties"]["value"]["value"])
231
+
232
+ @handleNotSupported
233
+ def getSecondaryCircuitOperationState(self) -> str:
234
+ return str(self.getProperty("heating.secondaryCircuit.operation.state")["properties"]["currentValue"]["value"])
235
+
236
+ @handleNotSupported
237
+ def getSecondaryCircuitOperationStateTarget(self) -> str:
238
+ return str(self.getProperty("heating.secondaryCircuit.operation.state")["properties"]["targetValue"]["value"])
239
+
240
+ @handleNotSupported
241
+ def getSecondaryCircuitFourThreeWayValvePosition(self) -> int:
242
+ return int(self.getProperty("heating.secondaryCircuit.valves.fourThreeWay")["properties"]["current"]["value"])
243
+
244
+ @handleNotSupported
245
+ def getSecondaryCircuitFourThreeWayValvePositionTarget(self) -> int:
246
+ return int(self.getProperty("heating.secondaryCircuit.valves.fourThreeWay")["properties"]["target"]["value"])
247
+
248
+ @handleNotSupported
249
+ def getSecondaryCircuitFourThreeWayValvePositionUnit(self) -> str:
250
+ return str(self.getProperty("heating.secondaryCircuit.valves.fourThreeWay")["properties"]["current"]["unit"])
251
+
185
252
  @handleNotSupported
186
253
  def getVolumetricFlowReturn(self):
187
254
  return self.getProperty("heating.sensors.volumetricFlow.allengra")["properties"]['value']['value']
@@ -651,8 +718,12 @@ class Compressor(HeatingDeviceWithComponent):
651
718
  return str(self.getProperty(f"heating.compressors.{self.compressor}.sensors.power")["properties"]["value"]["unit"])
652
719
 
653
720
  @handleNotSupported
654
- def getSpeed(self) -> int:
655
- return int(self.getProperty(f"heating.compressors.{self.compressor}.speed.current")["properties"]["value"]["value"])
721
+ def getSpeed(self) -> float:
722
+ return float(self.getProperty(f"heating.compressors.{self.compressor}.speed.current")["properties"]["value"]["value"])
723
+
724
+ @handleNotSupported
725
+ def getSpeedUnit(self) -> str:
726
+ return str(self.getProperty(f"heating.compressors.{self.compressor}.speed.current")["properties"]["value"]["unit"])
656
727
 
657
728
  @handleNotSupported
658
729
  def getHeatProductionCurrent(self) -> float:
@@ -807,14 +878,17 @@ class Compressor(HeatingDeviceWithComponent):
807
878
  # Shows the oil temperature of the compressor.
808
879
  return float(self.getProperty(f"heating.compressors.{self.compressor}.sensors.temperature.oil")["properties"]["value"]["value"])
809
880
 
881
+ @handleNotSupported
810
882
  def getMotorChamberTemperature(self) -> float:
811
883
  # Shows the motor chamber temperature of the compressor.
812
884
  return float(self.getProperty(f"heating.compressors.{self.compressor}.sensors.temperature.motorChamber")["properties"]["value"]["value"])
813
885
 
886
+ @handleNotSupported
814
887
  def getAmbientTemperature(self) -> float:
815
888
  # Shows the ambient temperature of the compressor.
816
889
  return float(self.getProperty(f"heating.compressors.{self.compressor}.sensors.temperature.ambient")["properties"]["value"]["value"])
817
890
 
891
+ @handleNotSupported
818
892
  def getOverheatTemperature(self) -> float:
819
893
  # Shows the overheat temperature of the compressor.
820
894
  return float(self.getProperty(f"heating.compressors.{self.compressor}.sensors.temperature.overheat")["properties"]["value"]["value"])
@@ -939,3 +1013,14 @@ class Inverter(HeatingDeviceWithComponent):
939
1013
  @handleNotSupported
940
1014
  def getTemperature(self) -> float:
941
1015
  return float(self.getProperty(f"heating.inverters.{self.inverter}.sensors.temperature.powerModule")["properties"]["value"]["value"])
1016
+
1017
+
1018
+ class Fan(HeatingDeviceWithComponent):
1019
+
1020
+ @property
1021
+ def fan(self) -> str:
1022
+ return self.component
1023
+
1024
+ @handleNotSupported
1025
+ def getSpeed(self) -> float:
1026
+ return float(self.getProperty(f"heating.primaryCircuit.fans.{self.fan}.current")["properties"]["value"]["value"])