diff --git a/homeassistant/components/duco/sensor.py b/homeassistant/components/duco/sensor.py index 2c157d473e00..5899f7d677fd 100644 --- a/homeassistant/components/duco/sensor.py +++ b/homeassistant/components/duco/sensor.py @@ -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, diff --git a/tests/components/duco/test_sensor.py b/tests/components/duco/test_sensor.py index 9cf809fc9878..b7ce79b1fd5a 100644 --- a/tests/components/duco/test_sensor.py +++ b/tests/components/duco/test_sensor.py @@ -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