Skip to content

Commit 904e1aa

Browse files
authored
Merge pull request #72 from yozik04/cell_state
Adding cell_state property
2 parents fb489fc + ae0da6f commit 904e1aa

File tree

2 files changed

+66
-17
lines changed

2 files changed

+66
-17
lines changed

tests/test_vallox_sensors.py

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from vallox_websocket_api import (
8+
CellState,
89
DefrostMode,
910
Profile,
1011
SupplyHeatingAdjustMode,
@@ -185,7 +186,6 @@ async def test_set_defrost_mode_with_invalid_mode(vallox):
185186
"A_CYC_RH_BASIC_LEVEL": 58,
186187
"A_CYC_CO2_THRESHOLD": 800,
187188
"A_CYC_SUPPLY_HEATING_ADJUST_MODE": 0,
188-
"A_CYC_DEFROST_MODE": 0,
189189
},
190190
{
191191
"A_CYC_HOME_RH_CTRL_ENABLED": 0,
@@ -198,7 +198,6 @@ async def test_set_defrost_mode_with_invalid_mode(vallox):
198198
"A_CYC_RH_BASIC_LEVEL": 50,
199199
"A_CYC_CO2_THRESHOLD": 750,
200200
"A_CYC_SUPPLY_HEATING_ADJUST_MODE": 1,
201-
"A_CYC_DEFROST_MODE": 1,
202201
},
203202
{
204203
"A_CYC_HOME_RH_CTRL_ENABLED": 0,
@@ -211,7 +210,6 @@ async def test_set_defrost_mode_with_invalid_mode(vallox):
211210
"A_CYC_RH_BASIC_LEVEL": 60,
212211
"A_CYC_CO2_THRESHOLD": 850,
213212
"A_CYC_SUPPLY_HEATING_ADJUST_MODE": 2,
214-
"A_CYC_DEFROST_MODE": 1,
215213
},
216214
{
217215
"A_CYC_HOME_RH_CTRL_ENABLED": 1,
@@ -224,7 +222,6 @@ async def test_set_defrost_mode_with_invalid_mode(vallox):
224222
"A_CYC_RH_BASIC_LEVEL": 55,
225223
"A_CYC_CO2_THRESHOLD": 900,
226224
"A_CYC_SUPPLY_HEATING_ADJUST_MODE": 0,
227-
"A_CYC_DEFROST_MODE": 0,
228225
},
229226
],
230227
)
@@ -286,14 +283,6 @@ async def test_get_sensor_controls_and_modes(vallox, metrics_response):
286283
).name
287284
)
288285

289-
# Test defrost mode
290-
assert isinstance(data.defrost_mode, DefrostMode)
291-
assert data.defrost_mode == DefrostMode(metrics_response["A_CYC_DEFROST_MODE"])
292-
assert (
293-
data.defrost_mode.name
294-
== DefrostMode(metrics_response["A_CYC_DEFROST_MODE"]).name
295-
)
296-
297286
# Test valid profiles without specific RH and CO2 sensor control metrics
298287
with pytest.raises(ValloxInvalidInputException):
299288
data.get_rh_sensor_control(Profile.FIREPLACE)
@@ -305,3 +294,51 @@ async def test_get_sensor_controls_and_modes(vallox, metrics_response):
305294
data.get_co2_sensor_control(Profile.EXTRA)
306295

