Move lcn non-config_entry related code to async_setup (#130603)
* Move non-config_entry related code to async_setup * Remove action unload
This commit is contained in:
parent
eea782bbfe
commit
3d84e35268
2 changed files with 23 additions and 17 deletions
|
@ -20,7 +20,8 @@ from homeassistant.const import (
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ADD_ENTITIES_CALLBACKS,
|
ADD_ENTITIES_CALLBACKS,
|
||||||
|
@ -41,15 +42,26 @@ from .helpers import (
|
||||||
register_lcn_address_devices,
|
register_lcn_address_devices,
|
||||||
register_lcn_host_device,
|
register_lcn_host_device,
|
||||||
)
|
)
|
||||||
from .services import SERVICES
|
from .services import register_services
|
||||||
from .websocket import register_panel_and_ws_api
|
from .websocket import register_panel_and_ws_api
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
|
"""Set up the LCN component."""
|
||||||
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
|
await register_services(hass)
|
||||||
|
await register_panel_and_ws_api(hass)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||||
"""Set up a connection to PCHK host from a config entry."""
|
"""Set up a connection to PCHK host from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
if config_entry.entry_id in hass.data[DOMAIN]:
|
if config_entry.entry_id in hass.data[DOMAIN]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -109,15 +121,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||||
)
|
)
|
||||||
lcn_connection.register_for_inputs(input_received)
|
lcn_connection.register_for_inputs(input_received)
|
||||||
|
|
||||||
# register service calls
|
|
||||||
for service_name, service in SERVICES:
|
|
||||||
if not hass.services.has_service(DOMAIN, service_name):
|
|
||||||
hass.services.async_register(
|
|
||||||
DOMAIN, service_name, service(hass).async_call_service, service.schema
|
|
||||||
)
|
|
||||||
|
|
||||||
await register_panel_and_ws_api(hass)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,11 +171,6 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||||
host = hass.data[DOMAIN].pop(config_entry.entry_id)
|
host = hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||||
await host[CONNECTION].async_close()
|
await host[CONNECTION].async_close()
|
||||||
|
|
||||||
# unregister service calls
|
|
||||||
if unload_ok and not hass.data[DOMAIN]: # check if this is the last entry to unload
|
|
||||||
for service_name, _ in SERVICES:
|
|
||||||
hass.services.async_remove(DOMAIN, service_name)
|
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -429,3 +429,11 @@ SERVICES = (
|
||||||
(LcnService.DYN_TEXT, DynText),
|
(LcnService.DYN_TEXT, DynText),
|
||||||
(LcnService.PCK, Pck),
|
(LcnService.PCK, Pck),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def register_services(hass: HomeAssistant) -> None:
|
||||||
|
"""Register services for LCN."""
|
||||||
|
for service_name, service in SERVICES:
|
||||||
|
hass.services.async_register(
|
||||||
|
DOMAIN, service_name, service(hass).async_call_service, service.schema
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue