From 00dbef91d992e1ff914e3376e883ffd70f063139 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 1 Sep 2016 10:24:19 +0100 Subject: [PATCH] Migrate automation to use component validation --- .../components/automation/__init__.py | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index efa972926bc5ba..e71c12ae1c168d 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -9,7 +9,8 @@ import voluptuous as vol -from homeassistant.bootstrap import prepare_setup_platform +from homeassistant.bootstrap import ( + prepare_setup_platform, prepare_setup_component) from homeassistant import config as conf_util from homeassistant.const import ( ATTR_ENTITY_ID, CONF_PLATFORM, STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, @@ -159,7 +160,6 @@ def reload(hass): def setup(hass, config): """Setup the automation.""" - # pylint: disable=too-many-locals component = EntityComponent(_LOGGER, DOMAIN, hass) success = _process_config(hass, config, component) @@ -186,28 +186,10 @@ def reload_service_handler(service_call): _LOGGER.error(err) return - # For now copied from bootstrap.py - # Depends on work by @Kellerza to split this out - from homeassistant.bootstrap import config_per_platform, log_exception - - platforms = [] - for _, p_config in config_per_platform(conf, DOMAIN): - # Validate component specific platform schema - try: - p_validated = PLATFORM_SCHEMA(p_config) - except vol.MultipleInvalid as ex: - log_exception(ex, DOMAIN, p_config) - return - - platforms.append(p_validated) - - # Create a copy of the configuration with all config for current - # component removed and add validated config back in. - filter_keys = extract_domain_configs(conf, DOMAIN) - conf = {key: value for key, value in conf.items() - if key not in filter_keys} - conf[DOMAIN] = platforms - # End copied from bootstrap + conf = prepare_setup_component(hass, conf, DOMAIN) + + if conf is None: + return component.reset() _process_config(hass, conf, component)