mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Fix climate device actions (#28660)
* limit climate device actions * update test * use supported_features for device_action * Fix tests * user support_features for device_condition
This commit is contained in:
parent
ea6417bea3
commit
9a5dc848c9
@ -59,14 +59,15 @@ async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]:
|
|||||||
CONF_TYPE: "set_hvac_mode",
|
CONF_TYPE: "set_hvac_mode",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
actions.append(
|
if state.attributes["supported_features"] & const.SUPPORT_PRESET_MODE:
|
||||||
{
|
actions.append(
|
||||||
CONF_DEVICE_ID: device_id,
|
{
|
||||||
CONF_DOMAIN: DOMAIN,
|
CONF_DEVICE_ID: device_id,
|
||||||
CONF_ENTITY_ID: entry.entity_id,
|
CONF_DOMAIN: DOMAIN,
|
||||||
CONF_TYPE: "set_preset_mode",
|
CONF_ENTITY_ID: entry.entity_id,
|
||||||
}
|
CONF_TYPE: "set_preset_mode",
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ async def async_get_conditions(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if state and const.ATTR_PRESET_MODES in state.attributes:
|
if state and state.attributes["supported_features"] & const.SUPPORT_PRESET_MODE:
|
||||||
conditions.append(
|
conditions.append(
|
||||||
{
|
{
|
||||||
CONF_CONDITION: "device",
|
CONF_CONDITION: "device",
|
||||||
|
@ -39,6 +39,7 @@ async def test_get_actions(hass, device_reg, entity_reg):
|
|||||||
)
|
)
|
||||||
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
||||||
hass.states.async_set("climate.test_5678", const.HVAC_MODE_COOL, {})
|
hass.states.async_set("climate.test_5678", const.HVAC_MODE_COOL, {})
|
||||||
|
hass.states.async_set("climate.test_5678", "attributes", {"supported_features": 17})
|
||||||
expected_actions = [
|
expected_actions = [
|
||||||
{
|
{
|
||||||
"domain": DOMAIN,
|
"domain": DOMAIN,
|
||||||
@ -57,6 +58,29 @@ async def test_get_actions(hass, device_reg, entity_reg):
|
|||||||
assert_lists_same(actions, expected_actions)
|
assert_lists_same(actions, expected_actions)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_action_hvac_only(hass, device_reg, entity_reg):
|
||||||
|
"""Test we get the expected actions from a climate."""
|
||||||
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
device_entry = device_reg.async_get_or_create(
|
||||||
|
config_entry_id=config_entry.entry_id,
|
||||||
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||||
|
)
|
||||||
|
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
||||||
|
hass.states.async_set("climate.test_5678", const.HVAC_MODE_COOL, {})
|
||||||
|
hass.states.async_set("climate.test_5678", "attributes", {"supported_features": 1})
|
||||||
|
expected_actions = [
|
||||||
|
{
|
||||||
|
"domain": DOMAIN,
|
||||||
|
"type": "set_hvac_mode",
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
"entity_id": "climate.test_5678",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
actions = await async_get_device_automations(hass, "action", device_entry.id)
|
||||||
|
assert_lists_same(actions, expected_actions)
|
||||||
|
|
||||||
|
|
||||||
async def test_action(hass):
|
async def test_action(hass):
|
||||||
"""Test for actions."""
|
"""Test for actions."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
|
@ -53,6 +53,7 @@ async def test_get_conditions(hass, device_reg, entity_reg):
|
|||||||
const.ATTR_PRESET_MODES: [const.PRESET_HOME, const.PRESET_AWAY],
|
const.ATTR_PRESET_MODES: [const.PRESET_HOME, const.PRESET_AWAY],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
hass.states.async_set("climate.test_5678", "attributes", {"supported_features": 17})
|
||||||
expected_conditions = [
|
expected_conditions = [
|
||||||
{
|
{
|
||||||
"condition": "device",
|
"condition": "device",
|
||||||
@ -73,6 +74,38 @@ async def test_get_conditions(hass, device_reg, entity_reg):
|
|||||||
assert_lists_same(conditions, expected_conditions)
|
assert_lists_same(conditions, expected_conditions)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_get_conditions_hvac_only(hass, device_reg, entity_reg):
|
||||||
|
"""Test we get the expected conditions from a climate."""
|
||||||
|
config_entry = MockConfigEntry(domain="test", data={})
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
device_entry = device_reg.async_get_or_create(
|
||||||
|
config_entry_id=config_entry.entry_id,
|
||||||
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||||
|
)
|
||||||
|
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
||||||
|
hass.states.async_set(
|
||||||
|
f"{DOMAIN}.test_5678",
|
||||||
|
const.HVAC_MODE_COOL,
|
||||||
|
{
|
||||||
|
const.ATTR_HVAC_MODE: const.HVAC_MODE_COOL,
|
||||||
|
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
|
||||||
|
const.ATTR_PRESET_MODES: [const.PRESET_HOME, const.PRESET_AWAY],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
hass.states.async_set("climate.test_5678", "attributes", {"supported_features": 1})
|
||||||
|
expected_conditions = [
|
||||||
|
{
|
||||||
|
"condition": "device",
|
||||||
|
"domain": DOMAIN,
|
||||||
|
"type": "is_hvac_mode",
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
"entity_id": f"{DOMAIN}.test_5678",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
conditions = await async_get_device_automations(hass, "condition", device_entry.id)
|
||||||
|
assert_lists_same(conditions, expected_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(
|
hass.states.async_set(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user