mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Move hass.local_api and hass.components to config object
This commit is contained in:
parent
609064b9d8
commit
58812b326c
@ -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')
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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, {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user