From 58812b326c0662c8e1fa997d37bdaab4bf35b721 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen <paulus@paulusschoutsen.nl> Date: Sat, 21 Mar 2015 21:10:46 -0700 Subject: [PATCH] Move hass.local_api and hass.components to config object --- homeassistant/__init__.py | 24 +++++++++++++++---- homeassistant/bootstrap.py | 4 ++-- homeassistant/components/api.py | 4 ++-- homeassistant/components/configurator.py | 4 ++-- homeassistant/components/discovery.py | 2 +- homeassistant/components/frontend/__init__.py | 2 +- homeassistant/components/http.py | 2 +- .../components/scheduler/__init__.py | 4 ++-- homeassistant/components/wink.py | 2 +- homeassistant/components/zwave.py | 2 +- homeassistant/remote.py | 12 +++++----- 11 files changed, 39 insertions(+), 23 deletions(-) diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 8ed3d7bc1b6..b93a8ee99be 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -54,11 +54,19 @@ class HomeAssistant(object): self.states = StateMachine(self.bus) self.config = Config() - # List of loaded components - self.components = [] + @property + def components(self): + """ DEPRECATED 3/21/2015. Use hass.config.components """ + _LOGGER.warning( + 'hass.components is deprecated. Use hass.config.components') + return self.config.components - # Remote.API object pointing at local API - self.local_api = None + @property + def local_api(self): + """ DEPRECATED 3/21/2015. Use hass.config.api """ + _LOGGER.warning( + 'hass.local_api is deprecated. Use hass.config.api') + return self.config.api @property def config_dir(self): @@ -848,6 +856,8 @@ class Timer(threading.Thread): class Config(object): """ Configuration settings for Home Assistant. """ + + # pylint: disable=too-many-instance-attributes def __init__(self): self.latitude = None self.longitude = None @@ -855,6 +865,12 @@ class Config(object): self.location_name = None self.time_zone = None + # List of loaded components + self.components = [] + + # Remote.API object pointing at local API + self.api = None + # Directory that holds the configuration self.config_dir = os.path.join(os.getcwd(), 'config') diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 83d966731cd..01093bdbded 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -33,7 +33,7 @@ ATTR_COMPONENT = "component" def setup_component(hass, domain, config=None): """ Setup a component for Home Assistant. """ # Check if already loaded - if domain in hass.components: + if domain in hass.config.components: return _ensure_loader_prepared(hass) @@ -45,7 +45,7 @@ def setup_component(hass, domain, config=None): try: if component.setup(hass, config): - hass.components.append(component.DOMAIN) + hass.config.components.append(component.DOMAIN) # Assumption: if a component does not depend on groups # it communicates with devices diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index ebb632b95ab..b5cdb9cae6c 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -32,7 +32,7 @@ _LOGGER = logging.getLogger(__name__) def setup(hass, config): """ Register the API with the HTTP interface. """ - if 'http' not in hass.components: + if 'http' not in hass.config.components: _LOGGER.error('Dependency http is not loaded') return False @@ -311,4 +311,4 @@ def _handle_delete_api_event_forward(handler, path_match, data): def _handle_get_api_components(handler, path_match, data): """ Returns all the loaded components. """ - handler.write_json(handler.server.hass.components) + handler.write_json(handler.server.hass.config.components) diff --git a/homeassistant/components/configurator.py b/homeassistant/components/configurator.py index fdd3c571601..8bec580abf9 100644 --- a/homeassistant/components/configurator.py +++ b/homeassistant/components/configurator.py @@ -83,8 +83,8 @@ def _get_instance(hass): except KeyError: _INSTANCES[hass] = Configurator(hass) - if DOMAIN not in hass.components: - hass.components.append(DOMAIN) + if DOMAIN not in hass.config.components: + hass.config.components.append(DOMAIN) return _INSTANCES[hass] diff --git a/homeassistant/components/discovery.py b/homeassistant/components/discovery.py index abd2aed6957..c17a20f9414 100644 --- a/homeassistant/components/discovery.py +++ b/homeassistant/components/discovery.py @@ -74,7 +74,7 @@ def setup(hass, config): logger.info("Found new service: %s %s", service, info) - if component and component not in hass.components: + if component and component not in hass.config.components: bootstrap.setup_component(hass, component, config) hass.bus.fire(EVENT_PLATFORM_DISCOVERED, { diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index e757ac43e69..8ff722e41b2 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -22,7 +22,7 @@ _LOGGER = logging.getLogger(__name__) def setup(hass, config): """ Setup serving the frontend. """ - if 'http' not in hass.components: + if 'http' not in hass.config.components: _LOGGER.error('Dependency http is not loaded') return False diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index 5528267686f..fed43cb43de 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -135,7 +135,7 @@ def setup(hass, config=None): threading.Thread(target=server.start, daemon=True).start()) hass.http = server - hass.local_api = rem.API(util.get_local_ip(), api_password, server_port) + hass.config.api = rem.API(util.get_local_ip(), api_password, server_port) return True diff --git a/homeassistant/components/scheduler/__init__.py b/homeassistant/components/scheduler/__init__.py index d05d90a903b..ac990543a30 100644 --- a/homeassistant/components/scheduler/__init__.py +++ b/homeassistant/components/scheduler/__init__.py @@ -35,7 +35,7 @@ _SCHEDULE_FILE = 'schedule.json' def setup(hass, config): """ Create the schedules """ - if DOMAIN in hass.components: + if DOMAIN in hass.config.components: return True def setup_listener(schedule, event_data): @@ -47,7 +47,7 @@ def setup(hass, config): if event_type in ['time']: component = 'scheduler.{}'.format(event_type) - elif component not in hass.components and \ + elif component not in hass.config.components and \ not bootstrap.setup_component(hass, component, config): _LOGGER.warn("Could setup event listener for %s", component) diff --git a/homeassistant/components/wink.py b/homeassistant/components/wink.py index 059aac4363c..daa6c92a893 100644 --- a/homeassistant/components/wink.py +++ b/homeassistant/components/wink.py @@ -41,7 +41,7 @@ def setup(hass, config): component = get_component(component_name) # Ensure component is loaded - if component.DOMAIN not in hass.components: + if component.DOMAIN not in hass.config.components: bootstrap.setup_component(hass, component.DOMAIN, config) # Fire discovery event diff --git a/homeassistant/components/zwave.py b/homeassistant/components/zwave.py index 15e436d7f4d..9304ba81a72 100644 --- a/homeassistant/components/zwave.py +++ b/homeassistant/components/zwave.py @@ -96,7 +96,7 @@ def setup(hass, config): for component, discovery_service, command_ids in DISCOVERY_COMPONENTS: if value.command_class in command_ids: # Ensure component is loaded - if component not in hass.components: + if component not in hass.config.components: bootstrap.setup_component(hass, component, config) # Fire discovery event diff --git a/homeassistant/remote.py b/homeassistant/remote.py index 3c2ffe69f29..19aa86f67b9 100644 --- a/homeassistant/remote.py +++ b/homeassistant/remote.py @@ -107,7 +107,6 @@ class HomeAssistant(ha.HomeAssistant): remote_api.host, remote_api.port, remote_api.status)) self.remote_api = remote_api - self.local_api = local_api self.pool = pool = ha.create_worker_pool() @@ -115,11 +114,12 @@ class HomeAssistant(ha.HomeAssistant): self.services = ha.ServiceRegistry(self.bus, pool) self.states = StateMachine(self.bus, self.remote_api) self.config = ha.Config() - self.components = [] + + self.config.api = local_api def start(self): # Ensure a local API exists to connect with remote - if self.local_api is None: + if self.config.api is None: bootstrap.setup_component(self, 'http') bootstrap.setup_component(self, 'api') @@ -130,10 +130,10 @@ class HomeAssistant(ha.HomeAssistant): # Setup that events from remote_api get forwarded to local_api # Do this after we fire START, otherwise HTTP is not started - if not connect_remote_events(self.remote_api, self.local_api): + if not connect_remote_events(self.remote_api, self.config.api): raise ha.HomeAssistantError(( 'Could not setup event forwarding from api {} to ' - 'local api {}').format(self.remote_api, self.local_api)) + 'local api {}').format(self.remote_api, self.config.api)) def stop(self): """ Stops Home Assistant and shuts down all threads. """ @@ -143,7 +143,7 @@ class HomeAssistant(ha.HomeAssistant): origin=ha.EventOrigin.remote) # Disconnect master event forwarding - disconnect_remote_events(self.remote_api, self.local_api) + disconnect_remote_events(self.remote_api, self.config.api) # Wait till all responses to homeassistant_stop are done self.pool.block_till_done() -- GitLab