mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 17:18:23 +00:00
Fix reproduce state
This commit is contained in:
parent
a63c30a1a2
commit
3a256c4a30
@ -20,6 +20,8 @@ from homeassistant.core import Context, HomeAssistant, State
|
|||||||
from . import (
|
from . import (
|
||||||
ATTR_AWAY_MODE,
|
ATTR_AWAY_MODE,
|
||||||
ATTR_OPERATION_MODE,
|
ATTR_OPERATION_MODE,
|
||||||
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
|
ATTR_TARGET_TEMP_LOW,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_SET_AWAY_MODE,
|
SERVICE_SET_AWAY_MODE,
|
||||||
SERVICE_SET_OPERATION_MODE,
|
SERVICE_SET_OPERATION_MODE,
|
||||||
@ -69,6 +71,10 @@ async def _async_reproduce_state(
|
|||||||
cur_state.state == state.state
|
cur_state.state == state.state
|
||||||
and cur_state.attributes.get(ATTR_TEMPERATURE)
|
and cur_state.attributes.get(ATTR_TEMPERATURE)
|
||||||
== state.attributes.get(ATTR_TEMPERATURE)
|
== state.attributes.get(ATTR_TEMPERATURE)
|
||||||
|
and cur_state.attributes.get(ATTR_TARGET_TEMP_LOW)
|
||||||
|
== state.attributes.get(ATTR_TARGET_TEMP_LOW)
|
||||||
|
and cur_state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
|
== state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
and cur_state.attributes.get(ATTR_AWAY_MODE)
|
and cur_state.attributes.get(ATTR_AWAY_MODE)
|
||||||
== state.attributes.get(ATTR_AWAY_MODE)
|
== state.attributes.get(ATTR_AWAY_MODE)
|
||||||
):
|
):
|
||||||
@ -89,6 +95,25 @@ async def _async_reproduce_state(
|
|||||||
DOMAIN, service, service_data, context=context, blocking=True
|
DOMAIN, service, service_data, context=context, blocking=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
(temp_low := state.attributes.get(ATTR_TARGET_TEMP_LOW)) is not None
|
||||||
|
and temp_low != cur_state.attributes.get(ATTR_TARGET_TEMP_LOW)
|
||||||
|
) or (
|
||||||
|
(temp_high := state.attributes.get(ATTR_TARGET_TEMP_HIGH)) is not None
|
||||||
|
and temp_high != cur_state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
|
):
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: state.entity_id,
|
||||||
|
ATTR_TARGET_TEMP_HIGH: state.attributes.get(ATTR_TARGET_TEMP_HIGH),
|
||||||
|
ATTR_TARGET_TEMP_LOW: state.attributes.get(ATTR_TARGET_TEMP_LOW),
|
||||||
|
},
|
||||||
|
context=context,
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
state.attributes.get(ATTR_TEMPERATURE)
|
state.attributes.get(ATTR_TEMPERATURE)
|
||||||
!= cur_state.attributes.get(ATTR_TEMPERATURE)
|
!= cur_state.attributes.get(ATTR_TEMPERATURE)
|
||||||
|
@ -5,6 +5,8 @@ import pytest
|
|||||||
from homeassistant.components.water_heater import (
|
from homeassistant.components.water_heater import (
|
||||||
ATTR_AWAY_MODE,
|
ATTR_AWAY_MODE,
|
||||||
ATTR_OPERATION_MODE,
|
ATTR_OPERATION_MODE,
|
||||||
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
|
ATTR_TARGET_TEMP_LOW,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
SERVICE_SET_AWAY_MODE,
|
SERVICE_SET_AWAY_MODE,
|
||||||
SERVICE_SET_OPERATION_MODE,
|
SERVICE_SET_OPERATION_MODE,
|
||||||
@ -25,6 +27,11 @@ async def test_reproducing_states(
|
|||||||
"""Test reproducing Water heater states."""
|
"""Test reproducing Water heater states."""
|
||||||
hass.states.async_set("water_heater.entity_off", STATE_OFF, {})
|
hass.states.async_set("water_heater.entity_off", STATE_OFF, {})
|
||||||
hass.states.async_set("water_heater.entity_on", STATE_ON, {ATTR_TEMPERATURE: 45})
|
hass.states.async_set("water_heater.entity_on", STATE_ON, {ATTR_TEMPERATURE: 45})
|
||||||
|
hass.states.async_set(
|
||||||
|
"water_heater.entity_range",
|
||||||
|
STATE_ON,
|
||||||
|
{ATTR_TARGET_TEMP_HIGH: 45, ATTR_TARGET_TEMP_LOW: 20},
|
||||||
|
)
|
||||||
hass.states.async_set("water_heater.entity_away", STATE_ON, {ATTR_AWAY_MODE: True})
|
hass.states.async_set("water_heater.entity_away", STATE_ON, {ATTR_AWAY_MODE: True})
|
||||||
hass.states.async_set("water_heater.entity_gas", STATE_GAS, {})
|
hass.states.async_set("water_heater.entity_gas", STATE_GAS, {})
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
@ -45,6 +52,11 @@ async def test_reproducing_states(
|
|||||||
[
|
[
|
||||||
State("water_heater.entity_off", STATE_OFF),
|
State("water_heater.entity_off", STATE_OFF),
|
||||||
State("water_heater.entity_on", STATE_ON, {ATTR_TEMPERATURE: 45}),
|
State("water_heater.entity_on", STATE_ON, {ATTR_TEMPERATURE: 45}),
|
||||||
|
State(
|
||||||
|
"water_heater.entity_range",
|
||||||
|
STATE_ON,
|
||||||
|
{ATTR_TARGET_TEMP_HIGH: 45, ATTR_TARGET_TEMP_LOW: 20},
|
||||||
|
),
|
||||||
State("water_heater.entity_away", STATE_ON, {ATTR_AWAY_MODE: True}),
|
State("water_heater.entity_away", STATE_ON, {ATTR_AWAY_MODE: True}),
|
||||||
State("water_heater.entity_gas", STATE_GAS, {}),
|
State("water_heater.entity_gas", STATE_GAS, {}),
|
||||||
State(
|
State(
|
||||||
@ -79,6 +91,11 @@ async def test_reproducing_states(
|
|||||||
[
|
[
|
||||||
State("water_heater.entity_on", STATE_OFF),
|
State("water_heater.entity_on", STATE_OFF),
|
||||||
State("water_heater.entity_off", STATE_ON, {ATTR_TEMPERATURE: 45}),
|
State("water_heater.entity_off", STATE_ON, {ATTR_TEMPERATURE: 45}),
|
||||||
|
State(
|
||||||
|
"water_heater.entity_range",
|
||||||
|
STATE_ON,
|
||||||
|
{ATTR_TARGET_TEMP_HIGH: 50, ATTR_TARGET_TEMP_LOW: 20},
|
||||||
|
),
|
||||||
State("water_heater.entity_all", STATE_ECO, {ATTR_AWAY_MODE: False}),
|
State("water_heater.entity_all", STATE_ECO, {ATTR_AWAY_MODE: False}),
|
||||||
State("water_heater.entity_away", STATE_GAS, {}),
|
State("water_heater.entity_away", STATE_GAS, {}),
|
||||||
State(
|
State(
|
||||||
@ -112,8 +129,13 @@ async def test_reproducing_states(
|
|||||||
valid_temp_calls = [
|
valid_temp_calls = [
|
||||||
{"entity_id": "water_heater.entity_off", ATTR_TEMPERATURE: 45},
|
{"entity_id": "water_heater.entity_off", ATTR_TEMPERATURE: 45},
|
||||||
{"entity_id": "water_heater.entity_gas", ATTR_TEMPERATURE: 45},
|
{"entity_id": "water_heater.entity_gas", ATTR_TEMPERATURE: 45},
|
||||||
|
{
|
||||||
|
"entity_id": "water_heater.entity_range",
|
||||||
|
ATTR_TARGET_TEMP_HIGH: 50,
|
||||||
|
ATTR_TARGET_TEMP_LOW: 20,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
assert len(set_temp_calls) == 2
|
assert len(set_temp_calls) == 3
|
||||||
for call in set_temp_calls:
|
for call in set_temp_calls:
|
||||||
assert call.domain == "water_heater"
|
assert call.domain == "water_heater"
|
||||||
assert call.data in valid_temp_calls
|
assert call.data in valid_temp_calls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user