aioWiserHeatAPI 1.7.9__tar.gz → 1.7.10__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 (76) hide show
  1. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/PKG-INFO +1 -1
  2. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/__init__.py +1 -1
  3. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/automations.py +3 -0
  4. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/opentherm.py +13 -3
  5. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/rest_controller.py +1 -0
  6. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/room.py +31 -8
  7. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/system.py +2 -0
  8. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/wiserhub.py +16 -8
  9. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI.egg-info/PKG-INFO +1 -1
  10. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI.egg-info/SOURCES.txt +1 -0
  11. aiowiserheatapi-1.7.10/tests/test_heating_state.py +255 -0
  12. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/LICENSE +0 -0
  13. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/README.md +0 -0
  14. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/automation.py +0 -0
  15. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/binary_sensor.py +0 -0
  16. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/boiler_interface.py +0 -0
  17. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/button_panel.py +0 -0
  18. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/cli.py +0 -0
  19. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/const.py +0 -0
  20. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/devices.py +0 -0
  21. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/discovery.py +0 -0
  22. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/equipments.py +0 -0
  23. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/evse.py +0 -0
  24. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/exceptions.py +0 -0
  25. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/heating.py +0 -0
  26. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/heating_actuator.py +0 -0
  27. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/__init__.py +0 -0
  28. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/battery.py +0 -0
  29. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/capabilities.py +0 -0
  30. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/cloud.py +0 -0
  31. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/device.py +0 -0
  32. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/equipment.py +0 -0
  33. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/extra_config.py +0 -0
  34. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/firmware.py +0 -0
  35. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/gps.py +0 -0
  36. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/misc.py +0 -0
  37. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/network.py +0 -0
  38. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/signal.py +0 -0
  39. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/special_times.py +0 -0
  40. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/status.py +0 -0
  41. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/temp.py +0 -0
  42. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/threshold.py +0 -0
  43. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/uiconfiguration.py +0 -0
  44. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/version.py +0 -0
  45. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/helpers/zigbee.py +0 -0
  46. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/hot_water.py +0 -0
  47. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/light.py +0 -0
  48. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/moments.py +0 -0
  49. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/ptc.py +0 -0
  50. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/pte.py +0 -0
  51. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/refactor.py +0 -0
  52. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/roomstat.py +0 -0
  53. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/schedule.py +0 -0
  54. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/shutter.py +0 -0
  55. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/smartplug.py +0 -0
  56. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/smartvalve.py +0 -0
  57. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/smokealarm.py +0 -0
  58. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/temp_humidity.py +0 -0
  59. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI/ufh.py +0 -0
  60. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI.egg-info/dependency_links.txt +0 -0
  61. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI.egg-info/entry_points.txt +0 -0
  62. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI.egg-info/requires.txt +0 -0
  63. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/aioWiserHeatAPI.egg-info/top_level.txt +0 -0
  64. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/setup.cfg +0 -0
  65. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/setup.py +0 -0
  66. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_device_notifications.py +0 -0
  67. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_equipment.py +0 -0
  68. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_equipments.py +0 -0
  69. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_evse.py +0 -0
  70. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_heating_actuator.py +0 -0
  71. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_light.py +0 -0
  72. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_ptc.py +0 -0
  73. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_rest_controller.py +0 -0
  74. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_rest_payloads.py +0 -0
  75. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_schedule.py +0 -0
  76. {aiowiserheatapi-1.7.9 → aiowiserheatapi-1.7.10}/tests/test_smartplug.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aioWiserHeatAPI
3
- Version: 1.7.9
3
+ Version: 1.7.10
4
4
  Summary: An AsyncIO API for controlling the Drayton Wiser Heating system
5
5
  Home-page: https://github.com/msp1974/aioWiserHeatAPI
6
6
  Author: Mark Parker
@@ -3,6 +3,6 @@ import logging
3
3
  name = "aioWiserHeatAPI"
4
4
  __all__ = ["wiserAPI", "wiserDiscovery"]
5
5
 
6
- __VERSION__ = "1.7.9"
6
+ __VERSION__ = "1.7.10"
7
7
 
8
8
  _LOGGER = logging.getLogger(__name__)
@@ -71,6 +71,9 @@ class _WiserHeatingChannelAutomations:
71
71
  if room.is_passive_mode
