diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 8ed3d7bc1b62bcd97c8088c8c470b5bb836eaaf9..b93a8ee99beacd024bac65837e98fc045938067b 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 83d966731cda033eff4fa6cf3c1e3d93facacdf9..01093bdbded3ed0bce6597db40276ce155f64414 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 ebb632b95abd7dcd4ec16d8c24b980e42c1f9761..b5cdb9cae6c058a298ab2a3296b6f2bca7c4694d 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 fdd3c5716018085752958ef8b805f725ea21609f..8bec580abf97614796fb55eac25ce7f730151001 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 abd2aed6957fd2bb743afb2849ab4ffcefa3fae6..c17a20f9414de23416e4b874106215edb669a62b 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 e757ac43e6908a4aee01a896b63374d71bdd9503..8ff722e41b2f2aa5f112c9429464ab5db0e13bf5 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 5528267686f6894d23346f929bd38cd94d493bb1..fed43cb43de765cf7d0ebf99ea234f7618327bc6 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 d05d90a903b543f97a44f4b4e16d457ca2ff3431..ac990543a3079628b2ecc93feaaa34bdf0258e4c 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 059aac4363c179d17aae49a545bed8b0ec446389..daa6c92a89396f928f4f36892f81e9d7eaa1b3c6 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 15e436d7f4da1770f50ba7278c2d659d6423f242..9304ba81a72da1f142727c38b34c053d4351280d 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 3c2ffe69f29ec5545424c71730ca99429e08161f..19aa86f67b92cac2ed38ad84072bfa9571ac232e 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()