mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix climate HVAC device condition (#69908)
This commit is contained in:
parent
67b200a532
commit
d1f4b7a3d9
@ -75,15 +75,19 @@ def async_condition_from_config(
|
|||||||
hass: HomeAssistant, config: ConfigType
|
hass: HomeAssistant, config: ConfigType
|
||||||
) -> condition.ConditionCheckerType:
|
) -> condition.ConditionCheckerType:
|
||||||
"""Create a function to test a device condition."""
|
"""Create a function to test a device condition."""
|
||||||
if config[CONF_TYPE] == "is_hvac_mode":
|
|
||||||
attribute = const.ATTR_HVAC_MODE
|
|
||||||
else:
|
|
||||||
attribute = const.ATTR_PRESET_MODE
|
|
||||||
|
|
||||||
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
|
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
|
||||||
"""Test if an entity is a certain state."""
|
"""Test if an entity is a certain state."""
|
||||||
state = hass.states.get(config[ATTR_ENTITY_ID])
|
if (state := hass.states.get(config[ATTR_ENTITY_ID])) is None:
|
||||||
return state.attributes.get(attribute) == config[attribute] if state else False
|
return False
|
||||||
|
|
||||||
|
if config[CONF_TYPE] == "is_hvac_mode":
|
||||||
|
return state.state == config[const.ATTR_HVAC_MODE]
|
||||||
|
|
||||||
|
return (
|
||||||
|
state.attributes.get(const.ATTR_PRESET_MODE)
|
||||||
|
== config[const.ATTR_PRESET_MODE]
|
||||||
|
)
|
||||||
|
|
||||||
return test_is_state
|
return test_is_state
|
||||||
|
|
||||||
|
@ -102,15 +102,6 @@ async def test_get_conditions(
|
|||||||
|
|
||||||
async def test_if_state(hass, calls):
|
async def test_if_state(hass, calls):
|
||||||
"""Test for turn_on and turn_off conditions."""
|
"""Test for turn_on and turn_off conditions."""
|
||||||
hass.states.async_set(
|
|
||||||
"climate.entity",
|
|
||||||
const.HVAC_MODE_COOL,
|
|
||||||
{
|
|
||||||
const.ATTR_HVAC_MODE: const.HVAC_MODE_COOL,
|
|
||||||
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
automation.DOMAIN,
|
automation.DOMAIN,
|
||||||
@ -157,6 +148,20 @@ async def test_if_state(hass, calls):
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Should not fire, entity doesn't exist yet
|
||||||
|
hass.bus.async_fire("test_event1")
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
hass.states.async_set(
|
||||||
|
"climate.entity",
|
||||||
|
const.HVAC_MODE_COOL,
|
||||||
|
{
|
||||||
|
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
hass.bus.async_fire("test_event1")
|
hass.bus.async_fire("test_event1")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
@ -166,7 +171,6 @@ async def test_if_state(hass, calls):
|
|||||||
"climate.entity",
|
"climate.entity",
|
||||||
const.HVAC_MODE_AUTO,
|
const.HVAC_MODE_AUTO,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_MODE: const.HVAC_MODE_AUTO,
|
|
||||||
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
|
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -186,7 +190,6 @@ async def test_if_state(hass, calls):
|
|||||||
"climate.entity",
|
"climate.entity",
|
||||||
const.HVAC_MODE_AUTO,
|
const.HVAC_MODE_AUTO,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_MODE: const.HVAC_MODE_AUTO,
|
|
||||||
const.ATTR_PRESET_MODE: const.PRESET_HOME,
|
const.ATTR_PRESET_MODE: const.PRESET_HOME,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user