Add zwave_js device triggers (#51968)
* Initial support for zwave_js device triggers * lint * Add node status changed trigger * comments * create helper function and simplify trigger logic * simplify code * fix exception * remove unused type ignore * switch to append to make future changes easier * make exception consistent * Add state config schema validation * comment * remove 0 from falsy check * increase test coverage * typos * Add central scene and scene activation value notification triggers * reorder things for readability and enumerate node statuses * Add support for Basic CC value notifications * fix schemas since additional fields on triggers aren't very flexible * pylint * remove extra logger statement * fix comment * dont use get when we know key will be available in dict * tweak text * use better schema for required extra fields that are ints * rename trigger types to make them easier to parse * fix strings * missed renaming of one trigger type * typo * Fix strings * reduce complexity * Use Al's suggestion for strings * add additional failure test cases * remove errant logging statement * make CC required * raise vol.Invalid when value ID isn't legit to prepare for next PR * Use helper function * fix tests * black
This commit is contained in:
parent
4d711898c7
commit
dd908caeba
8 changed files with 1970 additions and 1 deletions
|
@ -8,9 +8,11 @@ from zwave_js_server.client import Client as ZwaveClient
|
|||
from zwave_js_server.model.node import Node as ZwaveNode
|
||||
from zwave_js_server.model.value import Value as ZwaveValue, get_value_id
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import __version__ as HA_VERSION
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import (
|
||||
DeviceRegistry,
|
||||
async_get as async_get_dev_reg,
|
||||
|
@ -175,3 +177,35 @@ def get_zwave_value_from_config(node: ZwaveNode, config: ConfigType) -> ZwaveVal
|
|||
if value_id not in node.values:
|
||||
raise vol.Invalid(f"Value {value_id} can't be found on node {node}")
|
||||
return node.values[value_id]
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_node_status_sensor_entity_id(
|
||||
hass: HomeAssistant,
|
||||
device_id: str,
|
||||
ent_reg: EntityRegistry | None = None,
|
||||
dev_reg: DeviceRegistry | None = None,
|
||||
) -> str:
|
||||
"""Get the node status sensor entity ID for a given Z-Wave JS device."""
|
||||
if not ent_reg:
|
||||
ent_reg = async_get_ent_reg(hass)
|
||||
if not dev_reg:
|
||||
dev_reg = async_get_dev_reg(hass)
|
||||
device = dev_reg.async_get(device_id)
|
||||
if not device:
|
||||
raise HomeAssistantError("Invalid Device ID provided")
|
||||
|
||||
entry_id = next(entry_id for entry_id in device.config_entries)
|
||||
client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
|
||||
node = async_get_node_from_device_id(hass, device_id, dev_reg)
|
||||
entity_id = ent_reg.async_get_entity_id(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"{client.driver.controller.home_id}.{node.node_id}.node_status",
|
||||
)
|
||||
if not entity_id:
|
||||
raise HomeAssistantError(
|
||||
"Node status sensor entity not found. Device may not be a zwave_js device"
|
||||
)
|
||||
|
||||
return entity_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue