mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix notify platform setup for KNX (#61842)
* Fix notify platform setup for KNX * Apply review suggestions * Store hass config in DATA_HASS_CONFIG * Readd guard clause
This commit is contained in:
parent
59e4b52065
commit
66b8f87e43
@ -29,6 +29,7 @@ from homeassistant.const import (
|
|||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, ServiceCall
|
from homeassistant.core import Event, HomeAssistant, ServiceCall
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
||||||
@ -44,6 +45,7 @@ from .const import (
|
|||||||
CONF_KNX_INDIVIDUAL_ADDRESS,
|
CONF_KNX_INDIVIDUAL_ADDRESS,
|
||||||
CONF_KNX_ROUTING,
|
CONF_KNX_ROUTING,
|
||||||
CONF_KNX_TUNNELING,
|
CONF_KNX_TUNNELING,
|
||||||
|
DATA_HASS_CONFIG,
|
||||||
DATA_KNX_CONFIG,
|
DATA_KNX_CONFIG,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KNX_ADDRESS,
|
KNX_ADDRESS,
|
||||||
@ -195,6 +197,7 @@ SERVICE_KNX_EXPOSURE_REGISTER_SCHEMA = vol.Any(
|
|||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Start the KNX integration."""
|
"""Start the KNX integration."""
|
||||||
|
hass.data[DATA_HASS_CONFIG] = config
|
||||||
conf: ConfigType | None = config.get(DOMAIN)
|
conf: ConfigType | None = config.get(DOMAIN)
|
||||||
|
|
||||||
if conf is None:
|
if conf is None:
|
||||||
@ -251,15 +254,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(
|
hass.config_entries.async_setup_platforms(
|
||||||
entry, [platform for platform in SUPPORTED_PLATFORMS if platform in config]
|
entry,
|
||||||
|
[
|
||||||
|
platform
|
||||||
|
for platform in SUPPORTED_PLATFORMS
|
||||||
|
if platform in config and platform is not Platform.NOTIFY
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# set up notify platform, no entry support for notify component yet,
|
# set up notify platform, no entry support for notify component yet
|
||||||
# have to use discovery to load platform.
|
if NotifySchema.PLATFORM in config:
|
||||||
if NotifySchema.PLATFORM in conf:
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
discovery.async_load_platform(
|
discovery.async_load_platform(
|
||||||
hass, "notify", DOMAIN, conf[NotifySchema.PLATFORM], config
|
hass, "notify", DOMAIN, {}, hass.data[DATA_HASS_CONFIG]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -312,6 +319,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
platform
|
platform
|
||||||
for platform in SUPPORTED_PLATFORMS
|
for platform in SUPPORTED_PLATFORMS
|
||||||
if platform in hass.data[DATA_KNX_CONFIG]
|
if platform in hass.data[DATA_KNX_CONFIG]
|
||||||
|
and platform is not Platform.NOTIFY
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
|
@ -42,7 +42,10 @@ CONF_STATE_ADDRESS: Final = "state_address"
|
|||||||
CONF_SYNC_STATE: Final = "sync_state"
|
CONF_SYNC_STATE: Final = "sync_state"
|
||||||
CONF_KNX_INITIAL_CONNECTION_TYPES: Final = [CONF_KNX_TUNNELING, CONF_KNX_ROUTING]
|
CONF_KNX_INITIAL_CONNECTION_TYPES: Final = [CONF_KNX_TUNNELING, CONF_KNX_ROUTING]
|
||||||
|
|
||||||
|
# yaml config merged with config entry data
|
||||||
DATA_KNX_CONFIG: Final = "knx_config"
|
DATA_KNX_CONFIG: Final = "knx_config"
|
||||||
|
# original hass yaml config
|
||||||
|
DATA_HASS_CONFIG: Final = "knx_hass_config"
|
||||||
|
|
||||||
ATTR_COUNTER: Final = "counter"
|
ATTR_COUNTER: Final = "counter"
|
||||||
ATTR_SOURCE: Final = "source"
|
ATTR_SOURCE: Final = "source"
|
||||||
|
@ -11,7 +11,8 @@ from homeassistant.const import CONF_NAME
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .const import DOMAIN, KNX_ADDRESS
|
from .const import DATA_KNX_CONFIG, DOMAIN, KNX_ADDRESS
|
||||||
|
from .schema import NotifySchema
|
||||||
|
|
||||||
|
|
||||||
async def async_get_service(
|
async def async_get_service(
|
||||||
@ -20,24 +21,28 @@ async def async_get_service(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> KNXNotificationService | None:
|
) -> KNXNotificationService | None:
|
||||||
"""Get the KNX notification service."""
|
"""Get the KNX notification service."""
|
||||||
if not discovery_info:
|
if discovery_info is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
platform_config: dict = discovery_info
|
if platform_config := hass.data[DATA_KNX_CONFIG].get(NotifySchema.PLATFORM):
|
||||||
xknx: XKNX = hass.data[DOMAIN].xknx
|
xknx: XKNX = hass.data[DOMAIN].xknx
|
||||||
|
|
||||||
notification_devices = []
|
notification_devices = []
|
||||||
for device_config in platform_config:
|
for device_config in platform_config:
|
||||||
notification_devices.append(
|
notification_devices.append(
|
||||||
XknxNotification(
|
XknxNotification(
|
||||||
xknx,
|
xknx,
|
||||||
name=device_config[CONF_NAME],
|
name=device_config[CONF_NAME],
|
||||||
group_address=device_config[KNX_ADDRESS],
|
group_address=device_config[KNX_ADDRESS],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
return (
|
||||||
|
KNXNotificationService(notification_devices)
|
||||||
|
if notification_devices
|
||||||
|
else None
|
||||||
)
|
)
|
||||||
return (
|
|
||||||
KNXNotificationService(notification_devices) if notification_devices else None
|
return None
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class KNXNotificationService(BaseNotificationService):
|
class KNXNotificationService(BaseNotificationService):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user