Zwave cleanup for startup and poll_intensity.

If the polling intensity is zero, specifically
disable polling for that device/sub device.

Have zwave startup wait until the zwave
nework is ready (defined by python openzwave docs):

https://python-openzwave.googlecode.com

SIGNAL_NETWORK_AWAKED : all awake nodes are queried. Some sleeping nodes may be missing.

and

You can safely ask node informations when state >= STATE_AWAKED

This appears to make the polling of nodes a bit more deterministic.
pull/1636/head
Charles Spirakis 2016-03-27 11:29:39 -07:00
parent fad13beea6
commit f28aa030e6
1 changed files with 30 additions and 1 deletions

View File

@ -4,8 +4,10 @@ Support for Z-Wave.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/zwave/
"""
import logging
import os.path
import sys
import time
from pprint import pprint
from homeassistant import bootstrap
@ -26,6 +28,9 @@ CONF_POLLING_INTENSITY = "polling_intensity"
DEFAULT_ZWAVE_CONFIG_PATH = os.path.join(sys.prefix, 'share',
'python-openzwave', 'config')
# How long to wait for the zwave network to be ready.
NETWORK_READY_WAIT_SECS = 30
SERVICE_ADD_NODE = "add_node"
SERVICE_REMOVE_NODE = "remove_node"
SERVICE_HEAL_NETWORK = "heal_network"
@ -91,6 +96,8 @@ ATTR_SCENE_ID = "scene_id"
NETWORK = None
_LOGGER = logging.getLogger(__name__)
def _obj_to_dict(obj):
"""Convert an object into a hash for debug."""
@ -217,8 +224,10 @@ def setup(hass, config):
node_config = customize.get(name, {})
polling_intensity = convert(
node_config.get(CONF_POLLING_INTENSITY), int)
if polling_intensity is not None:
if polling_intensity:
value.enable_poll(polling_intensity)
else:
value.disable_poll()
# Fire discovery event
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
@ -268,11 +277,31 @@ def setup(hass, config):
"""Startup Z-Wave."""
NETWORK.start()
# Need to be in STATE_AWAKED before talking to nodes.
# Wait up to NETWORK_READY_WAIT_SECS seconds for the zwave network
# to be ready.
for i in range(NETWORK_READY_WAIT_SECS):
_LOGGER.info(
"network state: %d %s", NETWORK.state, NETWORK.state_str)
if NETWORK.state >= NETWORK.STATE_AWAKED:
_LOGGER.info("zwave ready after %d seconds", i)
break
time.sleep(1)
else:
_LOGGER.warning(
"zwave not ready after %d seconds, continuing anyway",
NETWORK_READY_WAIT_SECS)
_LOGGER.info(
"final network state: %d %s", NETWORK.state, NETWORK.state_str)
polling_interval = convert(
config[DOMAIN].get(CONF_POLLING_INTERVAL), int)
if polling_interval is not None:
NETWORK.set_poll_interval(polling_interval, False)
poll_interval = NETWORK.get_poll_interval()
_LOGGER.info("zwave polling interval set to %d ms", poll_interval)
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zwave)
# Register add / remove node services for Z-Wave sticks without