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 = data or {}
|
||||||
data["entity_id"] = state.entity_id
|
data["entity_id"] = state.entity_id
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key in state.attributes:
|
if (value := state.attributes.get(key)) is not None:
|
||||||
data[key] = state.attributes[key]
|
data[key] = value
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, service, data, blocking=True, context=context
|
DOMAIN, service, data, blocking=True, context=context
|
||||||
|
|
|
@ -117,3 +117,57 @@ async def test_attribute(hass, service, attribute):
|
||||||
|
|
||||||
assert len(calls_1) == 1
|
assert len(calls_1) == 1
|
||||||
assert calls_1[0].data == {"entity_id": ENTITY_1, attribute: value}
|
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
Add a link
Reference in a new issue