Add communication data attributes to Zwave node_entity (#6813)
* Add quality attribute to node * Move quality to node_entity * adjustments * Line lenght * flake8 * Cleanup and add each entry from getNodeStatistics as attribute * resolve conflict * Move NETWORK to hass.data * Test Done * Cleanup from review * Resolve conflicts * Review changes * Long lines.... * blank line * import-error-disable * Update tests Part1... Again * Hound * Argh! * Argh! * YABBADABBADOOOOOOO! * Enhance tests * hound * Resolve * resolve tests...
This commit is contained in:
1 parent
f68542ba0d
commit
d63028e44a
8 files changed
+240
-148
No files matched your search
@@ -65,8 +65,7 @@ DEFAULT_CONF_REFRESH_VALUE = False
|
||||
DEFAULT_CONF_REFRESH_DELAY = 5
|
||||
|
||||
DATA_ZWAVE_DICT = 'zwave_devices'
|
||||
|
||||
NETWORK = None
|
||||
ZWAVE_NETWORK = 'zwave_network'
|
||||
|
||||
RENAME_NODE_SCHEMA = vol.Schema({
|
||||
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
|
||||
@@ -200,7 +199,7 @@ def get_config_value(node, value_index, tries=5):
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
"""Generic Z-Wave platform setup."""
|
||||
if discovery_info is None or NETWORK is None:
|
||||
if discovery_info is None or ZWAVE_NETWORK not in hass.data:
|
||||
return False
|
||||
|
||||
device = hass.data[DATA_ZWAVE_DICT].pop(
|
||||
@@ -218,9 +217,6 @@ def setup(hass, config):
|
||||
|
||||
Will automatically load components to support devices found on the network.
|
||||
"""
|
||||
# pylint: disable=global-statement, import-error
|
||||
global NETWORK
|
||||
|
||||
descriptions = conf_util.load_yaml_config_file(
|
||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||
|
||||
@@ -232,6 +228,7 @@ def setup(hass, config):
|
||||
"https://home-assistant.io/components/zwave/")
|
||||
return False
|
||||
from pydispatch import dispatcher
|
||||
# pylint: disable=import-error
|
||||
from openzwave.option import ZWaveOption
|
||||
from openzwave.network import ZWaveNetwork
|
||||
from openzwave.group import ZWaveGroup
|
||||
@@ -257,7 +254,7 @@ def setup(hass, config):
|
||||
options.set_console_output(use_debug)
|
||||
options.lock()
|
||||
|
||||
NETWORK = ZWaveNetwork(options, autostart=False)
|
||||
network = hass.data[ZWAVE_NETWORK] = ZWaveNetwork(options, autostart=False)
|
||||
hass.data[DATA_ZWAVE_DICT] = {}
|
||||
|
||||
if use_debug: # pragma: no cover
|
||||
@@ -301,7 +298,7 @@ def setup(hass, config):
|
||||
|
||||
def node_added(node):
|
||||
"""Called when a node is added on the network."""
|
||||
entity = ZWaveNodeEntity(node)
|
||||
entity = ZWaveNodeEntity(node, network)
|
||||
node_config = device_config.get(entity.entity_id)
|
||||
if node_config.get(CONF_IGNORED):
|
||||
_LOGGER.info(
|
||||
@@ -354,49 +351,49 @@ def setup(hass, config):
|
||||
def add_node(service):
|
||||
"""Switch into inclusion mode."""
|
||||
_LOGGER.info("Zwave add_node have been initialized.")
|
||||
NETWORK.controller.add_node()
|
||||
network.controller.add_node()
|
||||
|
||||
def add_node_secure(service):
|
||||
"""Switch into secure inclusion mode."""
|
||||
_LOGGER.info("Zwave add_node_secure have been initialized.")
|
||||
NETWORK.controller.add_node(True)
|
||||
network.controller.add_node(True)
|
||||
|
||||
def remove_node(service):
|
||||
"""Switch into exclusion mode."""
|
||||
_LOGGER.info("Zwave remove_node have been initialized.")
|
||||
NETWORK.controller.remove_node()
|
||||
network.controller.remove_node()
|
||||
|
||||
def cancel_command(service):
|
||||
"""Cancel a running controller command."""
|
||||
_LOGGER.info("Cancel running ZWave command.")
|
||||
NETWORK.controller.cancel_command()
|
||||
network.controller.cancel_command()
|
||||
|
||||
def heal_network(service):
|
||||
"""Heal the network."""
|
||||
_LOGGER.info("ZWave heal running.")
|
||||
NETWORK.heal()
|
||||
network.heal()
|
||||
|
||||
def soft_reset(service):
|
||||
"""Soft reset the controller."""
|
||||
_LOGGER.info("Zwave soft_reset have been initialized.")
|
||||
NETWORK.controller.soft_reset()
|
||||
network.controller.soft_reset()
|
||||
|
||||
def test_network(service):
|
||||
"""Test the network by sending commands to all the nodes."""
|
||||
_LOGGER.info("Zwave test_network have been initialized.")
|
||||
NETWORK.test()
|
||||
network.test()
|
||||
|
||||
def stop_network(_service_or_event):
|
||||
"""Stop Z-Wave network."""
|
||||
_LOGGER.info("Stopping ZWave network.")
|
||||
NETWORK.stop()
|
||||
network.stop()
|
||||
if hass.state == CoreState.running:
|
||||
hass.bus.fire(const.EVENT_NETWORK_STOP)
|
||||
|
||||
def rename_node(service):
|
||||
"""Rename a node."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
node = NETWORK.nodes[node_id]
|
||||
node = hass.data[ZWAVE_NETWORK].nodes[node_id]
|
||||
name = service.data.get(const.ATTR_NAME)
|
||||
node.name = name
|
||||
_LOGGER.info(
|
||||
@@ -406,18 +403,18 @@ def setup(hass, config):
|
||||
"""Remove failed node."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
_LOGGER.info('Trying to remove zwave node %d', node_id)
|
||||
NETWORK.controller.remove_failed_node(node_id)
|
||||
network.controller.remove_failed_node(node_id)
|
||||
|
||||
def replace_failed_node(service):
|
||||
"""Replace failed node."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
_LOGGER.info('Trying to replace zwave node %d', node_id)
|
||||
NETWORK.controller.replace_failed_node(node_id)
|
||||
network.controller.replace_failed_node(node_id)
|
||||
|
||||
def set_config_parameter(service):
|
||||
"""Set a config parameter to a node."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
node = NETWORK.nodes[node_id]
|
||||
node = network.nodes[node_id]
|
||||
param = service.data.get(const.ATTR_CONFIG_PARAMETER)
|
||||
selection = service.data.get(const.ATTR_CONFIG_VALUE)
|
||||
size = service.data.get(const.ATTR_CONFIG_SIZE, 2)
|
||||
@@ -446,7 +443,7 @@ def setup(hass, config):
|
||||
def print_config_parameter(service):
|
||||
"""Print a config parameter from a node."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
node = NETWORK.nodes[node_id]
|
||||
node = network.nodes[node_id]
|
||||
param = service.data.get(const.ATTR_CONFIG_PARAMETER)
|
||||
_LOGGER.info("Config parameter %s on Node %s : %s",
|
||||
param, node_id, get_config_value(node, param))
|
||||
@@ -454,13 +451,13 @@ def setup(hass, config):
|
||||
def print_node(service):
|
||||
"""Print all information about z-wave node."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
node = NETWORK.nodes[node_id]
|
||||
node = network.nodes[node_id]
|
||||
nice_print_node(node)
|
||||
|
||||
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]
|
||||
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(
|
||||
@@ -478,7 +475,7 @@ def setup(hass, config):
|
||||
group = service.data.get(const.ATTR_GROUP)
|
||||
instance = service.data.get(const.ATTR_INSTANCE)
|
||||
|
||||
node = ZWaveGroup(group, NETWORK, node_id)
|
||||
node = ZWaveGroup(group, network, node_id)
|
||||
if association_type == 'add':
|
||||
node.add_association(target_node_id, instance)
|
||||
_LOGGER.info("Adding association for node:%s in group:%s "
|
||||
@@ -500,13 +497,13 @@ def setup(hass, config):
|
||||
def refresh_node(service):
|
||||
"""Refresh all node info."""
|
||||
node_id = service.data.get(const.ATTR_NODE_ID)
|
||||
node = NETWORK.nodes[node_id]
|
||||
node = network.nodes[node_id]
|
||||
node.refresh_info()
|
||||
|
||||
def start_zwave(_service_or_event):
|
||||
"""Startup Z-Wave network."""
|
||||
_LOGGER.info("Starting ZWave network.")
|
||||
NETWORK.start()
|
||||
network.start()
|
||||
hass.bus.fire(const.EVENT_NETWORK_START)
|
||||
|
||||
# Need to be in STATE_AWAKED before talking to nodes.
|
||||
@@ -514,8 +511,9 @@ def setup(hass, config):
|
||||
# to be ready.
|
||||
for i in range(const.NETWORK_READY_WAIT_SECS):
|
||||
_LOGGER.debug(
|
||||
"network state: %d %s", NETWORK.state, NETWORK.state_str)
|
||||
if NETWORK.state >= NETWORK.STATE_AWAKED:
|
||||
"network state: %d %s", hass.data[ZWAVE_NETWORK].state,
|
||||
network.state_str)
|
||||
if network.state >= network.STATE_AWAKED:
|
||||
_LOGGER.info("zwave ready after %d seconds", i)
|
||||
break
|
||||
time.sleep(1)
|
||||
@@ -524,14 +522,15 @@ def setup(hass, config):
|
||||
"zwave not ready after %d seconds, continuing anyway",
|
||||
const.NETWORK_READY_WAIT_SECS)
|
||||
_LOGGER.info(
|
||||
"final network state: %d %s", NETWORK.state, NETWORK.state_str)
|
||||
"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)
|
||||
network.set_poll_interval(polling_interval, False)
|
||||
|
||||
poll_interval = NETWORK.get_poll_interval()
|
||||
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_network)
|
||||
|
||||
Reference in new issue
Block a user