mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +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.states = StateMachine(self.bus)
|
||||||
self.config = Config()
|
self.config = Config()
|
||||||
|
|
||||||
# List of loaded components
|
@property
|
||||||
self.components = []
|
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
|
@property
|
||||||
self.local_api = None
|
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
|
@property
|
||||||
def config_dir(self):
|
def config_dir(self):
|
||||||
@ -848,6 +856,8 @@ class Timer(threading.Thread):
|
|||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
""" Configuration settings for Home Assistant. """
|
""" Configuration settings for Home Assistant. """
|
||||||
|
|
||||||
|
# pylint: disable=too-many-instance-attributes
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.latitude = None
|
self.latitude = None
|
||||||
self.longitude = None
|
self.longitude = None
|
||||||
@ -855,6 +865,12 @@ class Config(object):
|
|||||||
self.location_name = None
|
self.location_name = None
|
||||||
self.time_zone = 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
|
# Directory that holds the configuration
|
||||||
self.config_dir = os.path.join(os.getcwd(), 'config')
|
self.config_dir = os.path.join(os.getcwd(), 'config')
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ ATTR_COMPONENT = "component"
|
|||||||
def setup_component(hass, domain, config=None):
|
def setup_component(hass, domain, config=None):
|
||||||
""" Setup a component for Home Assistant. """
|
""" Setup a component for Home Assistant. """
|
||||||
# Check if already loaded
|
# Check if already loaded
|
||||||
if domain in hass.components:
|
if domain in hass.config.components:
|
||||||
return
|
return
|
||||||
|
|
||||||
_ensure_loader_prepared(hass)
|
_ensure_loader_prepared(hass)
|
||||||
@ -45,7 +45,7 @@ def setup_component(hass, domain, config=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if component.setup(hass, config):
|
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
|
# Assumption: if a component does not depend on groups
|
||||||
# it communicates with devices
|
# it communicates with devices
|
||||||
|
@ -32,7 +32,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Register the API with the HTTP interface. """
|
""" 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')
|
_LOGGER.error('Dependency http is not loaded')
|
||||||
return False
|
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):
|
def _handle_get_api_components(handler, path_match, data):
|
||||||
""" Returns all the loaded components. """
|
""" 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:
|
except KeyError:
|
||||||
_INSTANCES[hass] = Configurator(hass)
|
_INSTANCES[hass] = Configurator(hass)
|
||||||
|
|
||||||
if DOMAIN not in hass.components:
|
if DOMAIN not in hass.config.components:
|
||||||
hass.components.append(DOMAIN)
|
hass.config.components.append(DOMAIN)
|
||||||
|
|
||||||
return _INSTANCES[hass]
|
return _INSTANCES[hass]
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ def setup(hass, config):
|
|||||||
|
|
||||||
logger.info("Found new service: %s %s", service, info)
|
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)
|
bootstrap.setup_component(hass, component, config)
|
||||||
|
|
||||||
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
|
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
|
||||||
|
@ -22,7 +22,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup serving the frontend. """
|
""" Setup serving the frontend. """
|
||||||
if 'http' not in hass.components:
|
if 'http' not in hass.config.components:
|
||||||
_LOGGER.error('Dependency http is not loaded')
|
_LOGGER.error('Dependency http is not loaded')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ def setup(hass, config=None):
|
|||||||
threading.Thread(target=server.start, daemon=True).start())
|
threading.Thread(target=server.start, daemon=True).start())
|
||||||
|
|
||||||
hass.http = server
|
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
|
return True
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ _SCHEDULE_FILE = 'schedule.json'
|
|||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Create the schedules """
|
""" Create the schedules """
|
||||||
|
|
||||||
if DOMAIN in hass.components:
|
if DOMAIN in hass.config.components:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setup_listener(schedule, event_data):
|
def setup_listener(schedule, event_data):
|
||||||
@ -47,7 +47,7 @@ def setup(hass, config):
|
|||||||
if event_type in ['time']:
|
if event_type in ['time']:
|
||||||
component = 'scheduler.{}'.format(event_type)
|
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):
|
not bootstrap.setup_component(hass, component, config):
|
||||||
|
|
||||||
_LOGGER.warn("Could setup event listener for %s", component)
|
_LOGGER.warn("Could setup event listener for %s", component)
|
||||||
|
@ -41,7 +41,7 @@ def setup(hass, config):
|
|||||||
component = get_component(component_name)
|
component = get_component(component_name)
|
||||||
|
|
||||||
# Ensure component is loaded
|
# 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)
|
bootstrap.setup_component(hass, component.DOMAIN, config)
|
||||||
|
|
||||||
# Fire discovery event
|
# Fire discovery event
|
||||||
|
@ -96,7 +96,7 @@ def setup(hass, config):
|
|||||||
for component, discovery_service, command_ids in DISCOVERY_COMPONENTS:
|
for component, discovery_service, command_ids in DISCOVERY_COMPONENTS:
|
||||||
if value.command_class in command_ids:
|
if value.command_class in command_ids:
|
||||||
# Ensure component is loaded
|
# Ensure component is loaded
|
||||||
if component not in hass.components:
|
if component not in hass.config.components:
|
||||||
bootstrap.setup_component(hass, component, config)
|
bootstrap.setup_component(hass, component, config)
|
||||||
|
|
||||||
# Fire discovery event
|
# Fire discovery event
|
||||||
|
@ -107,7 +107,6 @@ class HomeAssistant(ha.HomeAssistant):
|
|||||||
remote_api.host, remote_api.port, remote_api.status))
|
remote_api.host, remote_api.port, remote_api.status))
|
||||||
|
|
||||||
self.remote_api = remote_api
|
self.remote_api = remote_api
|
||||||
self.local_api = local_api
|
|
||||||
|
|
||||||
self.pool = pool = ha.create_worker_pool()
|
self.pool = pool = ha.create_worker_pool()
|
||||||
|
|
||||||
@ -115,11 +114,12 @@ class HomeAssistant(ha.HomeAssistant):
|
|||||||
self.services = ha.ServiceRegistry(self.bus, pool)
|
self.services = ha.ServiceRegistry(self.bus, pool)
|
||||||
self.states = StateMachine(self.bus, self.remote_api)
|
self.states = StateMachine(self.bus, self.remote_api)
|
||||||
self.config = ha.Config()
|
self.config = ha.Config()
|
||||||
self.components = []
|
|
||||||
|
self.config.api = local_api
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# Ensure a local API exists to connect with remote
|
# 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, 'http')
|
||||||
bootstrap.setup_component(self, 'api')
|
bootstrap.setup_component(self, 'api')
|
||||||
|
|
||||||
@ -130,10 +130,10 @@ class HomeAssistant(ha.HomeAssistant):
|
|||||||
|
|
||||||
# Setup that events from remote_api get forwarded to local_api
|
# Setup that events from remote_api get forwarded to local_api
|
||||||
# Do this after we fire START, otherwise HTTP is not started
|
# 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((
|
raise ha.HomeAssistantError((
|
||||||
'Could not setup event forwarding from api {} to '
|
'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):
|
def stop(self):
|
||||||
""" Stops Home Assistant and shuts down all threads. """
|
""" Stops Home Assistant and shuts down all threads. """
|
||||||
@ -143,7 +143,7 @@ class HomeAssistant(ha.HomeAssistant):
|
|||||||
origin=ha.EventOrigin.remote)
|
origin=ha.EventOrigin.remote)
|
||||||
|
|
||||||
# Disconnect master event forwarding
|
# 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
|
# Wait till all responses to homeassistant_stop are done
|
||||||
self.pool.block_till_done()
|
self.pool.block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user