307296
vallox.fetch_metrics.assert_called_once()
297+
298+
299+
@pytest.mark.parametrize(
300+
"defrost_mode_value, expected_defrost_mode",
301+
[
302+
(0, DefrostMode.BYPASS),
303+
(1, DefrostMode.FAN_STOP),
304+
],
305+
)
306+
@pytest.mark.asyncio
307+
async def test_get_defrost_mode(vallox, defrost_mode_value, expected_defrost_mode):
308+
"""Test getting defrost mode."""
309+
# Mock the metrics response
310+
metrics_response = {"A_CYC_DEFROST_MODE": defrost_mode_value}
311+
vallox.fetch_metrics = mock.AsyncMock(return_value=metrics_response)
312+
313+
data = await vallox.fetch_metric_data()
314+
315+
# Test defrost mode
316+
assert isinstance(data.defrost_mode, DefrostMode)
317+
assert data.defrost_mode == expected_defrost_mode
318+
319+
vallox.fetch_metrics.assert_called_once()
320+
321+
322+
@pytest.mark.parametrize(
323+
"cell_state_value, expected_cell_state",
324+
[
325+
(0, CellState.HEAT_RECOVERY),
326+
(1, CellState.COOL_RECOVERY),
327+
(2, CellState.BYPASS),
328+
(3, CellState.DEFROST),
329+
],
330+
)
331+
@pytest.mark.asyncio
332+
async def test_get_cell_state(vallox, cell_state_value, expected_cell_state):
333+
"""Test getting cell state."""
334+
# Mock the metrics response
335+
metrics_response = {"A_CYC_CELL_STATE": cell_state_value}
336+
vallox.fetch_metrics = mock.AsyncMock(return_value=metrics_response)
337+
338+
data = await vallox.fetch_metric_data()
339+
340+
# Test cell state
341+
assert isinstance(data.cell_state, CellState)
342+
assert data.cell_state == expected_cell_state
343+
344+
vallox.fetch_metrics.assert_called_once()

vallox_websocket_api/vallox.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,18 @@ def defrost_mode(self) -> Optional[DefrostMode]:
303303
except ValueError:
304304
return None
305305

306+
@property
307+
def cell_state(self) -> Optional[CellState]:
308+
"""Get the current cell state.
309+
Returns:
310+
CellState: 'Heat recovery'(0), 'Cool recovery' (1), 'Bypass' (2), or 'Defrost' (3)
311+
"""
312+
state = self.get("A_CYC_CELL_STATE")
313+
try:
314+
return CellState(state)
315+
except ValueError:
316+
return None
317+
306318
def get_temperature_setting(self, profile: Profile) -> Optional[float]:
307319
"""Get the temperature setting for the profile"""
308320
if profile not in PROFILE_TO_SET_TEMPERATURE_METRIC_MAP:
@@ -351,8 +363,8 @@ def get_remaining_profile_duration(self, profile: Profile) -> Optional[int]:
351363
@property
352364
def rh_sensor_manual_control_mode(self) -> Optional[bool]:
353365
"""Return the RH sensor control mode (0 for automatic, 1 for manual)"""
354-
mode = self.get(SET_RH_SENSOR_CONTROL_MODE)
355-
return bool(mode) if mode is not None else None
366+
enabled = self.get(SET_RH_SENSOR_CONTROL_MODE)
367+
return bool(enabled) if enabled is not None else None
356368

357369
@property
358370
def rh_sensor_limit(self) -> Optional[int]:
@@ -573,13 +585,13 @@ async def set_co2_sensor_control(self, profile: Profile, enable: bool) -> None:
573585

574586
await self.set_values({setting: enable})
575587

576-
async def set_rh_sensor_manual_control_mode(self, mode: int) -> None:
588+
async def set_rh_sensor_manual_control_mode(self, enable: bool) -> None:
577589
"""Set the RH sensor control mode (0 for automatic, 1 for manual)"""
578-
if mode not in (0, 1):
590+
if enable not in (0, 1):
579591
raise ValloxInvalidInputException(
580592
"RH sensor control mode must be 0 (automatic) or 1 (manual)"
581593
)
582-
await self.set_values({SET_RH_SENSOR_CONTROL_MODE: mode})
594+
await self.set_values({SET_RH_SENSOR_CONTROL_MODE: enable})
583595

584596
async def set_rh_sensor_limit(self, percent: int) -> None:
585597
"""Set the RH sensor limit (0-100). Only relevant if the RH sensor mode is set to 'manual'."""

0 commit comments

Comments
 (0)