mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fire event for loading component/adding service
This commit is contained in:
parent
846e11d6b8
commit
7dd7c489e8
@ -19,7 +19,7 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
|
||||||
SERVICE_HOMEASSISTANT_STOP, EVENT_TIME_CHANGED, EVENT_STATE_CHANGED,
|
SERVICE_HOMEASSISTANT_STOP, EVENT_TIME_CHANGED, EVENT_STATE_CHANGED,
|
||||||
EVENT_CALL_SERVICE, ATTR_NOW, ATTR_DOMAIN, ATTR_SERVICE, MATCH_ALL,
|
EVENT_CALL_SERVICE, ATTR_NOW, ATTR_DOMAIN, ATTR_SERVICE, MATCH_ALL,
|
||||||
EVENT_SERVICE_EXECUTED, ATTR_SERVICE_CALL_ID)
|
EVENT_SERVICE_EXECUTED, ATTR_SERVICE_CALL_ID, EVENT_SERVICE_REGISTERED)
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
|
|
||||||
DOMAIN = "homeassistant"
|
DOMAIN = "homeassistant"
|
||||||
@ -683,6 +683,10 @@ class ServiceRegistry(object):
|
|||||||
else:
|
else:
|
||||||
self._services[domain] = {service: service_func}
|
self._services[domain] = {service: service_func}
|
||||||
|
|
||||||
|
self._bus.fire(
|
||||||
|
EVENT_SERVICE_REGISTERED,
|
||||||
|
{ATTR_DOMAIN: domain, ATTR_SERVICE: service})
|
||||||
|
|
||||||
def call(self, domain, service, service_data=None, blocking=False):
|
def call(self, domain, service, service_data=None, blocking=False):
|
||||||
"""
|
"""
|
||||||
Calls specified service.
|
Calls specified service.
|
||||||
|
@ -18,9 +18,12 @@ import homeassistant
|
|||||||
import homeassistant.loader as loader
|
import homeassistant.loader as loader
|
||||||
import homeassistant.components as core_components
|
import homeassistant.components as core_components
|
||||||
import homeassistant.components.group as group
|
import homeassistant.components.group as group
|
||||||
|
from homeassistant.const import EVENT_COMPONENT_LOADED
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
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. """
|
||||||
@ -39,13 +42,14 @@ def setup_component(hass, domain, config=None):
|
|||||||
if component.setup(hass, config):
|
if component.setup(hass, config):
|
||||||
hass.components.append(component.DOMAIN)
|
hass.components.append(component.DOMAIN)
|
||||||
|
|
||||||
_LOGGER.info("component %s initialized", 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
|
||||||
if group.DOMAIN not in component.DEPENDENCIES:
|
if group.DOMAIN not in component.DEPENDENCIES:
|
||||||
hass.pool.add_worker()
|
hass.pool.add_worker()
|
||||||
|
|
||||||
|
hass.bus.fire(
|
||||||
|
EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: component.DOMAIN})
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -28,6 +28,8 @@ EVENT_TIME_CHANGED = "time_changed"
|
|||||||
EVENT_CALL_SERVICE = "call_service"
|
EVENT_CALL_SERVICE = "call_service"
|
||||||
EVENT_SERVICE_EXECUTED = "service_executed"
|
EVENT_SERVICE_EXECUTED = "service_executed"
|
||||||
EVENT_PLATFORM_DISCOVERED = "platform_discovered"
|
EVENT_PLATFORM_DISCOVERED = "platform_discovered"
|
||||||
|
EVENT_COMPONENT_LOADED = "component_loaded"
|
||||||
|
EVENT_SERVICE_REGISTERED = "service_registered"
|
||||||
|
|
||||||
# #### STATES ####
|
# #### STATES ####
|
||||||
STATE_ON = 'on'
|
STATE_ON = 'on'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user