From 53d2b6e48c5569277b008d3f36143038c8491a59 Mon Sep 17 00:00:00 2001 From: Julius Vitkauskas Date: Wed, 20 Dec 2023 20:52:12 +0200 Subject: [PATCH] Always return HVACAction.HEATING or HVACAction.COOLING if heating or cooling operation mode is selected --- pybls21/client.py | 4 ++-- tests/test_client.py | 47 +++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/pybls21/client.py b/pybls21/client.py index 7fee387..b0c730e 100644 --- a/pybls21/client.py +++ b/pybls21/client.py @@ -104,8 +104,8 @@ async def _poll(self) -> ClimateDevice: else HVACMode.AUTO, hvac_action=HVACAction.OFF if not is_on else HVACAction.FAN if operation_mode == 0 - else HVACAction.HEATING if temp_before_heating_x10 < temp_after_heating_x10 - else HVACAction.COOLING if temp_before_heating_x10 > temp_after_heating_x10 + else HVACAction.HEATING if (operation_mode == 1 or (temp_before_heating_x10 < temp_after_heating_x10)) + else HVACAction.COOLING if (operation_mode == 2 or (temp_before_heating_x10 > temp_after_heating_x10)) else HVACAction.IDLE, hvac_modes=[HVACMode.OFF, HVACMode.HEAT, HVACMode.COOL, HVACMode.AUTO, HVACMode.FAN_ONLY], fan_mode=current_fan_level, diff --git a/tests/test_client.py b/tests/test_client.py index 233a02f..b839b16 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -101,10 +101,8 @@ async def test_poll_when_ventilation_only_mode_is_set(self): self.assertEqual(device.hvac_mode, HVACMode.FAN_ONLY) self.assertEqual(device.hvac_action, HVACAction.FAN) - async def test_poll_when_heating_mode_is_set_and_temperature_is_not_reached(self): + async def test_poll_when_heating_mode_is_set(self): self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [1]) - self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [10]) - self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [20]) client = S21Client(host=self.server.host, port=self.server.port) device = await client.poll() @@ -112,40 +110,49 @@ async def test_poll_when_heating_mode_is_set_and_temperature_is_not_reached(self self.assertEqual(device.hvac_mode, HVACMode.HEAT) self.assertEqual(device.hvac_action, HVACAction.HEATING) - async def test_poll_when_heating_mode_is_set_and_temperature_is_reached(self): - self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [1]) - self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [20]) - self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [20]) + async def test_poll_when_cooling_mode_is_set(self): + self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [2]) client = S21Client(host=self.server.host, port=self.server.port) device = await client.poll() - self.assertEqual(device.hvac_mode, HVACMode.HEAT) - self.assertEqual(device.hvac_action, HVACAction.IDLE) + self.assertEqual(device.hvac_mode, HVACMode.COOL) + self.assertEqual(device.hvac_action, HVACAction.COOLING) - async def test_poll_when_cooling_mode_is_set_and_temperature_is_not_reached(self): - self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [2]) + async def test_poll_when_auto_mode_is_set_and_output_temperature_is_bigger(self): + self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [3]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [10]) - self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [5]) + self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [20]) client = S21Client(host=self.server.host, port=self.server.port) device = await client.poll() - self.assertEqual(device.hvac_mode, HVACMode.COOL) - self.assertEqual(device.hvac_action, HVACAction.COOLING) + self.assertEqual(device.hvac_mode, HVACMode.AUTO) + self.assertEqual(device.hvac_action, HVACAction.HEATING) - async def test_poll_when_cooling_mode_is_set_and_temperature_is_reached(self): - self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [2]) + async def test_poll_when_auto_mode_is_set_and_temperature_is_reached(self): + self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [3]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [20]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [20]) client = S21Client(host=self.server.host, port=self.server.port) device = await client.poll() - self.assertEqual(device.hvac_mode, HVACMode.COOL) + self.assertEqual(device.hvac_mode, HVACMode.AUTO) self.assertEqual(device.hvac_action, HVACAction.IDLE) - async def test_poll_when_cooling_mode_is_set_to_auto_and_in_temperature_matches_out_temperature(self): + async def test_poll_when_auto_mode_is_set_and_output_temperature_is_lower(self): + self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [3]) + self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [10]) + self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [5]) + + client = S21Client(host=self.server.host, port=self.server.port) + device = await client.poll() + + self.assertEqual(device.hvac_mode, HVACMode.AUTO) + self.assertEqual(device.hvac_action, HVACAction.COOLING) + + async def test_poll_when_auto_mode_is_set_and_in_temperature_matches_out_temperature(self): self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [3]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [10]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [10]) @@ -156,7 +163,7 @@ async def test_poll_when_cooling_mode_is_set_to_auto_and_in_temperature_matches_ self.assertEqual(device.hvac_mode, HVACMode.AUTO) self.assertEqual(device.hvac_action, HVACAction.IDLE) - async def test_poll_when_cooling_mode_is_set_to_auto_and_in_temperature_is_cooler_than_out_temperature(self): + async def test_poll_when_auto_mode_is_set_and_in_temperature_is_cooler_than_out_temperature(self): self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [3]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [5]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [10]) @@ -167,7 +174,7 @@ async def test_poll_when_cooling_mode_is_set_to_auto_and_in_temperature_is_coole self.assertEqual(device.hvac_mode, HVACMode.AUTO) self.assertEqual(device.hvac_action, HVACAction.HEATING) - async def test_poll_when_cooling_mode_is_set_to_auto_and_in_temperature_is_hotter_than_out_temperature(self): + async def test_poll_when_auto_mode_is_set_and_in_temperature_is_hotter_than_out_temperature(self): self.server.data_bank.set_holding_registers(HR_OPERATION_MODE, [3]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirIn, [10]) self.server.data_bank.set_input_registers(IR_CurTEMP_SuAirOut, [5])