Reload groups (#3203)

* Allow reloading groups without restart

* Test to make sure automation listeners are removed.

* Remove unused imports for group tests

* Simplify group config validation

* Add prepare_reload function to entity component

* Migrate group to use entity_component.prepare_reload

* Migrate automation to use entity_component.prepare_reload

* Clean up group.get_entity_ids

* Use cv.boolean for group config validation
This commit is contained in:
Paulus Schoutsen
2016-09-07 06:59:16 -07:00
committed by GitHub
parent 91028cbc13
commit 35b388edce
8 changed files with 143 additions and 63 deletions

View File

@@ -1,11 +1,14 @@
"""Helpers for components that manage entities."""
from threading import Lock
from homeassistant.bootstrap import prepare_setup_platform
from homeassistant.components import group
from homeassistant import config as conf_util
from homeassistant.bootstrap import (prepare_setup_platform,
prepare_setup_component)
from homeassistant.const import (
ATTR_ENTITY_ID, CONF_SCAN_INTERVAL, CONF_ENTITY_NAMESPACE,
DEVICE_DEFAULT_NAME)
from homeassistant.exceptions import HomeAssistantError
from homeassistant.loader import get_component
from homeassistant.helpers import config_per_platform, discovery
from homeassistant.helpers.entity import generate_entity_id
from homeassistant.helpers.event import track_utc_time_change
@@ -135,6 +138,7 @@ class EntityComponent(object):
def update_group(self):
"""Set up and/or update component group."""
if self.group is None and self.group_name is not None:
group = get_component('group')
self.group = group.Group(self.hass, self.group_name,
user_defined=False)
@@ -157,6 +161,23 @@ class EntityComponent(object):
self.group.stop()
self.group = None
def prepare_reload(self):
"""Prepare reloading this entity component."""
try:
path = conf_util.find_config_file(self.hass.config.config_dir)
conf = conf_util.load_yaml_config_file(path)
except HomeAssistantError as err:
self.logger.error(err)
return None
conf = prepare_setup_component(self.hass, conf, self.domain)
if conf is None:
return None
self.reset()
return conf
class EntityPlatform(object):
"""Keep track of entities for a single platform."""