Bypass zwave_js config validation if driver not ready (#83410)

This commit is contained in:
Martin Hjelmare
2022-12-06 13:22:43 -05:00
committed by Paulus Schoutsen
parent 048553cd02
commit 1cfd292075
4 changed files with 149 additions and 9 deletions
@@ -1080,6 +1080,74 @@ async def test_if_value_updated_value_fires(
)
async def test_value_updated_value_no_driver(
hass, client, lock_schlage_be469, integration, calls
):
"""Test zwave_js.value_updated.value trigger with missing driver."""
node: Node = lock_schlage_be469
dev_reg = async_get_dev_reg(hass)
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
driver = client.driver
client.driver = None
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": device.id,
"type": "zwave_js.value_updated.value",
"command_class": CommandClass.DOOR_LOCK.value,
"property": "latchStatus",
"property_key": None,
"endpoint": None,
"from": "open",
},
"action": {
"service": "test.automation",
"data_template": {
"some": (
"zwave_js.value_updated.value - "
"{{ trigger.platform}} - "
"{{ trigger.previous_value }}"
)
},
},
},
]
},
)
await hass.async_block_till_done()
client.driver = driver
# No trigger as automation failed to setup.
event = Event(
type="value updated",
data={
"source": "node",
"event": "value updated",
"nodeId": node.node_id,
"args": {
"commandClassName": "Door Lock",
"commandClass": 98,
"endpoint": 0,
"property": "latchStatus",
"newValue": "closed",
"prevValue": "open",
"propertyName": "latchStatus",
},
},
)
node.receive_event(event)
await hass.async_block_till_done()
assert len(calls) == 0
async def test_get_trigger_capabilities_value_updated_value(
hass, client, lock_schlage_be469, integration
):
+59
View File
@@ -385,6 +385,65 @@ async def test_zwave_js_value_updated_bypass_dynamic_validation_no_nodes(
assert len(no_value_filter) == 0
async def test_zwave_js_value_updated_bypass_dynamic_validation_no_driver(
hass, client, lock_schlage_be469, integration
):
"""Test zwave_js.value_updated trigger without driver."""
trigger_type = f"{DOMAIN}.value_updated"
node: Node = lock_schlage_be469
driver = client.driver
client.driver = None
no_value_filter = async_capture_events(hass, "no_value_filter")
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
# no value filter
{
"trigger": {
"platform": trigger_type,
"entity_id": SCHLAGE_BE469_LOCK_ENTITY,
"command_class": CommandClass.DOOR_LOCK.value,
"property": "latchStatus",
},
"action": {
"event": "no_value_filter",
},
},
]
},
)
await hass.async_block_till_done()
client.driver = driver
# Test that no value filter is NOT triggered because automation failed setup
event = Event(
type="value updated",
data={
"source": "node",
"event": "value updated",
"nodeId": node.node_id,
"args": {
"commandClassName": "Door Lock",
"commandClass": 98,
"endpoint": 0,
"property": "latchStatus",
"newValue": "boo",
"prevValue": "hiss",
"propertyName": "latchStatus",
},
},
)
node.receive_event(event)
await hass.async_block_till_done()
assert len(no_value_filter) == 0
async def test_zwave_js_event(hass, client, lock_schlage_be469, integration):
"""Test for zwave_js.event automation trigger."""
trigger_type = f"{DOMAIN}.event"