mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve reload of legacy groups (#102925)
* Improve reload of legacy groups * Simplify reload * Get rid of inner function * Fix logic when there are no group.group entities * Update homeassistant/components/group/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> * Fix type hints --------- Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
1a6184a9aa
commit
e880ad7bda
@ -293,14 +293,31 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
await _async_process_config(hass, config)
|
await _async_process_config(hass, config)
|
||||||
|
|
||||||
async def reload_service_handler(service: ServiceCall) -> None:
|
async def reload_service_handler(service: ServiceCall) -> None:
|
||||||
"""Remove all user-defined groups and load new ones from config."""
|
"""Group reload handler.
|
||||||
auto = [e for e in component.entities if e.created_by_service]
|
|
||||||
|
|
||||||
if (conf := await component.async_prepare_reload()) is None:
|
- Remove group.group entities not created by service calls and set them up again
|
||||||
|
- Reload xxx.group platforms
|
||||||
|
"""
|
||||||
|
if (conf := await component.async_prepare_reload(skip_reset=True)) is None:
|
||||||
return
|
return
|
||||||
await _async_process_config(hass, conf)
|
|
||||||
|
|
||||||
await component.async_add_entities(auto)
|
# Simplified + modified version of EntityPlatform.async_reset:
|
||||||
|
# - group.group never retries setup
|
||||||
|
# - group.group never polls
|
||||||
|
# - We don't need to reset EntityPlatform._setup_complete
|
||||||
|
# - Only remove entities which were not created by service calls
|
||||||
|
tasks = [
|
||||||
|
entity.async_remove()
|
||||||
|
for entity in component.entities
|
||||||
|
if entity.entity_id.startswith("group.") and not entity.created_by_service
|
||||||
|
]
|
||||||
|
|
||||||
|
if tasks:
|
||||||
|
await asyncio.gather(*tasks)
|
||||||
|
|
||||||
|
component.config = None
|
||||||
|
|
||||||
|
await _async_process_config(hass, conf)
|
||||||
|
|
||||||
await async_reload_integration_platforms(hass, DOMAIN, PLATFORMS)
|
await async_reload_integration_platforms(hass, DOMAIN, PLATFORMS)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user