diff --git a/homeassistant/components/climate/reproduce_state.py b/homeassistant/components/climate/reproduce_state.py index 767a38b2e57449..f7e63f475ea885 100644 --- a/homeassistant/components/climate/reproduce_state.py +++ b/homeassistant/components/climate/reproduce_state.py @@ -41,8 +41,8 @@ async def call_service(service: str, keys: Iterable, data=None): data = data or {} data["entity_id"] = state.entity_id for key in keys: - if key in state.attributes: - data[key] = state.attributes[key] + if (value := state.attributes.get(key)) is not None: + data[key] = value await hass.services.async_call( DOMAIN, service, data, blocking=True, context=context diff --git a/tests/components/climate/test_reproduce_state.py b/tests/components/climate/test_reproduce_state.py index bdcf0441b9fed4..af1b14299ae5a4 100644 --- a/tests/components/climate/test_reproduce_state.py +++ b/tests/components/climate/test_reproduce_state.py @@ -117,3 +117,57 @@ async def test_attribute(hass, service, attribute): assert len(calls_1) == 1 assert calls_1[0].data == {"entity_id": ENTITY_1, attribute: value} + + +async def test_attribute_partial_temperature(hass): + """Test that service call ignores null attributes.""" + calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE) + + await async_reproduce_states( + hass, + [ + State( + ENTITY_1, + None, + { + ATTR_TEMPERATURE: 23.1, + ATTR_TARGET_TEMP_HIGH: None, + ATTR_TARGET_TEMP_LOW: None, + }, + ) + ], + ) + + await hass.async_block_till_done() + + assert len(calls_1) == 1 + assert calls_1[0].data == {"entity_id": ENTITY_1, ATTR_TEMPERATURE: 23.1} + + +async def test_attribute_partial_high_low_temperature(hass): + """Test that service call ignores null attributes.""" + calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE) + + await async_reproduce_states( + hass, + [ + State( + ENTITY_1, + None, + { + ATTR_TEMPERATURE: None, + ATTR_TARGET_TEMP_HIGH: 30.1, + ATTR_TARGET_TEMP_LOW: 20.2, + }, + ) + ], + ) + + await hass.async_block_till_done() + + assert len(calls_1) == 1 + assert calls_1[0].data == { + "entity_id": ENTITY_1, + ATTR_TARGET_TEMP_HIGH: 30.1, + ATTR_TARGET_TEMP_LOW: 20.2, + }