mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Fix zwave_js device automation bug (#71715)
This commit is contained in:
parent
1f53786e1b
commit
a19a88db63
@ -8,6 +8,12 @@ from zwave_js_server.const import ConfigurationValueType
|
||||
from zwave_js_server.model.node import Node
|
||||
from zwave_js_server.model.value import ConfigurationValue
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
NODE_STATUSES = ["asleep", "awake", "dead", "alive"]
|
||||
|
||||
CONF_SUBTYPE = "subtype"
|
||||
@ -41,3 +47,21 @@ def generate_config_parameter_subtype(config_value: ConfigurationValue) -> str:
|
||||
parameter = f"{parameter}[{hex(config_value.property_key)}]"
|
||||
|
||||
return f"{parameter} ({config_value.property_name})"
|
||||
|
||||
|
||||
@callback
|
||||
def async_bypass_dynamic_config_validation(hass: HomeAssistant, device_id: str) -> bool:
|
||||
"""Return whether device's config entries are not loaded."""
|
||||
dev_reg = dr.async_get(hass)
|
||||
if (device := dev_reg.async_get(device_id)) is None:
|
||||
raise ValueError(f"Device {device_id} not found")
|
||||
entry = next(
|
||||
(
|
||||
config_entry
|
||||
for config_entry in hass.config_entries.async_entries(DOMAIN)
|
||||
if config_entry.entry_id in device.config_entries
|
||||
and config_entry.state == ConfigEntryState.LOADED
|
||||
),
|
||||
None,
|
||||
)
|
||||
return not entry
|
||||
|
@ -29,12 +29,12 @@ from .device_automation_helpers import (
|
||||
CONF_SUBTYPE,
|
||||
CONF_VALUE_ID,
|
||||
NODE_STATUSES,
|
||||
async_bypass_dynamic_config_validation,
|
||||
generate_config_parameter_subtype,
|
||||
get_config_parameter_value_schema,
|
||||
)
|
||||
from .helpers import (
|
||||
async_get_node_from_device_id,
|
||||
async_is_device_config_entry_not_loaded,
|
||||
check_type_schema_map,
|
||||
get_zwave_value_from_config,
|
||||
remove_keys_with_empty_values,
|
||||
@ -101,7 +101,7 @@ 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
|
||||
try:
|
||||
device_config_entry_not_loaded = async_is_device_config_entry_not_loaded(
|
||||
bypass_dynamic_config_validation = async_bypass_dynamic_config_validation(
|
||||
hass, config[CONF_DEVICE_ID]
|
||||
)
|
||||
except ValueError as err:
|
||||
@ -109,7 +109,7 @@ async def async_validate_condition_config(
|
||||
f"Device {config[CONF_DEVICE_ID]} not found"
|
||||
) from err
|
||||
|
||||
if device_config_entry_not_loaded:
|
||||
if bypass_dynamic_config_validation:
|
||||
return config
|
||||
|
||||
if config[CONF_TYPE] == VALUE_TYPE:
|
||||
|
@ -53,12 +53,12 @@ from .const import (
|
||||
from .device_automation_helpers import (
|
||||
CONF_SUBTYPE,
|
||||
NODE_STATUSES,
|
||||
async_bypass_dynamic_config_validation,
|
||||
generate_config_parameter_subtype,
|
||||
)
|
||||
from .helpers import (
|
||||
async_get_node_from_device_id,
|
||||
async_get_node_status_sensor_entity_id,
|
||||
async_is_device_config_entry_not_loaded,
|
||||
check_type_schema_map,
|
||||
copy_available_params,
|
||||
get_value_state_schema,
|
||||
@ -215,7 +215,7 @@ 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
|
||||
try:
|
||||
device_config_entry_not_loaded = async_is_device_config_entry_not_loaded(
|
||||
bypass_dynamic_config_validation = async_bypass_dynamic_config_validation(
|
||||
hass, config[CONF_DEVICE_ID]
|
||||
)
|
||||
except ValueError as err:
|
||||
@ -223,7 +223,7 @@ async def async_validate_trigger_config(
|
||||
f"Device {config[CONF_DEVICE_ID]} not found"
|
||||
) from err
|
||||
|
||||
if device_config_entry_not_loaded:
|
||||
if bypass_dynamic_config_validation:
|
||||
return config
|
||||
|
||||
trigger_type = config[CONF_TYPE]
|
||||
|
Loading…
x
Reference in New Issue
Block a user