72
72
  and room.id in heating_channel.room_ids
73
73
  and room.current_temperature is not None
74
+ # At a schedule transition the hub's room target can still be
75
+ # from the previous slot. Writing now would create an override.
76
+ and not room.passive_lower_limit_follows_schedule
74
77
  ]
75
78
 
76
79
  # If no passive mode rooms
@@ -174,9 +174,11 @@ class _WiserOpentherm(object):
174
174
  wiser_rest_controller: _WiserRestController,
175
175
  data: dict,
176
176
  enabled_status: str,
177
+ ever_connected: bool = False,
177
178
  ):
178
179
  self._data = data
179
180
  self._enabled_status = enabled_status
181
+ self._ever_connected = ever_connected or enabled_status == "Connected"
180
182
  self._wiser_rest_controller = wiser_rest_controller
181
183
 
182
184
  @property
@@ -219,10 +221,17 @@ class _WiserOpentherm(object):
219
221
  return tf._from_wiser_temp(self._data.get("ch2FlowSetpoint", None), "current")
220
222
 
221
223
  @property
222
- def central_heating_active(self) -> bool:
224
+ def central_heating_active(self) -> bool | None:
223
225
  """Return whether the boiler is operating in central-heating mode."""
224
226
  slave_status = self.operational_data.slave_status
225
- return isinstance(slave_status, int) and bool(slave_status & (1 << 1))
227
+ if isinstance(slave_status, bool) or not isinstance(slave_status, int):
228
+ return None
229
+ return bool(slave_status & (1 << 1))
230
+
231
+ @property
232
+ def is_configured(self) -> bool:
233
+ """Keep a known OpenTherm installation distinct during outages."""
234
+ return self._ever_connected or self.enabled
226
235
 
227
236
  @property
228
237
  def connection_status(self) -> str:
@@ -251,7 +260,8 @@ class _WiserOpentherm(object):
251
260
 
252
261
  @property
253
262
  def operational_data(self) -> _WiserOpenThermOperationalData:
254
- return _WiserOpenThermOperationalData(self._data.get("operationalData", {}))
263
+ data = self._data.get("operationalData")
264
+ return _WiserOpenThermOperationalData(data if isinstance(data, dict) else {})
255
265
 
256
266
  @property
257
267
  def boiler_parameters(self) -> _WiserOpenThermBoilerParameters:
@@ -43,6 +43,7 @@ class WiserAPIParams:
43
43
  stored_manual_target_temperature_alt_source: str = "current"
44
44
  boost_temp_delta: int = DEFAULT_BOOST_DELTA
45
45
  hw_climate_mode: bool = False
46
+ opentherm_ever_connected: bool = False
46
47
 
47
48
 
48
49
  # Connection info class
@@ -1,5 +1,6 @@
1
1
  import inspect
2
2
  from datetime import datetime
3
+ from math import isfinite
3
4
  from typing import Union
4
5
 
5
6
  from aioWiserHeatAPI.helpers.capabilities import _WiserClimateCapabilities
@@ -254,6 +255,16 @@ class _WiserRoom(object):
254
255
  )
255
256
  return False
256
257
 
258
+ @property
259
+ def passive_lower_limit_follows_schedule(self) -> bool:
260
+ """Return whether the hub schedule already supplies the limiter target."""
261
+ return (
262
+ not self.is_override
263
+ and not self.is_away_mode
264
+ and self._auto_uses_scheduled_passive_lower_temp
265
+ and self.passive_mode_lower_temp == self.schedule.current_setting
266
+ )
267
+
257
268
  async def set_passive_mode_lower_temp(self, temp):
258
269
  if not await self._update_extra_config("min", temp):
