Skip 'None' values when restoring climate scenes (#53484)
This commit is contained in:
parent
68945e8814
commit
1c20eb3263
2 changed files with 56 additions and 2 deletions
|
@ -41,8 +41,8 @@ async def _async_reproduce_states(
|
|||
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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue