Skip to content

Commit

Permalink
Always return HVACAction.HEATING or HVACAction.COOLING if heating or …
Browse files Browse the repository at this point in the history
…cooling operation mode is selected
  • Loading branch information
jvitkauskas committed Dec 20, 2023
1 parent 3a25b10 commit 53d2b6e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pybls21/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 27 additions & 20 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,51 +101,58 @@ 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()

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])
Expand All @@ -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])
Expand All @@ -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])
Expand Down

0 comments on commit 53d2b6e

Please sign in to comment.