Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions homeassistant/components/climate/reproduce_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,22 @@ async def call_service(
[ATTR_TEMPERATURE, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW],
)

if ATTR_PRESET_MODE in state.attributes:
if (
ATTR_PRESET_MODE in state.attributes
and state.attributes[ATTR_PRESET_MODE] is not None
):
await call_service(SERVICE_SET_PRESET_MODE, [ATTR_PRESET_MODE])

if ATTR_SWING_MODE in state.attributes:
if (
ATTR_SWING_MODE in state.attributes
and state.attributes[ATTR_SWING_MODE] is not None
):
await call_service(SERVICE_SET_SWING_MODE, [ATTR_SWING_MODE])

if ATTR_FAN_MODE in state.attributes:
if (
ATTR_FAN_MODE in state.attributes
and state.attributes[ATTR_FAN_MODE] is not None
):
await call_service(SERVICE_SET_FAN_MODE, [ATTR_FAN_MODE])

if ATTR_HUMIDITY in state.attributes:
Expand Down
19 changes: 19 additions & 0 deletions tests/components/climate/test_reproduce_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ async def test_attribute(hass: HomeAssistant, service, attribute) -> None:
assert calls_1[0].data == {"entity_id": ENTITY_1, attribute: value}


@pytest.mark.parametrize(
("service", "attribute"),
[
(SERVICE_SET_PRESET_MODE, ATTR_PRESET_MODE),
(SERVICE_SET_SWING_MODE, ATTR_SWING_MODE),
(SERVICE_SET_FAN_MODE, ATTR_FAN_MODE),
],
)
async def test_attribute_with_none(hass: HomeAssistant, service, attribute) -> None:
"""Test that service call is not made for attributes with None value."""
calls_1 = async_mock_service(hass, DOMAIN, service)

await async_reproduce_states(hass, [State(ENTITY_1, None, {attribute: None})])

await hass.async_block_till_done()

assert len(calls_1) == 0


async def test_attribute_partial_temperature(hass: HomeAssistant) -> None:
"""Test that service call ignores null attributes."""
calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE)
Expand Down