Raise when zwave_js device automation fails validation (#65610)
parent
3babc43fa5
commit
9eeaec4f79
|
@ -99,7 +99,16 @@ async def async_validate_condition_config(
|
||||||
|
|
||||||
# We return early if the config entry for this device is not ready because we can't
|
# We return early if the config entry for this device is not ready because we can't
|
||||||
# validate the value without knowing the state of the device
|
# validate the value without knowing the state of the device
|
||||||
if async_is_device_config_entry_not_loaded(hass, config[CONF_DEVICE_ID]):
|
try:
|
||||||
|
device_config_entry_not_loaded = async_is_device_config_entry_not_loaded(
|
||||||
|
hass, config[CONF_DEVICE_ID]
|
||||||
|
)
|
||||||
|
except ValueError as err:
|
||||||
|
raise InvalidDeviceAutomationConfig(
|
||||||
|
f"Device {config[CONF_DEVICE_ID]} not found"
|
||||||
|
) from err
|
||||||
|
|
||||||
|
if device_config_entry_not_loaded:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
if config[CONF_TYPE] == VALUE_TYPE:
|
if config[CONF_TYPE] == VALUE_TYPE:
|
||||||
|
|
|
@ -217,7 +217,16 @@ async def async_validate_trigger_config(
|
||||||
|
|
||||||
# We return early if the config entry for this device is not ready because we can't
|
# We return early if the config entry for this device is not ready because we can't
|
||||||
# validate the value without knowing the state of the device
|
# validate the value without knowing the state of the device
|
||||||
if async_is_device_config_entry_not_loaded(hass, config[CONF_DEVICE_ID]):
|
try:
|
||||||
|
device_config_entry_not_loaded = async_is_device_config_entry_not_loaded(
|
||||||
|
hass, config[CONF_DEVICE_ID]
|
||||||
|
)
|
||||||
|
except ValueError as err:
|
||||||
|
raise InvalidDeviceAutomationConfig(
|
||||||
|
f"Device {config[CONF_DEVICE_ID]} not found"
|
||||||
|
) from err
|
||||||
|
|
||||||
|
if device_config_entry_not_loaded:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
trigger_type = config[CONF_TYPE]
|
trigger_type = config[CONF_TYPE]
|
||||||
|
|
|
@ -298,7 +298,8 @@ def async_is_device_config_entry_not_loaded(
|
||||||
"""Return whether device's config entries are not loaded."""
|
"""Return whether device's config entries are not loaded."""
|
||||||
dev_reg = dr.async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
device = dev_reg.async_get(device_id)
|
device = dev_reg.async_get(device_id)
|
||||||
assert device
|
if device is None:
|
||||||
|
raise ValueError(f"Device {device_id} not found")
|
||||||
return any(
|
return any(
|
||||||
(entry := hass.config_entries.async_get_entry(entry_id))
|
(entry := hass.config_entries.async_get_entry(entry_id))
|
||||||
and entry.state != ConfigEntryState.LOADED
|
and entry.state != ConfigEntryState.LOADED
|
||||||
|
|
|
@ -596,6 +596,23 @@ async def test_failure_scenarios(hass, client, hank_binary_switch, integration):
|
||||||
== INVALID_CONFIG
|
== INVALID_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test invalid device ID fails validation
|
||||||
|
with pytest.raises(InvalidDeviceAutomationConfig):
|
||||||
|
await device_condition.async_validate_condition_config(
|
||||||
|
hass,
|
||||||
|
{
|
||||||
|
"condition": "device",
|
||||||
|
"domain": DOMAIN,
|
||||||
|
"type": "value",
|
||||||
|
"device_id": "invalid_device_id",
|
||||||
|
"command_class": CommandClass.DOOR_LOCK.value,
|
||||||
|
"property": 9999,
|
||||||
|
"property_key": 9999,
|
||||||
|
"endpoint": 9999,
|
||||||
|
"value": 9999,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_get_value_from_config_failure(
|
async def test_get_value_from_config_failure(
|
||||||
hass, client, hank_binary_switch, integration
|
hass, client, hank_binary_switch, integration
|
||||||
|
|
|
@ -1370,3 +1370,19 @@ async def test_failure_scenarios(hass, client, hank_binary_switch, integration):
|
||||||
await device_trigger.async_validate_trigger_config(hass, INVALID_CONFIG)
|
await device_trigger.async_validate_trigger_config(hass, INVALID_CONFIG)
|
||||||
== INVALID_CONFIG
|
== INVALID_CONFIG
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test invalid device ID fails validation
|
||||||
|
with pytest.raises(InvalidDeviceAutomationConfig):
|
||||||
|
await device_trigger.async_validate_trigger_config(
|
||||||
|
hass,
|
||||||
|
{
|
||||||
|
"platform": "device",
|
||||||
|
"domain": DOMAIN,
|
||||||
|
"device_id": "invalid_device_id",
|
||||||
|
"type": "zwave_js.value_updated.value",
|
||||||
|
"command_class": CommandClass.DOOR_LOCK.value,
|
||||||
|
"property": 9999,
|
||||||
|
"property_key": 9999,
|
||||||
|
"endpoint": 9999,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue