diff --git a/homeassistant/components/zwave.py b/homeassistant/components/zwave.py index ddabdee9def..3f396e2ded4 100644 --- a/homeassistant/components/zwave.py +++ b/homeassistant/components/zwave.py @@ -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 diff --git a/homeassistant/helpers/__init__.py b/homeassistant/helpers/__init__.py index 69777a0ccd4..02c7eece73a 100644 --- a/homeassistant/helpers/__init__.py +++ b/homeassistant/helpers/__init__.py @@ -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 diff --git a/tests/helpers/test_init.py b/tests/helpers/test_init.py index 098211085f7..541247c5420 100644 --- a/tests/helpers/test_init.py +++ b/tests/helpers/test_init.py @@ -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'))