Add support for zwave wakeup setting. (#5849)

* Add support for zwave wakeup setting.

* rename wakeup
This commit is contained in:
Andrey 2017-02-10 18:54:48 +02:00 committed by Paulus Schoutsen
parent 4e8d20328a
commit 0b5191a247
4 changed files with 49 additions and 2 deletions

View File

@ -13,8 +13,9 @@ import voluptuous as vol
from homeassistant.helpers import discovery, customize
from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_LOCATION, ATTR_ENTITY_ID, CONF_CUSTOMIZE,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, CONF_ENTITY_ID)
ATTR_BATTERY_LEVEL, ATTR_LOCATION, ATTR_ENTITY_ID, ATTR_WAKEUP,
CONF_CUSTOMIZE, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
CONF_ENTITY_ID)
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import track_time_change
from homeassistant.util import convert, slugify
@ -152,6 +153,12 @@ CHANGE_ASSOCIATION_SCHEMA = vol.Schema({
vol.Optional(const.ATTR_INSTANCE, default=0x00): vol.Coerce(int)
})
SET_WAKEUP_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_VALUE):
vol.All(vol.Coerce(int), cv.positive_int),
})
_ZWAVE_CUSTOMIZE_SCHEMA_ENTRY = vol.Schema({
vol.Required(CONF_ENTITY_ID): cv.match_all,
vol.Optional(CONF_POLLING_INTENSITY): cv.positive_int,
@ -242,6 +249,14 @@ def get_config_value(node, value_index):
return get_config_value(node, value_index)
def _get_wakeup(node):
"""Return wakeup interval of the node or None if node is not wakable."""
if node.can_wake_up():
for value_id in node.get_values(class_id=const.COMMAND_CLASS_WAKE_UP):
return node.values[value_id].data
return None
# pylint: disable=R0914
def setup(hass, config):
"""Setup Z-Wave.
@ -503,6 +518,19 @@ def setup(hass, config):
_LOGGER.info("Config parameter %s on Node %s : %s",
param, node_id, get_config_value(node, param))
def set_wakeup(service):
"""Set wake-up interval of a node."""
node_id = service.data.get(const.ATTR_NODE_ID)
node = NETWORK.nodes[node_id]
value = service.data.get(const.ATTR_CONFIG_VALUE)
if node.can_wake_up():
for value_id in node.get_values(
class_id=const.COMMAND_CLASS_WAKE_UP):
node.values[value_id].data = value
_LOGGER.info("Node %s wake-up set to %d", node_id, value)
else:
_LOGGER.info("Node %s is not wakeable", node_id)
def change_association(service):
"""Change an association in the zwave network."""
association_type = service.data.get(const.ATTR_ASSOCIATION)
@ -598,6 +626,11 @@ def setup(hass, config):
descriptions[
const.SERVICE_CHANGE_ASSOCIATION],
schema=CHANGE_ASSOCIATION_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_SET_WAKEUP,
set_wakeup,
descriptions[
const.SERVICE_SET_WAKEUP],
schema=SET_WAKEUP_SCHEMA)
# Setup autoheal
if autoheal:
@ -727,4 +760,8 @@ class ZWaveDeviceEntity(Entity):
if location:
attrs[ATTR_LOCATION] = location
wakeup = _get_wakeup(self._value.node)
if wakeup:
attrs[ATTR_WAKEUP] = wakeup
return attrs

View File

@ -25,6 +25,7 @@ SERVICE_SOFT_RESET = "soft_reset"
SERVICE_TEST_NETWORK = "test_network"
SERVICE_SET_CONFIG_PARAMETER = "set_config_parameter"
SERVICE_PRINT_CONFIG_PARAMETER = "print_config_parameter"
SERVICE_SET_WAKEUP = "set_wakeup"
SERVICE_STOP_NETWORK = "stop_network"
SERVICE_START_NETWORK = "start_network"
SERVICE_RENAME_NODE = "rename_node"

View File

@ -47,6 +47,14 @@ print_config_parameter:
parameter:
description: Parameter number to print (integer).
set_wakeup:
description: Sets wake-up interval of a node.
fields:
node_id:
description: Node id of the device to set the wake-up interval for. (integer)
value:
description: Value of the interval to set. (integer)
start_network:
description: Start the Z-Wave network. This might take a while, depending on how big your Z-Wave network is.

View File

@ -253,6 +253,7 @@ ATTR_DISCOVERED = 'discovered'
ATTR_LOCATION = 'location'
ATTR_BATTERY_LEVEL = 'battery_level'
ATTR_WAKEUP = 'wake_up_interval'
# For devices which support a code attribute
ATTR_CODE = 'code'