Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion homeassistant/components/zwave_js/device_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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

if config[CONF_TYPE] == VALUE_TYPE:
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/zwave_js/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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

trigger_type = config[CONF_TYPE]
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/zwave_js/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ def async_is_device_config_entry_not_loaded(
"""Return whether device's config entries are not loaded."""
dev_reg = dr.async_get(hass)
device = dev_reg.async_get(device_id)
assert device
if device is None:
raise ValueError(f"Device {device_id} not found")
return any(
(entry := hass.config_entries.async_get_entry(entry_id))
and entry.state != ConfigEntryState.LOADED
Expand Down
17 changes: 17 additions & 0 deletions tests/components/zwave_js/test_device_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,23 @@ async def test_failure_scenarios(hass, client, hank_binary_switch, integration):
== 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(
hass, client, hank_binary_switch, integration
Expand Down
16 changes: 16 additions & 0 deletions tests/components/zwave_js/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
== 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,
},
)