Skip to content

Commit

Permalink
Skip 'None' values when restoring climate scenes (#53484)
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter authored Jul 28, 2021
1 parent 68945e8 commit 1c20eb3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/climate/reproduce_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions tests/components/climate/test_reproduce_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit 1c20eb3

Please sign in to comment.