Add config reloaded events for automation and scene (#34664)
parent
07469127ce
commit
1883b1d2a2
|
@ -61,6 +61,8 @@ CONDITION_TYPE_OR = "or"
|
|||
DEFAULT_CONDITION_TYPE = CONDITION_TYPE_AND
|
||||
DEFAULT_INITIAL_STATE = True
|
||||
|
||||
EVENT_AUTOMATION_RELOADED = "automation_reloaded"
|
||||
|
||||
ATTR_LAST_TRIGGERED = "last_triggered"
|
||||
ATTR_VARIABLES = "variables"
|
||||
SERVICE_TRIGGER = "trigger"
|
||||
|
@ -214,6 +216,7 @@ async def async_setup(hass, config):
|
|||
if conf is None:
|
||||
return
|
||||
await _async_process_config(hass, conf, component)
|
||||
hass.bus.async_fire(EVENT_AUTOMATION_RELOADED, context=service_call.context)
|
||||
|
||||
async_register_admin_service(
|
||||
hass, DOMAIN, SERVICE_RELOAD, reload_service_handler, schema=vol.Schema({})
|
||||
|
|
|
@ -75,6 +75,7 @@ def _ensure_no_intersection(value):
|
|||
CONF_SCENE_ID = "scene_id"
|
||||
CONF_SNAPSHOT = "snapshot_entities"
|
||||
DATA_PLATFORM = "homeassistant_scene"
|
||||
EVENT_SCENE_RELOADED = "scene_reloaded"
|
||||
STATES_SCHEMA = vol.All(dict, _convert_states)
|
||||
|
||||
|
||||
|
@ -182,6 +183,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
|
||||
_process_scenes_config(hass, async_add_entities, p_config)
|
||||
|
||||
hass.bus.async_fire(EVENT_SCENE_RELOADED, context=call.context)
|
||||
|
||||
hass.helpers.service.async_register_admin_service(
|
||||
SCENE_DOMAIN, SERVICE_RELOAD, reload_config
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||
import pytest
|
||||
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.automation import DOMAIN
|
||||
from homeassistant.components.automation import DOMAIN, EVENT_AUTOMATION_RELOADED
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_NAME,
|
||||
|
@ -483,6 +483,11 @@ async def test_reload_config_service(hass, calls, hass_admin_user, hass_read_onl
|
|||
assert len(calls) == 1
|
||||
assert calls[0].data.get("event") == "test_event"
|
||||
|
||||
test_reload_event = []
|
||||
hass.bus.async_listen(
|
||||
EVENT_AUTOMATION_RELOADED, lambda event: test_reload_event.append(event)
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.config.load_yaml_config_file",
|
||||
autospec=True,
|
||||
|
@ -505,6 +510,8 @@ async def test_reload_config_service(hass, calls, hass_admin_user, hass_read_onl
|
|||
# De-flake ?!
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(test_reload_event) == 1
|
||||
|
||||
assert hass.states.get("automation.hello") is None
|
||||
assert hass.states.get("automation.bye") is not None
|
||||
listeners = hass.bus.async_listeners()
|
||||
|
|
|
@ -3,6 +3,7 @@ import pytest
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.homeassistant import scene as ha_scene
|
||||
from homeassistant.components.homeassistant.scene import EVENT_SCENE_RELOADED
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
@ -13,6 +14,11 @@ async def test_reload_config_service(hass):
|
|||
"""Test the reload config service."""
|
||||
assert await async_setup_component(hass, "scene", {})
|
||||
|
||||
test_reloaded_event = []
|
||||
hass.bus.async_listen(
|
||||
EVENT_SCENE_RELOADED, lambda event: test_reloaded_event.append(event)
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.config.load_yaml_config_file",
|
||||
autospec=True,
|
||||
|
@ -22,6 +28,7 @@ async def test_reload_config_service(hass):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("scene.hallo") is not None
|
||||
assert len(test_reloaded_event) == 1
|
||||
|
||||
with patch(
|
||||
"homeassistant.config.load_yaml_config_file",
|
||||
|
@ -31,6 +38,7 @@ async def test_reload_config_service(hass):
|
|||
await hass.services.async_call("scene", "reload", blocking=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(test_reloaded_event) == 2
|
||||
assert hass.states.get("scene.hallo") is None
|
||||
assert hass.states.get("scene.bye") is not None
|
||||
|
||||
|
|
Loading…
Reference in New Issue