diff --git a/homeassistant/components/climate/reproduce_state.py b/homeassistant/components/climate/reproduce_state.py index 2897a956fc6..e5fb5d6004b 100644 --- a/homeassistant/components/climate/reproduce_state.py +++ b/homeassistant/components/climate/reproduce_state.py @@ -68,13 +68,22 @@ async def _async_reproduce_states( [ATTR_TEMPERATURE, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW], ) - if ATTR_PRESET_MODE in state.attributes: + if ( + ATTR_PRESET_MODE in state.attributes + and state.attributes[ATTR_PRESET_MODE] is not None + ): await call_service(SERVICE_SET_PRESET_MODE, [ATTR_PRESET_MODE]) - if ATTR_SWING_MODE in state.attributes: + if ( + ATTR_SWING_MODE in state.attributes + and state.attributes[ATTR_SWING_MODE] is not None + ): await call_service(SERVICE_SET_SWING_MODE, [ATTR_SWING_MODE]) - if ATTR_FAN_MODE in state.attributes: + if ( + ATTR_FAN_MODE in state.attributes + and state.attributes[ATTR_FAN_MODE] is not None + ): await call_service(SERVICE_SET_FAN_MODE, [ATTR_FAN_MODE]) if ATTR_HUMIDITY in state.attributes: diff --git a/tests/components/climate/test_reproduce_state.py b/tests/components/climate/test_reproduce_state.py index 34cf4433029..b8719fd8fd0 100644 --- a/tests/components/climate/test_reproduce_state.py +++ b/tests/components/climate/test_reproduce_state.py @@ -119,6 +119,25 @@ async def test_attribute(hass: HomeAssistant, service, attribute) -> None: assert calls_1[0].data == {"entity_id": ENTITY_1, attribute: value} +@pytest.mark.parametrize( + ("service", "attribute"), + [ + (SERVICE_SET_PRESET_MODE, ATTR_PRESET_MODE), + (SERVICE_SET_SWING_MODE, ATTR_SWING_MODE), + (SERVICE_SET_FAN_MODE, ATTR_FAN_MODE), + ], +) +async def test_attribute_with_none(hass: HomeAssistant, service, attribute) -> None: + """Test that service call is not made for attributes with None value.""" + calls_1 = async_mock_service(hass, DOMAIN, service) + + await async_reproduce_states(hass, [State(ENTITY_1, None, {attribute: None})]) + + await hass.async_block_till_done() + + assert len(calls_1) == 0 + + async def test_attribute_partial_temperature(hass: HomeAssistant) -> None: """Test that service call ignores null attributes.""" calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE)