Bugfixes random (#2270)

* Fix Z-Wave autoheal network

* Make config_per_platform handle bad config better
pull/2271/head
Paulus Schoutsen 2016-06-10 22:53:31 -07:00 committed by GitHub
parent b60806583c
commit c9756c40e2
3 changed files with 33 additions and 13 deletions

View File

@ -214,12 +214,6 @@ def setup(hass, config):
config_path=config[DOMAIN].get('config_path',
default_zwave_config_path),)
# Setup autoheal
if autoheal:
_LOGGER.info("ZWave network autoheal is enabled.")
track_time_change(hass, lambda: heal_network(None),
hour=0, minute=0, second=0)
options.set_console_output(use_debug)
options.lock()
@ -291,24 +285,24 @@ def setup(hass, config):
dispatcher.connect(
scene_activated, ZWaveNetwork.SIGNAL_SCENE_EVENT, weak=False)
def add_node(event):
def add_node(service):
"""Switch into inclusion mode."""
NETWORK.controller.begin_command_add_device()
def remove_node(event):
def remove_node(service):
"""Switch into exclusion mode."""
NETWORK.controller.begin_command_remove_device()
def heal_network(event):
def heal_network(service):
"""Heal the network."""
_LOGGER.info("ZWave heal running.")
NETWORK.heal()
def soft_reset(event):
def soft_reset(service):
"""Soft reset the controller."""
NETWORK.controller.soft_reset()
def test_network(event):
def test_network(service):
"""Test the network by sending commands to all the nodes."""
NETWORK.test()
@ -324,7 +318,7 @@ def setup(hass, config):
# 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(
_LOGGER.debug(
"network state: %d %s", NETWORK.state, NETWORK.state_str)
if NETWORK.state >= NETWORK.STATE_AWAKED:
_LOGGER.info("zwave ready after %d seconds", i)
@ -355,6 +349,11 @@ def setup(hass, config):
hass.services.register(DOMAIN, SERVICE_SOFT_RESET, soft_reset)
hass.services.register(DOMAIN, SERVICE_TEST_NETWORK, test_network)
# Setup autoheal
if autoheal:
_LOGGER.info("ZWave network autoheal is enabled.")
track_time_change(hass, heal_network, hour=0, minute=0, second=0)
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_zwave)
return True

View File

@ -40,7 +40,11 @@ def config_per_platform(config, domain):
platform_config = [platform_config]
for item in platform_config:
platform = None if item is None else item.get(CONF_PLATFORM)
try:
platform = item.get(CONF_PLATFORM)
except AttributeError:
platform = None
yield platform, item

View File

@ -1,5 +1,6 @@
"""Test component helpers."""
# pylint: disable=protected-access,too-many-public-methods
from collections import OrderedDict
import unittest
from homeassistant import helpers
@ -30,3 +31,19 @@ class TestHelpers(unittest.TestCase):
self.assertEqual(set(['zone', 'zone Hallo', 'zone 100']),
set(helpers.extract_domain_configs(config, 'zone')))
def test_config_per_platform(self):
"""Test config per platform method."""
config = OrderedDict([
('zone', {'platform': 'hello'}),
('zoner', None),
('zone Hallo', [1, {'platform': 'hello 2'}]),
('zone 100', None),
])
assert [
('hello', config['zone']),
(None, 1),
('hello 2', config['zone Hallo'][1]),
(None, None)
] == list(helpers.config_per_platform(config, 'zone'))