259
270
  _LOGGER.error(
@@ -432,18 +443,30 @@ class _WiserRoom(object):
432
443
  @property
433
444
  def is_calling_for_heat(self) -> bool | None:
434
445
  """Return whether the room is requesting heat."""
435
- if "PercentageDemand" not in self._data:
446
+ demand = self._data.get("PercentageDemand")
447
+ if (
448
+ isinstance(demand, bool)
449
+ or not isinstance(demand, (int, float))
450
+ or not 0 <= demand <= 100
451
+ or not isfinite(demand)
452
+ ):
436
453
  return None
437
- return self.percentage_demand > 0
454
+ return demand > 0
438
455
 
439
456
  @property
440
- def is_heating(self) -> bool:
457
+ def is_heating(self) -> bool | None:
441
458
  """Return whether central heating is currently servicing room demand."""
442
- if self._opentherm and self._opentherm.connection_status == "Connected":
443
- return (
444
- self.is_calling_for_heat is True
445
- and self._opentherm.central_heating_active
446
- )
459
+ if self._opentherm and self._opentherm.is_configured:
460
+ if (
461
+ self._opentherm.connection_status != "Connected"
462
+ or not self._opentherm.enabled
463
+ ):
464
+ return None
465
+ calling = self.is_calling_for_heat
466
+ active = self._opentherm.central_heating_active
467
+ if calling is None or active is None:
468
+ return None
469
+ return calling and active
447
470
  return self._data.get("ControlOutputState", TEXT_OFF) == TEXT_ON
448
471
 
449
472
  @property
@@ -29,6 +29,7 @@ class _WiserSystem(object):
29
29
  network_data: dict,
30
30
  device_data: dict,
31
31
  opentherm_data: dict,
32
+ opentherm_ever_connected: bool = False,
32
33
  ):
33
34
  self._wiser_rest_controller = wiser_rest_controller
34
35
  self._data = domain_data
@@ -53,6 +54,7 @@ class _WiserSystem(object):
53
54
  self._wiser_rest_controller,
54
55
  opentherm_data,
55
56
  self._system_data.get("OpenThermConnectionStatus", TEXT_UNKNOWN),
57
+ opentherm_ever_connected,
56
58
  )
57
59
  self._signal = _WiserSignalStrength(self._device_data)
58
60
  self._upgrade_data = _WiserFirmareUpgradeInfo(self._data.get("UpgradeInfo", {}))
@@ -196,11 +196,13 @@ class WiserAPI:
196
196
  except WiserHubRESTError:
197
197
  self._status_data = {}
198
198
 
199
- # Only get opentherm data if connected
199
+ # Do not let an optional boiler endpoint invalidate fresh hub data.
200
200
  opentherm = self._domain_data.get("System", {}).get(
201
201
  "OpenThermConnectionStatus", ""
202
202
  )
