Revert "Refactor zwave discovery to entity schema (#6445)" (#6564)

This reverts commit 56abc7f9b4.
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2017-03-12 23:35:10 -07:00
1 parent 56abc7f9b4
commit 58826b264a
11 files changed
+565 -658

No files matched your search

+247 -187
View File
@@ -5,7 +5,6 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/zwave/
"""
import asyncio
import copy
import logging
import os.path
import time
@@ -30,8 +29,7 @@ from homeassistant.helpers.dispatcher import (
from . import const
from . import workaround
from .discovery_schemas import DISCOVERY_SCHEMAS
from .util import check_node_schema, check_value_schema
from .util import value_handler
REQUIREMENTS = ['pydispatcher==2.0.5']
@@ -66,6 +64,88 @@ DATA_ZWAVE_DICT = 'zwave_devices'
NETWORK = None
# List of tuple (DOMAIN, discovered service, supported command classes,
# value type, genre type, specific device class).
DISCOVERY_COMPONENTS = [
('sensor',
[const.GENERIC_TYPE_WHATEVER],
[const.SPECIFIC_TYPE_WHATEVER],
[const.COMMAND_CLASS_SENSOR_MULTILEVEL,
const.COMMAND_CLASS_METER,
const.COMMAND_CLASS_ALARM,
const.COMMAND_CLASS_SENSOR_ALARM,
const.COMMAND_CLASS_BATTERY],
const.TYPE_WHATEVER,
const.GENRE_USER),
('light',
[const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_SWITCH_REMOTE],
[const.SPECIFIC_TYPE_POWER_SWITCH_MULTILEVEL,
const.SPECIFIC_TYPE_SCENE_SWITCH_MULTILEVEL,
const.SPECIFIC_TYPE_NOT_USED],
[const.COMMAND_CLASS_SWITCH_MULTILEVEL],
const.TYPE_BYTE,
const.GENRE_USER),
('switch',
[const.GENERIC_TYPE_SENSOR_ALARM,
const.GENERIC_TYPE_SENSOR_BINARY,
const.GENERIC_TYPE_SWITCH_BINARY,
const.GENERIC_TYPE_ENTRY_CONTROL,
const.GENERIC_TYPE_SENSOR_MULTILEVEL,
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_SENSOR_NOTIFICATION,
const.GENERIC_TYPE_GENERIC_CONTROLLER,
const.GENERIC_TYPE_SWITCH_REMOTE,
const.GENERIC_TYPE_REPEATER_SLAVE,
const.GENERIC_TYPE_THERMOSTAT,
const.GENERIC_TYPE_WALL_CONTROLLER],
[const.SPECIFIC_TYPE_WHATEVER],
[const.COMMAND_CLASS_SWITCH_BINARY],
const.TYPE_BOOL,
const.GENRE_USER),
('binary_sensor',
[const.GENERIC_TYPE_SENSOR_ALARM,
const.GENERIC_TYPE_SENSOR_BINARY,
const.GENERIC_TYPE_SWITCH_BINARY,
const.GENERIC_TYPE_METER,
const.GENERIC_TYPE_SENSOR_MULTILEVEL,
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_SENSOR_NOTIFICATION,
const.GENERIC_TYPE_THERMOSTAT],
[const.SPECIFIC_TYPE_WHATEVER],
[const.COMMAND_CLASS_SENSOR_BINARY],
const.TYPE_BOOL,
const.GENRE_USER),
('lock',
[const.GENERIC_TYPE_ENTRY_CONTROL],
[const.SPECIFIC_TYPE_ADVANCED_DOOR_LOCK,
const.SPECIFIC_TYPE_SECURE_KEYPAD_DOOR_LOCK],
[const.COMMAND_CLASS_DOOR_LOCK],
const.TYPE_BOOL,
const.GENRE_USER),
('cover',
[const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_ENTRY_CONTROL],
[const.SPECIFIC_TYPE_CLASS_A_MOTOR_CONTROL,
const.SPECIFIC_TYPE_CLASS_B_MOTOR_CONTROL,
const.SPECIFIC_TYPE_CLASS_C_MOTOR_CONTROL,
const.SPECIFIC_TYPE_MOTOR_MULTIPOSITION,
const.SPECIFIC_TYPE_SECURE_BARRIER_ADDON,
const.SPECIFIC_TYPE_SECURE_DOOR],
[const.COMMAND_CLASS_SWITCH_BINARY,
const.COMMAND_CLASS_BARRIER_OPERATOR,
const.COMMAND_CLASS_SWITCH_MULTILEVEL],
const.TYPE_WHATEVER,
const.GENRE_USER),
('climate',
[const.GENERIC_TYPE_THERMOSTAT],
[const.SPECIFIC_TYPE_WHATEVER],
[const.COMMAND_CLASS_THERMOSTAT_SETPOINT],
const.TYPE_WHATEVER,
const.GENRE_WHATEVER),
]
RENAME_NODE_SCHEMA = vol.Schema({
vol.Required(ATTR_ENTITY_ID): cv.entity_id,
vol.Required(const.ATTR_NAME): cv.string,
@@ -278,25 +358,92 @@ def setup(hass, config):
dispatcher.connect(log_all, weak=False)
discovered_values = []
def value_added(node, value):
"""Called when a value is added to a node on the network."""
# Check if this value should be tracked by an existing entity
for values in discovered_values:
values.check_value(value)
for (component,
generic_device_class,
specific_device_class,
command_class,
value_type,
value_genre) in DISCOVERY_COMPONENTS:
for schema in DISCOVERY_SCHEMAS:
if not check_node_schema(node, schema):
_LOGGER.debug("Component=%s Node_id=%s query start",
component, node.node_id)
if node.generic not in generic_device_class and \
None not in generic_device_class:
_LOGGER.debug("node.generic %s not None and in "
"generic_device_class %s",
node.generic, generic_device_class)
continue
if not check_value_schema(
value,
schema[const.DISC_INSTANCE_VALUES][const.DISC_PRIMARY]):
if node.specific not in specific_device_class and \
None not in specific_device_class:
_LOGGER.debug("node.specific %s is not None and in "
"specific_device_class %s", node.specific,
specific_device_class)
continue
if value.command_class not in command_class and \
None not in command_class:
_LOGGER.debug("value.command_class %s is not None "
"and in command_class %s",
value.command_class, command_class)
continue
if value_type != value.type and value_type is not None:
_LOGGER.debug("value.type %s != value_type %s",
value.type, value_type)
continue
if value_genre != value.genre and value_genre is not None:
_LOGGER.debug("value.genre %s != value_genre %s",
value.genre, value_genre)
continue
values = ZWaveDeviceEntityValues(
hass, schema, value, config, device_config)
discovered_values.append(values)
# Configure node
_LOGGER.debug("Adding Node_id=%s Generic_command_class=%s, "
"Specific_command_class=%s, "
"Command_class=%s, Value type=%s, "
"Genre=%s as %s", node.node_id,
node.generic, node.specific,
value.command_class, value.type,
value.genre, component)
workaround_component = workaround.get_device_component_mapping(
value)
if workaround_component and workaround_component != component:
if workaround_component == workaround.WORKAROUND_IGNORE:
_LOGGER.info("Ignoring device %s due to workaround.",
"{}.{}".format(component, object_id(value)))
continue
_LOGGER.debug("Using %s instead of %s",
workaround_component, component)
component = workaround_component
name = "{}.{}".format(component, object_id(value))
node_config = device_config.get(name)
if node_config.get(CONF_IGNORED):
_LOGGER.info(
"Ignoring device %s due to device settings.", name)
return
polling_intensity = convert(
node_config.get(CONF_POLLING_INTENSITY), int)
if polling_intensity:
value.enable_poll(polling_intensity)
else:
value.disable_poll()
platform = get_platform(component, DOMAIN)
device = platform.get_device(
node=node, value=value, node_config=node_config, hass=hass)
if not device:
continue
dict_id = value.value_id
@asyncio.coroutine
def discover_device(component, device, dict_id):
"""Put device in a dictionary and call discovery on it."""
hass.data[DATA_ZWAVE_DICT][dict_id] = device
yield from discovery.async_load_platform(
hass, component, DOMAIN,
{const.DISCOVERY_DEVICE: dict_id}, config)
hass.add_job(discover_device, component, device, dict_id)
def scene_activated(node, scene_id):
"""Called when a scene is activated on any node in the network."""
@@ -605,166 +752,24 @@ def setup(hass, config):
return True
class ZWaveDeviceEntityValues():
"""Manages entity access to the underlying zwave value objects."""
def __init__(self, hass, schema, primary_value, zwave_config,
device_config):
"""Initialize the values object with the passed entity schema."""
self._hass = hass
self._zwave_config = zwave_config
self._device_config = device_config
self._schema = copy.deepcopy(schema)
self._values = {}
self._entity = None
self._workaround_ignore = False
# Combine node value schemas and instance value schemas into one
# values schema mapping.
self._schema[const.DISC_VALUES] = {}
for name in self._schema[const.DISC_NODE_VALUES].keys():
self._values[name] = None
self._schema[const.DISC_VALUES][name] = \
self._schema[const.DISC_NODE_VALUES][name]
for name in self._schema[const.DISC_INSTANCE_VALUES].keys():
self._values[name] = None
self._schema[const.DISC_VALUES][name] = \
self._schema[const.DISC_INSTANCE_VALUES][name]
self._schema[const.DISC_VALUES][name][const.DISC_INSTANCE] = \
[primary_value.instance]
self._values[const.DISC_PRIMARY] = primary_value
self._node = primary_value.node
self._schema[const.DISC_NODE_ID] = [self._node.node_id]
# Check values that have already been discovered for node
for value in self._node.values.values():
self.check_value(value)
self._check_entity_ready()
def __getattr__(self, name):
"""Get the specified value for this entity."""
return self._values[name]
def __iter__(self):
"""Allow iteration over all values."""
return iter(self._values.values())
def check_value(self, value):
"""Check if the new value matches a missing value for this entity.
If a match is found, it is added to the values mapping.
"""
if not check_node_schema(value.node, self._schema):
return
for name in self._values:
if self._values[name] is not None:
continue
if not check_value_schema(
value, self._schema[const.DISC_VALUES][name]):
continue
self._values[name] = value
if self._entity:
self._entity.value_changed()
self._check_entity_ready()
def _check_entity_ready(self):
"""Check if all required values are discovered and create entity."""
if self._workaround_ignore:
return
if self._entity is not None:
return
for name in self._schema[const.DISC_VALUES]:
if self._values[name] is None and \
not self._schema[const.DISC_VALUES][name].get(
const.DISC_OPTIONAL):
return
component = self._schema[const.DISC_COMPONENT]
workaround_component = workaround.get_device_component_mapping(
self.primary)
if workaround_component and workaround_component != component:
if workaround_component == workaround.WORKAROUND_IGNORE:
_LOGGER.info("Ignoring device %s due to workaround.",
"{}.{}".format(
component, object_id(self.primary)))
# No entity will be created for this value
self._workaround_ignore = True
return
_LOGGER.debug("Using %s instead of %s",
workaround_component, component)
component = workaround_component
name = "{}.{}".format(component, object_id(self.primary))
node_config = self._device_config.get(name)
# Configure node
_LOGGER.debug("Adding Node_id=%s Generic_command_class=%s, "
"Specific_command_class=%s, "
"Command_class=%s, Value type=%s, "
"Genre=%s as %s", self._node.node_id,
self._node.generic, self._node.specific,
self.primary.command_class, self.primary.type,
self.primary.genre, component)
if node_config.get(CONF_IGNORED):
_LOGGER.info(
"Ignoring node %s due to device settings.", self._node.node_id)
# No entity will be created for this value
self._workaround_ignore = True
return
polling_intensity = convert(
node_config.get(CONF_POLLING_INTENSITY), int)
if polling_intensity:
self.primary.enable_poll(polling_intensity)
else:
self.primary.disable_poll()
platform = get_platform(component, DOMAIN)
device = platform.get_device(
node=self._node, values=self,
node_config=node_config, hass=self._hass)
if not device:
# No entity will be created for this value
self._workaround_ignore = True
return
self._entity = device
dict_id = self.primary.value_id
@asyncio.coroutine
def discover_device(component, device, dict_id):
"""Put device in a dictionary and call discovery on it."""
self._hass.data[DATA_ZWAVE_DICT][dict_id] = device
yield from discovery.async_load_platform(
self._hass, component, DOMAIN,
{const.DISCOVERY_DEVICE: dict_id}, self._zwave_config)
self._hass.add_job(discover_device, component, device, dict_id)
class ZWaveDeviceEntity(Entity):
"""Representation of a Z-Wave node entity."""
def __init__(self, values, domain):
def __init__(self, value, domain):
"""Initialize the z-Wave device."""
# pylint: disable=import-error
from openzwave.network import ZWaveNetwork
from pydispatch import dispatcher
self.values = values
self.node = values.primary.node
self.values.primary.set_change_verified(False)
self.entity_id = "{}.{}".format(domain, object_id(values.primary))
self._value = value
self._value.set_change_verified(False)
self.entity_id = "{}.{}".format(domain, object_id(value))
self._name = _value_name(self.values.primary)
self._unique_id = "ZWAVE-{}-{}".format(self.node.node_id,
self.values.primary.object_id)
self._name = _value_name(self._value)
self._unique_id = "ZWAVE-{}-{}".format(self._value.node.node_id,
self._value.object_id)
self._wakeup_value_id = None
self._battery_value_id = None
self._power_value_id = None
self._update_scheduled = False
self._update_attributes()
@@ -773,11 +778,19 @@ class ZWaveDeviceEntity(Entity):
def network_value_changed(self, value):
"""Called when a value has changed on the network."""
if value.value_id in [v.value_id for v in self.values if v]:
if self._value.value_id == value.value_id:
return self.value_changed()
dependent_ids = self._get_dependent_value_ids()
if dependent_ids is None and self._value.node == value.node:
return self.value_changed()
if dependent_ids is not None and value.value_id in dependent_ids:
return self.value_changed()
def value_changed(self):
"""Called when a value for this entity's node has changed."""
if not self._value.node.is_ready:
self._update_ids()
self._update_attributes()
self.update_properties()
# If value changed after device was created but before setup_platform
@@ -785,6 +798,29 @@ class ZWaveDeviceEntity(Entity):
if self.hass and not self._update_scheduled:
self.hass.add_job(self._schedule_update)
def _update_ids(self):
"""Update value_ids from which to pull attributes."""
if self._wakeup_value_id is None:
self._wakeup_value_id = self.get_value(
class_id=const.COMMAND_CLASS_WAKE_UP, member='value_id')
if self._battery_value_id is None:
self._battery_value_id = self.get_value(
class_id=const.COMMAND_CLASS_BATTERY, member='value_id')
if self._power_value_id is None:
self._power_value_id = self.get_value(
class_id=[const.COMMAND_CLASS_SENSOR_MULTILEVEL,
const.COMMAND_CLASS_METER],
label=['Power'], member='value_id',
instance=self._value.instance)
@property
def dependent_value_ids(self):
"""List of value IDs a device depends on.
None if depends on the whole node.
"""
return []
@asyncio.coroutine
def async_added_to_hass(self):
"""Add device to dict."""
@@ -793,26 +829,45 @@ class ZWaveDeviceEntity(Entity):
SIGNAL_REFRESH_ENTITY_FORMAT.format(self.entity_id),
self.refresh_from_network)
def _get_dependent_value_ids(self):
"""Return a list of value_ids this device depend on.
Return None if it depends on the whole node.
"""
if self.dependent_value_ids is None:
# Device depends on node.
return None
if not self._value.node.is_ready:
# Node is not ready, so depend on the whole node.
return None
return [val for val in (self.dependent_value_ids + [
self._wakeup_value_id, self._battery_value_id,
self._power_value_id]) if val]
def _update_attributes(self):
"""Update the node attributes. May only be used inside callback."""
self.node_id = self.node.node_id
self.location = self.node.location
self.node_id = self._value.node.node_id
self.location = self._value.node.location
self.battery_level = self._value.node.get_battery_level(
self._battery_value_id)
self.wakeup_interval = None
if self._wakeup_value_id:
self.wakeup_interval = self._value.node.values[
self._wakeup_value_id].data
power_value = None
if self._power_value_id:
power_value = self._value.node.values[self._power_value_id]
self.power_consumption = round(
power_value.data, power_value.precision) if power_value else None
if self.values.battery:
self.battery_level = self.values.battery.data
else:
self.battery_level = None
def get_value(self, **kwargs):
"""Simplifyer to get values. May only be used inside callback."""
return value_handler(self._value, method='get', **kwargs)
if self.values.wakeup:
self.wakeup_interval = self.values.wakeup.data
else:
self.wakeup_interval = None
if self.values.power:
self.power_consumption = round(
self.values.power.data, self.values.power.precision)
else:
self.power_consumption = None
def set_value(self, **kwargs):
"""Simplifyer to set a value."""
return value_handler(self._value, method='set', **kwargs)
def update_properties(self):
"""Callback on data changes for node values."""
@@ -856,8 +911,13 @@ class ZWaveDeviceEntity(Entity):
def refresh_from_network(self):
"""Refresh all dependent values from zwave network."""
for value in self.values:
self.node.refresh_value(value.value_id)
dependent_ids = self._get_dependent_value_ids()
if dependent_ids is None:
# Entity depends on the whole node
self._value.node.refresh_info()
return
for value_id in dependent_ids + [self._value.value_id]:
self._value.node.refresh_value(value_id)
@callback
def _schedule_update(self):
-19
View File
@@ -311,22 +311,3 @@ TYPE_BOOL = "Bool"
TYPE_DECIMAL = "Decimal"
TYPE_INT = "Int"
TYPE_LIST = "List"
TYPE_STRING = "String"
DISC_COMMAND_CLASS = "command_class"
DISC_COMPONENT = "component"
DISC_GENERIC_DEVICE_CLASS = "generic_device_class"
DISC_GENRE = "genre"
DISC_INDEX = "index"
DISC_INSTANCE_VALUES = "instance_values"
DISC_INSTANCE = "instance"
DISC_LABEL = "label"
DISC_NODE_ID = "node_id"
DISC_NODE_VALUES = "node_values"
DISC_OPTIONAL = "optional"
DISC_PRIMARY = "primary"
DISC_READONLY = "readonly"
DISC_SPECIFIC_DEVICE_CLASS = "specific_device_class"
DISC_TYPE = "type"
DISC_VALUES = "values"
DISC_WRITEONLY = "writeonly"
@@ -1,220 +0,0 @@
"""Zwave discovery schemas."""
from . import const
DEFAULT_NODE_VALUES_SCHEMA = {
'wakeup': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_WAKE_UP],
const.DISC_GENRE: const.GENRE_USER,
const.DISC_OPTIONAL: True,
},
'battery': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_BATTERY],
const.DISC_OPTIONAL: True,
},
}
DEFAULT_INSTANCE_VALUES_SCHEMA = {
'power': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SENSOR_MULTILEVEL,
const.COMMAND_CLASS_METER],
const.DISC_LABEL: ['Power'],
const.DISC_OPTIONAL: True,
},
}
DISCOVERY_SCHEMAS = [
{const.DISC_COMPONENT: 'binary_sensor',
const.DISC_GENERIC_DEVICE_CLASS: [
const.GENERIC_TYPE_SENSOR_ALARM,
const.GENERIC_TYPE_SENSOR_BINARY,
const.GENERIC_TYPE_SWITCH_BINARY,
const.GENERIC_TYPE_METER,
const.GENERIC_TYPE_SENSOR_MULTILEVEL,
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_SENSOR_NOTIFICATION,
const.GENERIC_TYPE_THERMOSTAT],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SENSOR_BINARY],
const.DISC_TYPE: const.TYPE_BOOL,
const.DISC_GENRE: const.GENRE_USER
}})},
{const.DISC_COMPONENT: 'climate',
const.DISC_GENERIC_DEVICE_CLASS: [const.GENERIC_TYPE_THERMOSTAT],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [
const.COMMAND_CLASS_THERMOSTAT_SETPOINT],
},
'temperature': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SENSOR_MULTILEVEL],
const.DISC_LABEL: 'Temperature',
const.DISC_OPTIONAL: True,
},
'mode': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_THERMOSTAT_MODE],
const.DISC_OPTIONAL: True,
},
'fan_mode': {
const.DISC_COMMAND_CLASS: [
const.COMMAND_CLASS_THERMOSTAT_FAN_MODE],
const.DISC_OPTIONAL: True,
},
'operating_state': {
const.DISC_COMMAND_CLASS: [
const.COMMAND_CLASS_THERMOSTAT_OPERATING_STATE],
const.DISC_OPTIONAL: True,
},
'fan_state': {
const.DISC_COMMAND_CLASS: [
const.COMMAND_CLASS_THERMOSTAT_FAN_STATE],
const.DISC_OPTIONAL: True,
},
'zxt_120_swing_mode': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_CONFIGURATION],
const.DISC_INDEX: [33],
const.DISC_OPTIONAL: True,
}})},
{const.DISC_COMPONENT: 'cover', # Rollershutter
const.DISC_GENERIC_DEVICE_CLASS: [
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_ENTRY_CONTROL],
const.DISC_SPECIFIC_DEVICE_CLASS: [
const.SPECIFIC_TYPE_CLASS_A_MOTOR_CONTROL,
const.SPECIFIC_TYPE_CLASS_B_MOTOR_CONTROL,
const.SPECIFIC_TYPE_CLASS_C_MOTOR_CONTROL,
const.SPECIFIC_TYPE_MOTOR_MULTIPOSITION,
const.SPECIFIC_TYPE_SECURE_BARRIER_ADDON,
const.SPECIFIC_TYPE_SECURE_DOOR],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_MULTILEVEL],
const.DISC_GENRE: const.GENRE_USER,
},
'open': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_MULTILEVEL],
const.DISC_LABEL: ['Open', 'Up'],
const.DISC_OPTIONAL: True,
},
'close': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_MULTILEVEL],
const.DISC_LABEL: ['Close', 'Down'],
const.DISC_OPTIONAL: True,
}})},
{const.DISC_COMPONENT: 'cover', # Garage Door
const.DISC_GENERIC_DEVICE_CLASS: [
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_ENTRY_CONTROL],
const.DISC_SPECIFIC_DEVICE_CLASS: [
const.SPECIFIC_TYPE_CLASS_A_MOTOR_CONTROL,
const.SPECIFIC_TYPE_CLASS_B_MOTOR_CONTROL,
const.SPECIFIC_TYPE_CLASS_C_MOTOR_CONTROL,
const.SPECIFIC_TYPE_MOTOR_MULTIPOSITION,
const.SPECIFIC_TYPE_SECURE_BARRIER_ADDON,
const.SPECIFIC_TYPE_SECURE_DOOR],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [
const.COMMAND_CLASS_BARRIER_OPERATOR,
const.COMMAND_CLASS_SWITCH_BINARY],
const.DISC_GENRE: const.GENRE_USER,
}})},
{const.DISC_COMPONENT: 'light',
const.DISC_GENERIC_DEVICE_CLASS: [
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_SWITCH_REMOTE],
const.DISC_SPECIFIC_DEVICE_CLASS: [
const.SPECIFIC_TYPE_POWER_SWITCH_MULTILEVEL,
const.SPECIFIC_TYPE_SCENE_SWITCH_MULTILEVEL,
const.SPECIFIC_TYPE_NOT_USED],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_MULTILEVEL],
const.DISC_GENRE: const.GENRE_USER,
const.DISC_TYPE: const.TYPE_BYTE,
},
'color': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_COLOR],
const.DISC_GENRE: const.GENRE_USER,
const.DISC_TYPE: const.TYPE_STRING,
const.DISC_READONLY: False,
const.DISC_WRITEONLY: False,
const.DISC_OPTIONAL: True,
},
'color_channels': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_COLOR],
const.DISC_GENRE: const.GENRE_SYSTEM,
const.DISC_TYPE: const.TYPE_INT,
const.DISC_OPTIONAL: True,
}})},
{const.DISC_COMPONENT: 'lock',
const.DISC_GENERIC_DEVICE_CLASS: [const.GENERIC_TYPE_ENTRY_CONTROL],
const.DISC_SPECIFIC_DEVICE_CLASS: [
const.SPECIFIC_TYPE_ADVANCED_DOOR_LOCK,
const.SPECIFIC_TYPE_SECURE_KEYPAD_DOOR_LOCK],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_DOOR_LOCK],
const.DISC_TYPE: const.TYPE_BOOL,
const.DISC_GENRE: const.GENRE_USER,
},
'access_control': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_ALARM],
const.DISC_LABEL: 'Access Control',
const.DISC_OPTIONAL: True,
},
'alarm_type': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_ALARM],
const.DISC_LABEL: 'Alarm Type',
const.DISC_OPTIONAL: True,
},
'alarm_level': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_ALARM],
const.DISC_LABEL: 'Alarm Level',
const.DISC_OPTIONAL: True,
},
'v2btze_advanced': {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_CONFIGURATION],
const.DISC_INDEX: [12],
const.DISC_LABEL: 'Access Control',
const.DISC_OPTIONAL: True,
}})},
{const.DISC_COMPONENT: 'sensor',
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [
const.COMMAND_CLASS_SENSOR_MULTILEVEL,
const.COMMAND_CLASS_METER,
const.COMMAND_CLASS_ALARM,
const.COMMAND_CLASS_SENSOR_ALARM,
const.COMMAND_CLASS_BATTERY],
const.DISC_GENRE: const.GENRE_USER,
}})},
{const.DISC_COMPONENT: 'switch',
const.DISC_GENERIC_DEVICE_CLASS: [
const.GENERIC_TYPE_SENSOR_ALARM,
const.GENERIC_TYPE_SENSOR_BINARY,
const.GENERIC_TYPE_SWITCH_BINARY,
const.GENERIC_TYPE_ENTRY_CONTROL,
const.GENERIC_TYPE_SENSOR_MULTILEVEL,
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
const.GENERIC_TYPE_SENSOR_NOTIFICATION,
const.GENERIC_TYPE_GENERIC_CONTROLLER,
const.GENERIC_TYPE_SWITCH_REMOTE,
const.GENERIC_TYPE_REPEATER_SLAVE,
const.GENERIC_TYPE_THERMOSTAT,
const.GENERIC_TYPE_WALL_CONTROLLER],
const.DISC_NODE_VALUES: dict(DEFAULT_NODE_VALUES_SCHEMA),
const.DISC_INSTANCE_VALUES: dict(DEFAULT_INSTANCE_VALUES_SCHEMA, **{
const.DISC_PRIMARY: {
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_BINARY],
const.DISC_TYPE: const.TYPE_BOOL,
const.DISC_GENRE: const.GENRE_USER,
}})},
]
+46 -63
View File
@@ -1,71 +1,54 @@
"""Zwave util methods."""
import logging
from . import const
_LOGGER = logging.getLogger(__name__)
def check_node_schema(node, schema):
"""Check if node matches the passed node schema."""
if (const.DISC_NODE_ID in schema and
node.node_id not in schema[const.DISC_NODE_ID]):
_LOGGER.debug("node.node_id %s not in node_id %s",
node.node_id, schema[const.DISC_NODE_ID])
return False
if (const.DISC_GENERIC_DEVICE_CLASS in schema and
node.generic not in schema[const.DISC_GENERIC_DEVICE_CLASS]):
_LOGGER.debug("node.generic %s not in generic_device_class %s",
node.generic, schema[const.DISC_GENERIC_DEVICE_CLASS])
return False
if (const.DISC_SPECIFIC_DEVICE_CLASS in schema and
node.specific not in schema[const.DISC_SPECIFIC_DEVICE_CLASS]):
_LOGGER.debug("node.specific %s not in specific_device_class %s",
node.specific, schema[const.DISC_SPECIFIC_DEVICE_CLASS])
return False
return True
def value_handler(value, method=None, class_id=None, index=None,
label=None, data=None, member=None, instance=None,
**kwargs):
"""Get the values for a given command_class with arguments.
May only be used inside callback.
def check_value_schema(value, schema):
"""Check if the value matches the passed value schema."""
if (const.DISC_COMMAND_CLASS in schema and
value.command_class not in schema[const.DISC_COMMAND_CLASS]):
_LOGGER.debug("value.command_class %s not in command_class %s",
value.command_class, schema[const.DISC_COMMAND_CLASS])
return False
if (const.DISC_TYPE in schema and
value.type not in schema[const.DISC_TYPE]):
_LOGGER.debug("value.type %s not in type %s",
value.type, schema[const.DISC_TYPE])
return False
if (const.DISC_GENRE in schema and
value.genre not in schema[const.DISC_GENRE]):
_LOGGER.debug("value.genre %s not in genre %s",
value.genre, schema[const.DISC_GENRE])
return False
if (const.DISC_READONLY in schema and
value.is_read_only is not schema[const.DISC_READONLY]):
_LOGGER.debug("value.is_read_only %s not %s",
value.is_read_only, schema[const.DISC_READONLY])
return False
if (const.DISC_WRITEONLY in schema and
value.is_write_only is not schema[const.DISC_WRITEONLY]):
_LOGGER.debug("value.is_write_only %s not %s",
value.is_write_only, schema[const.DISC_WRITEONLY])
return False
if (const.DISC_LABEL in schema and
value.label not in schema[const.DISC_LABEL]):
_LOGGER.debug("value.label %s not in label %s",
value.label, schema[const.DISC_LABEL])
return False
if (const.DISC_INDEX in schema and
value.index not in schema[const.DISC_INDEX]):
_LOGGER.debug("value.index %s not in index %s",
value.index, schema[const.DISC_INDEX])
return False
if (const.DISC_INSTANCE in schema and
value.instance not in schema[const.DISC_INSTANCE]):
_LOGGER.debug("value.instance %s not in instance %s",
value.instance, schema[const.DISC_INSTANCE])
return False
return True
"""
values = []
if class_id is None:
values.extend(value.node.get_values(**kwargs).values())
else:
if not isinstance(class_id, list):
class_id = [class_id]
for cid in class_id:
values.extend(value.node.get_values(
class_id=cid, **kwargs).values())
_LOGGER.debug('method=%s, class_id=%s, index=%s, label=%s, data=%s,'
' member=%s, instance=%d, kwargs=%s',
method, class_id, index, label, data, member, instance,
kwargs)
_LOGGER.debug('values=%s', values)
results = None
for value in values:
if index is not None and value.index != index:
continue
if label is not None:
label_found = False
for entry in label:
if value.label == entry:
label_found = True
break
if not label_found:
continue
if method == 'set':
value.data = data
return
if data is not None and value.data != data:
continue
if instance is not None and value.instance != instance:
continue
if member is not None:
results = getattr(value, member)
else:
results = value
break
_LOGGER.debug('final result=%s', results)
return results