diff --git a/homeassistant/components/climate/reproduce_state.py b/homeassistant/components/climate/reproduce_state.py index d38e243cb62..e0e8022561b 100644 --- a/homeassistant/components/climate/reproduce_state.py +++ b/homeassistant/components/climate/reproduce_state.py @@ -57,9 +57,9 @@ async def _async_reproduce_states( await call_service(SERVICE_SET_HVAC_MODE, [], {ATTR_HVAC_MODE: state.state}) if ( - (ATTR_TEMPERATURE in state.attributes) - or (ATTR_TARGET_TEMP_HIGH in state.attributes) - or (ATTR_TARGET_TEMP_LOW in state.attributes) + (ATTR_TEMPERATURE in state.attributes and state.attributes[ATTR_TEMPERATURE] is not None) + or (ATTR_TARGET_TEMP_HIGH in state.attributes and state.attributes[ATTR_TARGET_TEMP_HIGH] is not None) + or (ATTR_TARGET_TEMP_LOW in state.attributes and state.attributes[ATTR_TARGET_TEMP_LOW] is not None) ): await call_service( SERVICE_SET_TEMPERATURE, diff --git a/tests/components/climate/test_reproduce_state.py b/tests/components/climate/test_reproduce_state.py index 3bc91467f14..b9e152f84d1 100644 --- a/tests/components/climate/test_reproduce_state.py +++ b/tests/components/climate/test_reproduce_state.py @@ -192,3 +192,33 @@ async def test_attribute_partial_high_low_temperature(hass: HomeAssistant) -> No ATTR_TARGET_TEMP_HIGH: 30.1, ATTR_TARGET_TEMP_LOW: 20.2, } + + +async def test_all_temperature_attributes_none(hass: HomeAssistant) -> None: + """Test that set_temperature service is not called when all temperature attributes are None.""" + calls_temp = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE) + calls_hvac = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE) + + await async_reproduce_states( + hass, + [ + State( + ENTITY_1, + HVACMode.OFF, + { + ATTR_TEMPERATURE: None, + ATTR_TARGET_TEMP_HIGH: None, + ATTR_TARGET_TEMP_LOW: None, + }, + ) + ], + ) + + await hass.async_block_till_done() + + # Should call set_hvac_mode with OFF but not call set_temperature + assert len(calls_hvac) == 1 + assert calls_hvac[0].data == {"entity_id": ENTITY_1, "hvac_mode": HVACMode.OFF} + + # Should NOT call set_temperature when all temperature attributes are None + assert len(calls_temp) == 0