203
- if opentherm and opentherm == "Connected" or True:
203
+ self._opentherm_data = {}
204
+ if opentherm == "Connected":
205
+ self.api_parameters.opentherm_ever_connected = True
204
206
  fw_version = Version(
205
207
  self._domain_data.get("System", {}).get(
206
208
  "ActiveSystemVersion", "1.0.0"
@@ -209,12 +211,17 @@ class WiserAPI:
209
211
  hw_version = self._domain_data.get("System", {}).get(
210
212
  "HardwareGeneration", 1
211
213
  )
212
- self._opentherm_data = await self._wiser_rest_controller.get_hub_data(
213
- WISERHUBOPENTHERMV2
214
- if hw_version == 2 and fw_version >= OPENTHERMV2_MIN_VERSION
215
- else WISERHUBOPENTHERM,
216
- False,
217
- )
214
+ try:
215
+ data = await self._wiser_rest_controller.get_hub_data(
216
+ WISERHUBOPENTHERMV2
217
+ if hw_version == 2 and fw_version >= OPENTHERMV2_MIN_VERSION
218
+ else WISERHUBOPENTHERM,
219
+ False,
220
+ )
221
+ if isinstance(data, dict):
222
+ self._opentherm_data = data
223
+ except (WiserHubConnectionError, WiserHubRESTError) as ex:
224
+ _LOGGER.warning("Unable to read OpenTherm data: %s", ex)
218
225
  except (
219
226
  WiserHubConnectionError,
220
227
  WiserHubAuthenticationError,
@@ -258,6 +265,7 @@ class WiserAPI:
258
265
  self._network_data,
259
266
  _device_data,
260
267
  self._opentherm_data,
268
+ self.api_parameters.opentherm_ever_connected,
261
269
  )
262
270
 
263
271
  # Schedules Collection
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aioWiserHeatAPI
3
- Version: 1.7.9
3
+ Version: 1.7.10
4
4
  Summary: An AsyncIO API for controlling the Drayton Wiser Heating system
5
5
  Home-page: https://github.com/msp1974/aioWiserHeatAPI
6
6
  Author: Mark Parker
@@ -66,6 +66,7 @@ tests/test_equipment.py
66
66
  tests/test_equipments.py
67
67
  tests/test_evse.py
68
68
  tests/test_heating_actuator.py
69
+ tests/test_heating_state.py
69
70
  tests/test_light.py
70
71
  tests/test_ptc.py
71
72
  tests/test_rest_controller.py
@@ -0,0 +1,255 @@
1
+ """Heating state and refresh regressions using the real API objects."""
2
+
3
+ import unittest
4
+ from types import SimpleNamespace
5
+ from unittest.mock import AsyncMock
6
+
7
+ from aioWiserHeatAPI.const import (
8
+ WISERHUBDOMAIN,
9
+ WISERHUBNETWORK,
10
+ WISERHUBOPENTHERM,
11
+ WISERHUBOPENTHERMV2,
12
+ WISERHUBSCHEDULES,
13
+ WISERHUBSTATUS,
14
+ )
15
+ from aioWiserHeatAPI.exceptions import (
16
+ WiserHubAuthenticationError,
17
+ WiserHubConnectionError,
18
+ WiserHubRESTError,
19
+ )
20
+ from aioWiserHeatAPI.helpers.automations import _WiserHeatingChannelAutomations
21
+ from aioWiserHeatAPI.helpers.opentherm import _WiserOpentherm
22
+ from aioWiserHeatAPI.rest_controller import WiserAPIParams
23
+ from aioWiserHeatAPI.room import _WiserRoom
24
+ from aioWiserHeatAPI.wiserhub import WiserAPI
25
+
26
+
27
+ def boiler(status="Connected", data=None, ever_connected=False):
28
+ return _WiserOpentherm(None, data or {}, status, ever_connected)
29
+
30
+
31
+ def room(opentherm=None, **data):
32
+ # Only the state properties are under test; no schedule or devices needed.
33
+ result = object.__new__(_WiserRoom)
34
+ result._data = data
35
+ result._opentherm = opentherm
36
+ return result
37
+
38
+
39
+ class PassiveScheduleTest(unittest.IsolatedAsyncioTestCase):
40
+ async def test_limiter_leaves_matching_schedule_target_to_hub(self):
41
+ for active_demand in (0, 20):
42
+ for lower in (17, 16):
43
+ with self.subTest(active_demand=active_demand, lower=lower):
44
+ limiter = room(
45
+ id=1,
46
+ DisplayedSetPoint=180,
47
+ CalculatedTemperature=179,
48
+ SetpointOrigin="FromSchedule",
49
+ )
50
+ limiter._enable_automations = True
51
+ limiter._name = "Lounge"
52
+ limiter._extra_config = {"passive_mode": True, "max": 22}
53
+ limiter._mode = "Auto"
54
+ limiter._schedule = SimpleNamespace(current_setting=17)
55
+ limiter.set_target_temperature = AsyncMock(return_value=True)
56
+ controller = SimpleNamespace(
57
+ _api_parameters=WiserAPIParams(
58
+ passive_mode_lower_temp_provider=lambda _: lower,
59
+ passive_mode_temperature_limiter_provider=lambda _: True,
60
+ )
61
+ )
62
+ limiter._wiser_rest_controller = controller
63
+ active_room = SimpleNamespace(
64
+ id=2,
65
+ name="Office",
66
+ is_passive_mode=False,
67
+ percentage_demand=active_demand,
68
+ )
69
+ channels = SimpleNamespace(
70
+ all=[SimpleNamespace(id=1, room_ids=[1, 2])],
71
+ _rooms=SimpleNamespace(all=[limiter, active_room]),
72
+ )
73
+
74
+ updated = await _WiserHeatingChannelAutomations(
75
+ controller, channels
76
+ ).run_automations()
77
+
78
+ if lower == 17:
79
+ self.assertFalse(updated)
80
+ limiter.set_target_temperature.assert_not_awaited()
81
+ else:
82
+ self.assertTrue(updated)
83
+ limiter.set_target_temperature.assert_awaited_once_with(16)
84
+
85
+
86
+ class HeatingStateTest(unittest.TestCase):
87
+ def test_relay_rooms_keep_using_control_output(self):
88
+ for status in ("On", "Off"):
89
+ for demand in (0, 50):
90
+ with self.subTest(status=status, demand=demand):
91
+ result = room(
92
+ boiler("Disconnected"),
93
+ ControlOutputState=status,
94
+ PercentageDemand=demand,
95
+ )
96
+ self.assertIs(result.is_heating, status == "On")
97
+
98
+ def test_opentherm_requires_room_demand_and_ch_activity(self):
99
+ for demand in (0, 50):
100
+ for slave in (0, 2, 4, 8, 12):
101
+ with self.subTest(demand=demand, slave=slave):
102
+ result = room(
103
+ boiler(data={
104
+ "Enabled": True,
105
+ "operationalData": {"SlaveStatus": slave},
106
+ }),
107
+ PercentageDemand=demand,
108
+ ControlOutputState="On",
109
+ )
110
+ self.assertIs(
111
+ result.is_heating, demand > 0 and bool(slave & 2)
112
+ )
113
+
114
+ def test_missing_or_invalid_slave_status_is_unknown(self):
115
+ for value in (None, True, False, "2", 2.0):
116
+ with self.subTest(value=value):
117
+ ot = boiler(data={
118
+ "Enabled": True,
119
+ "operationalData": {"SlaveStatus": value},
120
+ })
121
+ self.assertIsNone(ot.central_heating_active)
122
+ self.assertIsNone(room(ot, PercentageDemand=50).is_heating)
123
+
124
+ def test_missing_or_invalid_operational_data_is_unknown(self):
125
+ for data in ({}, {"operationalData": None}, {"operationalData": []}):
126
+ with self.subTest(data=data):
127
+ self.assertIsNone(boiler(data=data).central_heating_active)
128
+
129
+ def test_missing_or_invalid_room_demand_is_unknown(self):
130
+ ot = boiler(data={
131
+ "Enabled": True, "operationalData": {"SlaveStatus": 2},
132
+ })
133
+ invalid = (None, True, "50", -1, 101, float("nan"), float("inf"))
134
+ for data in ({}, *({"PercentageDemand": v} for v in invalid)):
135
+ with self.subTest(data=data):
136
+ result = room(ot, **data)
137
+ self.assertIsNone(result.is_calling_for_heat)
138
+ self.assertIsNone(result.is_heating)
139
+
140
+ def test_disconnected_or_disabled_opentherm_does_not_use_room_output(self):
141
+ for ot in (
142
+ boiler("Disconnected", {"Enabled": True}),
143
+ boiler("Disconnected", ever_connected=True),
144
+ boiler("Unknown", ever_connected=True),
145
+ boiler(data={"Enabled": False, "operationalData": {"SlaveStatus": 2}}),
146
+ ):
147
+ for output in ("On", "Off"):
148
+ with self.subTest(status=ot.connection_status, output=output):
149
+ result = room(
150
+ ot, PercentageDemand=50, ControlOutputState=output
151
+ )
152
+ self.assertIsNone(result.is_heating)
153
+
154
+
155
+ class HeatingRefreshTest(unittest.IsolatedAsyncioTestCase):
156
+ def setUp(self):
157
+ self.hub = WiserAPI("wiser.example", "secret")
158
+ self.domain = {
159
+ "System": {
160
+ "UnixTime": 0,
161
+ "HardwareGeneration": 1,
162
+ "OpenThermConnectionStatus": "Disconnected",
163
+ },
164
+ "Device": [],
165
+ "Room": [{
166
+ "id": 1, "Name": "Room", "Mode": "Auto",
167
+ "PercentageDemand": 50, "ControlOutputState": "On",
168
+ }],
169
+ "HeatingChannel": [{"id": 1, "RoomIds": [1]}],
170
+ "HotWater": [{"id": 2}],
171
+ }
172
+ self.ot_data = {"Enabled": True, "operationalData": {"SlaveStatus": 2}}
173
+ self.ot_error = None
174
+ self.controller = self.hub._wiser_rest_controller
175
+ self.controller.get_hub_data = AsyncMock(side_effect=self.read)
176
+ self.controller.get_extra_config_data = AsyncMock()
177
+
178
+ async def read(self, endpoint, *_args):
179
+ if endpoint in (WISERHUBOPENTHERM, WISERHUBOPENTHERMV2):
180
+ if self.ot_error:
181
+ raise self.ot_error
182
+ return self.ot_data
183
+ return {
184
+ WISERHUBDOMAIN: self.domain,
185
+ WISERHUBNETWORK: {"Station": {}},
186
+ WISERHUBSCHEDULES: [],
187
+ WISERHUBSTATUS: {},
188
+ }[endpoint]
189
+
190
+ async def test_relay_hub_does_not_poll_opentherm(self):
191
+ await self.hub.read_hub_data()
192
+ calls = [
193
+ call.args[0] for call in self.controller.get_hub_data.await_args_list
194
+ ]
195
+ self.assertNotIn(WISERHUBOPENTHERM, calls)
196
+ self.assertNotIn(WISERHUBOPENTHERMV2, calls)
197
+ self.assertTrue(self.hub.rooms.get_by_id(1).is_heating)
198
+
199
+ async def test_connection_loss_and_recovery(self):
200
+ self.domain["System"]["OpenThermConnectionStatus"] = "Connected"
201
+ await self.hub.read_hub_data()
202
+ self.assertTrue(self.hub.rooms.get_by_id(1).is_heating)
203
+ self.domain["System"]["OpenThermConnectionStatus"] = "Disconnected"
204
+ await self.hub.read_hub_data()
205
+ self.assertIsNone(self.hub.rooms.get_by_id(1).is_heating)
206
+ self.assertEqual(self.hub.system.opentherm.json_data, {})
207
+ self.domain["System"]["OpenThermConnectionStatus"] = "Connected"
208
+ await self.hub.read_hub_data()
209
+ self.assertTrue(self.hub.rooms.get_by_id(1).is_heating)
210
+
211
+ async def test_known_opentherm_disconnected_on_startup(self):
212
+ self.hub.api_parameters.opentherm_ever_connected = True
213
+ await self.hub.read_hub_data()
214
+ self.assertIsNone(self.hub.rooms.get_by_id(1).is_heating)
215
+
216
+ async def test_optional_endpoint_failure_clears_previous_data(self):
217
+ self.domain["System"]["OpenThermConnectionStatus"] = "Connected"
218
+ await self.hub.read_hub_data()
219
+ for error in (
220
+ WiserHubConnectionError("timeout"), WiserHubRESTError("bad JSON")
221
+ ):
222
+ with self.subTest(error=type(error).__name__):
223
+ self.ot_error = error
224
+ await self.hub.read_hub_data()
225
+ self.assertEqual(self.hub.system.opentherm.json_data, {})
226
+ self.assertIsNone(self.hub.rooms.get_by_id(1).is_heating)
227
+ self.assertIsNotNone(self.hub.heating_channels)
228
+
229
+ async def test_malformed_endpoint_response_is_unknown(self):
230
+ self.domain["System"]["OpenThermConnectionStatus"] = "Connected"
231
+ self.ot_data = None
232
+ await self.hub.read_hub_data()
233
+ self.assertIsNone(self.hub.rooms.get_by_id(1).is_heating)
234
+
235
+ async def test_authentication_failure_is_not_suppressed(self):
236
+ self.domain["System"]["OpenThermConnectionStatus"] = "Connected"
237
+ self.ot_error = WiserHubAuthenticationError("unauthorized")
238
+ with self.assertRaises(WiserHubAuthenticationError):
239
+ await self.hub.read_hub_data()
240
+
241
+ async def test_firmware_selects_correct_opentherm_endpoint(self):
242
+ for generation, version, expected in (
243
+ (1, "4.99.0", WISERHUBOPENTHERM),
244
+ (2, "4.32.46", WISERHUBOPENTHERM),
245
+ (2, "4.32.47", WISERHUBOPENTHERMV2),
246
+ ):
247
+ with self.subTest(generation=generation, version=version):
248
+ self.domain["System"].update(
249
+ HardwareGeneration=generation,
250
+ ActiveSystemVersion=version,
251
+ OpenThermConnectionStatus="Connected",
252
+ )
253
+ self.controller.get_hub_data.reset_mock()
254
+ await self.hub.read_hub_data()
255
+ self.controller.get_hub_data.assert_any_await(expected, False)