Initial support for zwave_js device conditions (#52003)

This commit is contained in:
Raman Gupta 2021-07-12 00:22:33 -04:00 committed by GitHub
parent 2ddaf746e6
commit e652ef51a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 848 additions and 5 deletions

View file

@ -3,9 +3,10 @@ from __future__ import annotations
from typing import Any, cast
import voluptuous as vol
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
from zwave_js_server.model.value import Value as ZwaveValue, get_value_id
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import __version__ as HA_VERSION
@ -18,8 +19,17 @@ from homeassistant.helpers.entity_registry import (
EntityRegistry,
async_get as async_get_ent_reg,
)
from homeassistant.helpers.typing import ConfigType
from .const import CONF_DATA_COLLECTION_OPTED_IN, DATA_CLIENT, DOMAIN
from .const import (
ATTR_COMMAND_CLASS,
ATTR_ENDPOINT,
ATTR_PROPERTY,
ATTR_PROPERTY_KEY,
CONF_DATA_COLLECTION_OPTED_IN,
DATA_CLIENT,
DOMAIN,
)
@callback
@ -143,3 +153,23 @@ def async_get_node_from_entity_id(
# tied to a device
assert entity_entry.device_id
return async_get_node_from_device_id(hass, entity_entry.device_id, dev_reg)
def get_zwave_value_from_config(node: ZwaveNode, config: ConfigType) -> ZwaveValue:
"""Get a Z-Wave JS Value from a config."""
endpoint = None
if config.get(ATTR_ENDPOINT):
endpoint = config[ATTR_ENDPOINT]
property_key = None
if config.get(ATTR_PROPERTY_KEY):
property_key = config[ATTR_PROPERTY_KEY]
value_id = get_value_id(
node,
config[ATTR_COMMAND_CLASS],
config[ATTR_PROPERTY],
endpoint,
property_key,
)
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]