Add device automation condition (#26313)
* Add support for device conditions * Lint * Update test case * Make and+or conditions async, adjust tests * Cleanup tests * Remove non callback versions of conditions, correct typing * Correct typing * Update light/strings.json * Address review comments * Make device automation lists simple lists, not dicts * Add device_automation/const.py * Use IS_ON/IS_OFF everywhere for conditions
This commit is contained in:
1 parent
c50faaef3c
commit
f7dc537275
11 files changed
+480
-263
No files matched your search
@@ -21,7 +21,7 @@ def entity_reg(hass):
|
||||
return mock_registry(hass)
|
||||
|
||||
|
||||
def _same_triggers(a, b):
|
||||
def _same_lists(a, b):
|
||||
if len(a) != len(b):
|
||||
return False
|
||||
|
||||
@@ -31,6 +31,50 @@ def _same_triggers(a, b):
|
||||
return True
|
||||
|
||||
|
||||
async def test_websocket_get_conditions(hass, hass_ws_client, device_reg, entity_reg):
|
||||
"""Test we get the expected conditions from a light through websocket."""
|
||||
await async_setup_component(hass, "device_automation", {})
|
||||
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("light", "test", "5678", device_id=device_entry.id)
|
||||
expected_conditions = [
|
||||
{
|
||||
"condition": "device",
|
||||
"domain": "light",
|
||||
"type": "is_off",
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": "light.test_5678",
|
||||
},
|
||||
{
|
||||
"condition": "device",
|
||||
"domain": "light",
|
||||
"type": "is_on",
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": "light.test_5678",
|
||||
},
|
||||
]
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 1,
|
||||
"type": "device_automation/condition/list",
|
||||
"device_id": device_entry.id,
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["id"] == 1
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
conditions = msg["result"]
|
||||
assert _same_lists(conditions, expected_conditions)
|
||||
|
||||
|
||||
async def test_websocket_get_triggers(hass, hass_ws_client, device_reg, entity_reg):
|
||||
"""Test we get the expected triggers from a light through websocket."""
|
||||
await async_setup_component(hass, "device_automation", {})
|
||||
@@ -71,5 +115,5 @@ async def test_websocket_get_triggers(hass, hass_ws_client, device_reg, entity_r
|
||||
assert msg["id"] == 1
|
||||
assert msg["type"] == TYPE_RESULT
|
||||
assert msg["success"]
|
||||
triggers = msg["result"]["triggers"]
|
||||
assert _same_triggers(triggers, expected_triggers)
|
||||
triggers = msg["result"]
|
||||
assert _same_lists(triggers, expected_triggers)
|
||||
Reference in new issue
Block a user