mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Reload template blueprints when reloading templates (#136794)
This commit is contained in:
parent
f909b54811
commit
d06b0fe340
@ -53,6 +53,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
async def _reload_config(call: Event | ServiceCall) -> None:
|
||||
"""Reload top-level + platforms."""
|
||||
await async_get_blueprints(hass).async_reset_cache()
|
||||
try:
|
||||
unprocessed_conf = await conf_util.async_hass_config_yaml(hass)
|
||||
except HomeAssistantError as err:
|
||||
|
@ -149,6 +149,69 @@ async def test_inverted_binary_sensor(
|
||||
)
|
||||
|
||||
|
||||
async def test_reload_template_when_blueprint_changes(hass: HomeAssistant) -> None:
|
||||
"""Test a template is updated at reload if the blueprint has changed."""
|
||||
hass.states.async_set("binary_sensor.foo", "on", {"friendly_name": "Foo"})
|
||||
config = {
|
||||
DOMAIN: [
|
||||
{
|
||||
"use_blueprint": {
|
||||
"path": "inverted_binary_sensor.yaml",
|
||||
"input": {"reference_entity": "binary_sensor.foo"},
|
||||
},
|
||||
"name": "Inverted foo",
|
||||
},
|
||||
]
|
||||
}
|
||||
with patch_blueprint(
|
||||
"inverted_binary_sensor.yaml",
|
||||
BUILTIN_BLUEPRINT_FOLDER / "inverted_binary_sensor.yaml",
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
hass.states.async_set("binary_sensor.foo", "off", {"friendly_name": "Foo"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("binary_sensor.foo").state == "off"
|
||||
|
||||
inverted = hass.states.get("binary_sensor.inverted_foo")
|
||||
assert inverted
|
||||
assert inverted.state == "on"
|
||||
|
||||
# Reload the automations without any change, but with updated blueprint
|
||||
blueprint_config = yaml_util.load_yaml(
|
||||
BUILTIN_BLUEPRINT_FOLDER / "inverted_binary_sensor.yaml"
|
||||
)
|
||||
blueprint_config["binary_sensor"]["state"] = "{{ states(reference_entity) }}"
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.config.load_yaml_config_file",
|
||||
autospec=True,
|
||||
return_value=config,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.blueprint.models.yaml_util.load_yaml_dict",
|
||||
autospec=True,
|
||||
return_value=blueprint_config,
|
||||
),
|
||||
):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True)
|
||||
|
||||
hass.states.async_set("binary_sensor.foo", "off", {"friendly_name": "Foo"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
not_inverted = hass.states.get("binary_sensor.inverted_foo")
|
||||
assert not_inverted
|
||||
assert not_inverted.state == "off"
|
||||
|
||||
hass.states.async_set("binary_sensor.foo", "on", {"friendly_name": "Foo"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
not_inverted = hass.states.get("binary_sensor.inverted_foo")
|
||||
assert not_inverted
|
||||
assert not_inverted.state == "on"
|
||||
|
||||
|
||||
async def test_domain_blueprint(hass: HomeAssistant) -> None:
|
||||
"""Test DomainBlueprint services."""
|
||||
reload_handler_calls = async_mock_service(hass, DOMAIN, SERVICE_RELOAD)
|
||||
|
Loading…
x
Reference in New Issue
Block a user