Skip to content

Commit ffb968b

Browse files
committed
Refactor RH sensor control methods to use boolean values and update related tests
1 parent a79582f commit ffb968b

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

tests/test_vallox_sensors.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,32 @@ async def test_set_co2_sensor_control_with_invalid_profile(vallox):
7272
await vallox.set_co2_sensor_control(Profile.EXTRA, True)
7373

7474

75+
@pytest.mark.parametrize(
76+
"mode, expected",
77+
[
78+
(True, 1),
79+
(False, 0),
80+
(1, 1),
81+
(0, 0),
82+
],
83+
)
7584
@pytest.mark.asyncio
76-
async def test_set_sensor_control_mode_and_limits(vallox):
85+
async def test_set_sensor_control_mode(vallox, mode, expected):
7786
"""Test setting sensor control modes and limits."""
7887
vallox.set_values = mock.AsyncMock()
7988

80-
# Test setting RH sensor mode
81-
await vallox.set_rh_sensor_control_mode(1) # Manual mode
82-
vallox.set_values.assert_called_once_with({"A_CYC_RH_LEVEL_MODE": 1})
83-
vallox.set_values.reset_mock()
89+
await vallox.set_rh_sensor_manual_control_mode(mode) # Manual mode
90+
vallox.set_values.assert_called_once_with({"A_CYC_RH_LEVEL_MODE": expected})
91+
92+
# Test invalid RH sensor mode
93+
with pytest.raises(ValloxInvalidInputException):
94+
await vallox.set_rh_sensor_manual_control_mode(2)
95+
96+
97+
@pytest.mark.asyncio
98+
async def test_set_sensor_control_limits(vallox):
99+
"""Test setting sensor control modes and limits."""
100+
vallox.set_values = mock.AsyncMock()
84101

85102
# Test setting RH sensor limit
86103
await vallox.set_rh_sensor_limit(65)
@@ -92,10 +109,6 @@ async def test_set_sensor_control_mode_and_limits(vallox):
92109
vallox.set_values.assert_called_once_with({"A_CYC_CO2_THRESHOLD": 1000})
93110
vallox.set_values.reset_mock()
94111

95-
# Test invalid RH sensor mode
96-
with pytest.raises(ValloxInvalidInputException):
97-
await vallox.set_rh_sensor_control_mode(2)
98-
99112
# Test invalid RH sensor limit
100113
with pytest.raises(ValloxInvalidInputException):
101114
await vallox.set_rh_sensor_limit(101)
@@ -254,7 +267,10 @@ async def test_get_sensor_controls_and_modes(vallox, metrics_response):
254267
)
255268

256269
# Test sensor modes and limits
257-
assert data.rh_sensor_control_mode == metrics_response["A_CYC_RH_LEVEL_MODE"]
270+
assert isinstance(data.rh_sensor_manual_control_mode, bool)
271+
assert data.rh_sensor_manual_control_mode == bool(
272+
metrics_response["A_CYC_RH_LEVEL_MODE"]
273+
)
258274
assert data.rh_sensor_limit == metrics_response["A_CYC_RH_BASIC_LEVEL"]
259275
assert data.co2_sensor_limit == metrics_response["A_CYC_CO2_THRESHOLD"]
260276

vallox_websocket_api/vallox.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,10 @@ def get_remaining_profile_duration(self, profile: Profile) -> Optional[int]:
349349
return None
350350

351351
@property
352-
def rh_sensor_control_mode(self) -> Optional[int]:
352+
def rh_sensor_manual_control_mode(self) -> Optional[bool]:
353353
"""Return the RH sensor control mode (0 for automatic, 1 for manual)"""
354-
return self.get(SET_RH_SENSOR_CONTROL_MODE)
354+
mode = self.get(SET_RH_SENSOR_CONTROL_MODE)
355+
return bool(mode) if mode is not None else None
355356

356357
@property
357358
def rh_sensor_limit(self) -> Optional[int]:
@@ -572,9 +573,9 @@ async def set_co2_sensor_control(self, profile: Profile, enable: bool) -> None:
572573

573574
await self.set_values({setting: enable})
574575

575-
async def set_rh_sensor_control_mode(self, mode: int) -> None:
576-
"""Set the RH sensor mode to manual (1) or automatic (0)"""
577-
if mode < 0 or mode > 1:
576+
async def set_rh_sensor_manual_control_mode(self, mode: int) -> None:
577+
"""Set the RH sensor control mode (0 for automatic, 1 for manual)"""
578+
if mode not in (0, 1):
578579
raise ValloxInvalidInputException(
579580
"RH sensor control mode must be 0 (automatic) or 1 (manual)"
580581
)

0 commit comments

Comments
 (0)