Fix stale Duco end times for continuous ventilation states (#181529)

This commit is contained in:
Ronald van der Meer
2026-09-08 10:38:15 +02:00
committed by GitHub
parent 93afe7411f
commit 08c4f686bf
2 changed files with 23 additions and 3 deletions
+9 -1
View File
@@ -34,6 +34,12 @@ _LOGGER = logging.getLogger(__name__)
PARALLEL_UPDATES = 0
_CONTINUOUS_VENTILATION_STATES = {
VentilationState.CNT1,
VentilationState.CNT2,
VentilationState.CNT3,
}
@dataclass(frozen=True, kw_only=True)
class DucoSensorEntityDescription(SensorEntityDescription):
@@ -85,7 +91,9 @@ SENSOR_DESCRIPTIONS: tuple[DucoSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda node: (
dt_util.utc_from_timestamp(node.ventilation.time_state_end)
if node.ventilation and node.ventilation.time_state_end != 0
if node.ventilation
and node.ventilation.state not in _CONTINUOUS_VENTILATION_STATES
and node.ventilation.time_state_end != 0
else None
),
node_types=VENTILATION_CAPABLE_NODE_TYPES,
+14 -2
View File
@@ -95,11 +95,22 @@ async def test_ventilation_related_sensors_created_for_supported_node_types(
assert hass.states.get("sensor.office_co2_state_end_time") is None
@pytest.mark.parametrize(
("ventilation_state", "expected_state_end"),
[
pytest.param(VentilationState.MAN1, "2023-11-14T22:20:59+00:00", id="timed"),
pytest.param(VentilationState.CNT1, STATE_UNKNOWN, id="continuous-1"),
pytest.param(VentilationState.CNT2, STATE_UNKNOWN, id="continuous-2"),
pytest.param(VentilationState.CNT3, STATE_UNKNOWN, id="continuous-3"),
],
)
async def test_ventilation_related_sensors_created_for_box_node(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_duco_client: AsyncMock,
mock_sensor_nodes: list[Node],
ventilation_state: VentilationState,
expected_state_end: str,
) -> None:
"""Test ventilation-related sensors are created for the box node.
@@ -111,6 +122,7 @@ async def test_ventilation_related_sensors_created_for_box_node(
mock_sensor_nodes[0],
ventilation=replace(
mock_sensor_nodes[0].ventilation,
state=ventilation_state,
flow_lvl_tgt=42,
time_state_end=1700000459,
),
@@ -124,7 +136,7 @@ async def test_ventilation_related_sensors_created_for_box_node(
state = hass.states.get("sensor.living_ventilation_state")
assert state is not None
assert state.state == "auto"
assert state.state == ventilation_state.lower()
state = hass.states.get("sensor.living_target_flow_level")
assert state is not None
@@ -132,7 +144,7 @@ async def test_ventilation_related_sensors_created_for_box_node(
state = hass.states.get("sensor.living_state_end_time")
assert state is not None
assert state.state == "2023-11-14T22:20:59+00:00"
assert state.state == expected_state_end
assert hass.states.get("sensor.office_co2_ventilation_state") is None
assert hass.states.get("sensor.office_co2_target_flow_level") is None