Add reload support to KNX (#42429)
* Add reload support to KNX * Changes from review (platform reset + asyncio.gather) * Changes from review (proper asyncio.gather usage)
This commit is contained in:
parent
a665e152a9
commit
bbd7402793
1 changed files with 28 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
"""Support KNX devices."""
|
"""Support KNX devices."""
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -19,6 +20,7 @@ from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
SERVICE_RELOAD,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
|
@ -27,7 +29,11 @@ from homeassistant.const import (
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import async_get_platforms
|
||||||
from homeassistant.helpers.event import async_track_state_change_event
|
from homeassistant.helpers.event import async_track_state_change_event
|
||||||
|
from homeassistant.helpers.reload import async_integration_yaml_config
|
||||||
|
from homeassistant.helpers.service import async_register_admin_service
|
||||||
|
from homeassistant.helpers.typing import ServiceCallType
|
||||||
|
|
||||||
from .const import DOMAIN, SupportedPlatforms
|
from .const import DOMAIN, SupportedPlatforms
|
||||||
from .factory import create_knx_device
|
from .factory import create_knx_device
|
||||||
|
@ -172,6 +178,28 @@ async def async_setup(hass, config):
|
||||||
schema=SERVICE_KNX_SEND_SCHEMA,
|
schema=SERVICE_KNX_SEND_SCHEMA,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def reload_service_handler(service_call: ServiceCallType) -> None:
|
||||||
|
"""Remove all KNX components and load new ones from config."""
|
||||||
|
|
||||||
|
# First check for config file. If for some reason it is no longer there
|
||||||
|
# or knx is no longer mentioned, stop the reload.
|
||||||
|
config = await async_integration_yaml_config(hass, DOMAIN)
|
||||||
|
|
||||||
|
if not config or DOMAIN not in config:
|
||||||
|
return
|
||||||
|
|
||||||
|
await hass.data[DOMAIN].xknx.stop()
|
||||||
|
|
||||||
|
await asyncio.gather(
|
||||||
|
*[platform.async_reset() for platform in async_get_platforms(hass, DOMAIN)]
|
||||||
|
)
|
||||||
|
|
||||||
|
await async_setup(hass, config)
|
||||||
|
|
||||||
|
async_register_admin_service(
|
||||||
|
hass, DOMAIN, SERVICE_RELOAD, reload_service_handler, schema=vol.Schema({})
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue