Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ariston/nuos_split_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,14 @@ async def async_set_water_heater_reduced_temperature(self, temperature: float):
def set_water_heater_operation_mode(self, operation_mode: str):
"""Set water heater operation mode"""
self.api.set_nuos_mode(self.gw, NuosSplitOperativeMode[operation_mode])
self.data[NuosSplitProperties.MODE] = NuosSplitOperativeMode[
# The Nuos cloud payload exposes two distinct fields: `mode` (the
# plant mode shared with other Velis devices) and `opMode` (the
# operative mode specific to Nuos: GREEN / COMFORT / FAST / IMEMORY).
# `set_nuos_mode` posts to `/operativeMode`, so the server updates
# `opMode`. The `water_heater_mode_value` getter also reads `opMode`,
# so the optimistic cache update has to mirror that field, not the
# generic `mode`.
self.data[NuosSplitProperties.OP_MODE] = NuosSplitOperativeMode[

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update test_nuos_split_properties_sync_async_and_missing_state_defaults with this cache-key correction. Its fixture has no MODE entry, but the sync and async assertions still read device.data[NuosSplitProperties.MODE]; this change writes OP_MODE, so the existing test raises KeyError and does not verify the getter-backed field. Assert OP_MODE/water_heater_mode_value for both paths.

operation_mode
].value

Expand All @@ -213,7 +220,10 @@ async def async_set_water_heater_operation_mode(self, operation_mode: str):
await self.api.async_set_nuos_mode(
self.gw, NuosSplitOperativeMode[operation_mode]
)
self.data[NuosSplitProperties.MODE] = NuosSplitOperativeMode[
# See note in `set_water_heater_operation_mode`: the cloud
# /operativeMode endpoint updates `opMode`, which is also what the
# `water_heater_mode_value` getter reads.
self.data[NuosSplitProperties.OP_MODE] = NuosSplitOperativeMode[
operation_mode
].value

Expand Down
20 changes: 16 additions & 4 deletions tests/test_device_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,16 @@ def test_nuos_split_properties_sync_async_and_missing_state_defaults(self):
self.assertNotIn(NuosSplitProperties.PROC_REQ_TEMP, device.data)
device.set_water_heater_reduced_temperature(42)
device.set_water_heater_operation_mode("FAST")
# The getter must reflect the requested mode immediately (regression:
# setter used to write `mode` while the getter reads `opMode`).
self.assertEqual(device.water_heater_mode_value, NuosSplitOperativeMode.FAST.value)
self.assertNotIn(NuosSplitProperties.MODE, device.data)
device.set_min_setpoint_temp(35)
device.set_preheating(True)
device.set_heating_rate(5)
self.assertEqual(device.data[NuosSplitProperties.COMFORT_TEMP], 43)
self.assertEqual(device.data[NuosSplitProperties.REDUCED_TEMP], 42)
self.assertEqual(device.data[NuosSplitProperties.MODE], NuosSplitOperativeMode.FAST.value)
self.assertEqual(device.data[NuosSplitProperties.OP_MODE], NuosSplitOperativeMode.FAST.value)
device.api.set_nuos_temperature.assert_called_with("gw-1", 43, 42, 60, 40)
device.api.set_velis_plant_setting.assert_called()

Expand All @@ -335,7 +339,9 @@ async def set_values():

asyncio.run(set_values())
self.assertTrue(device.data[NuosSplitProperties.BOOST_ON])
self.assertEqual(device.data[NuosSplitProperties.MODE], NuosSplitOperativeMode.GREEN.value)
self.assertEqual(device.data[NuosSplitProperties.OP_MODE], NuosSplitOperativeMode.GREEN.value)
self.assertEqual(device.water_heater_mode_value, NuosSplitOperativeMode.GREEN.value)
self.assertNotIn(NuosSplitProperties.MODE, device.data)
self.assertEqual(device.plant_settings[SlpDeviceSettings.SLP_HEATING_RATE], 4)
self.assertEqual(device.api.async_set_velis_plant_setting.await_count, 3)

Expand Down Expand Up @@ -429,7 +435,10 @@ def test_nuos_split_green_plus_mode_is_exposed_and_settable(self):

device.set_water_heater_operation_mode("GREEN_PLUS")
self.assertEqual(
device.data[NuosSplitProperties.MODE], NuosSplitOperativeMode.GREEN_PLUS.value
device.data[NuosSplitProperties.OP_MODE], NuosSplitOperativeMode.GREEN_PLUS.value
)
self.assertEqual(
device.water_heater_mode_value, NuosSplitOperativeMode.GREEN_PLUS.value
)
device.api.set_nuos_mode.assert_called_once_with(
"gw-1", NuosSplitOperativeMode.GREEN_PLUS
Expand All @@ -438,7 +447,10 @@ def test_nuos_split_green_plus_mode_is_exposed_and_settable(self):
device.api.async_set_nuos_mode = AsyncMock()
asyncio.run(device.async_set_water_heater_operation_mode("GREEN_PLUS"))
self.assertEqual(
device.data[NuosSplitProperties.MODE], NuosSplitOperativeMode.GREEN_PLUS.value
device.data[NuosSplitProperties.OP_MODE], NuosSplitOperativeMode.GREEN_PLUS.value
)
self.assertEqual(
device.water_heater_mode_value, NuosSplitOperativeMode.GREEN_PLUS.value
)
device.api.async_set_nuos_mode.assert_awaited_once_with(
"gw-1", NuosSplitOperativeMode.GREEN_PLUS
Expand Down
Loading