Use reload helper to reload rest component (#78491)
This commit is contained in:
parent
2cc45cd302
commit
c37d294d12
1 changed files with 10 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
"""The rest component."""
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
|
@ -26,13 +27,13 @@ from homeassistant.const import (
|
|||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import discovery, template
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import (
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
EntityComponent,
|
||||
from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL
|
||||
from homeassistant.helpers.reload import (
|
||||
async_integration_yaml_config,
|
||||
async_reload_integration_platforms,
|
||||
)
|
||||
from homeassistant.helpers.reload import async_reload_integration_platforms
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
|
@ -54,12 +55,14 @@ COORDINATOR_AWARE_PLATFORMS = [SENSOR_DOMAIN, BINARY_SENSOR_DOMAIN]
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the rest platforms."""
|
||||
component = EntityComponent[Entity](_LOGGER, DOMAIN, hass)
|
||||
_async_setup_shared_data(hass)
|
||||
|
||||
async def reload_service_handler(service: ServiceCall) -> None:
|
||||
"""Remove all user-defined groups and load new ones from config."""
|
||||
if (conf := await component.async_prepare_reload()) is None:
|
||||
conf = None
|
||||
with contextlib.suppress(HomeAssistantError):
|
||||
conf = await async_integration_yaml_config(hass, DOMAIN)
|
||||
if conf is None:
|
||||
return
|
||||
await async_reload_integration_platforms(hass, DOMAIN, PLATFORMS)
|
||||
_async_setup_shared_data(hass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue