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."""
|
"""The rest component."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
@ -26,13 +27,13 @@ from homeassistant.const import (
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import discovery, template
|
from homeassistant.helpers import discovery, template
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL
|
||||||
from homeassistant.helpers.entity_component import (
|
from homeassistant.helpers.reload import (
|
||||||
DEFAULT_SCAN_INTERVAL,
|
async_integration_yaml_config,
|
||||||
EntityComponent,
|
async_reload_integration_platforms,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.reload import async_reload_integration_platforms
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
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:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the rest platforms."""
|
"""Set up the rest platforms."""
|
||||||
component = EntityComponent[Entity](_LOGGER, DOMAIN, hass)
|
|
||||||
_async_setup_shared_data(hass)
|
_async_setup_shared_data(hass)
|
||||||
|
|
||||||
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."""
|
"""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
|
return
|
||||||
await async_reload_integration_platforms(hass, DOMAIN, PLATFORMS)
|
await async_reload_integration_platforms(hass, DOMAIN, PLATFORMS)
|
||||||
_async_setup_shared_data(hass)
|
_async_setup_shared_data(hass)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue