Fix rest_command reload when the rest_command key is removed (#187262)

This commit is contained in:
Jesse Hills
2026-10-19 04:52:08 +00:00
committed by GitHub
parent 87604108ee
commit 9c5df9cd3d
2 changed files with 20 additions and 1 deletions
@@ -99,7 +99,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
continue
hass.services.async_remove(DOMAIN, existing_service)
for name, command_config in conf[DOMAIN].items():
for name, command_config in conf.get(DOMAIN, {}).items():
async_register_rest_command(name, command_config)
@callback
@@ -48,6 +48,25 @@ async def test_reload(hass: HomeAssistant, setup_component: ComponentSetup) -> N
assert not hass.services.has_service(DOMAIN, "get_test")
async def test_reload_without_domain_config(
hass: HomeAssistant, setup_component: ComponentSetup
) -> None:
"""Verify reload removes all commands when the domain key is gone."""
await setup_component()
assert hass.services.has_service(DOMAIN, "get_test")
with patch(
"homeassistant.config.load_yaml_config_file",
autospec=True,
return_value={},
):
await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True)
assert not hass.services.has_service(DOMAIN, "get_test")
assert hass.services.has_service(DOMAIN, SERVICE_RELOAD)
async def test_setup_tests(
hass: HomeAssistant, setup_component: ComponentSetup
) -> None: