mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Create KNX notify entities directly from config (#50709)
This commit is contained in:
parent
c2e2b046d9
commit
3200b0150a
@ -9,7 +9,6 @@ from xknx.devices import (
|
||||
Cover as XknxCover,
|
||||
Device as XknxDevice,
|
||||
Light as XknxLight,
|
||||
Notification as XknxNotification,
|
||||
Sensor as XknxSensor,
|
||||
Weather as XknxWeather,
|
||||
)
|
||||
@ -46,9 +45,6 @@ def create_knx_device(
|
||||
if platform is SupportedPlatforms.SENSOR:
|
||||
return _create_sensor(knx_module, config)
|
||||
|
||||
if platform is SupportedPlatforms.NOTIFY:
|
||||
return _create_notify(knx_module, config)
|
||||
|
||||
if platform is SupportedPlatforms.BINARY_SENSOR:
|
||||
return _create_binary_sensor(knx_module, config)
|
||||
|
||||
@ -269,15 +265,6 @@ def _create_sensor(knx_module: XKNX, config: ConfigType) -> XknxSensor:
|
||||
)
|
||||
|
||||
|
||||
def _create_notify(knx_module: XKNX, config: ConfigType) -> XknxNotification:
|
||||
"""Return a KNX notification to be used within XKNX."""
|
||||
return XknxNotification(
|
||||
knx_module,
|
||||
name=config[CONF_NAME],
|
||||
group_address=config[KNX_ADDRESS],
|
||||
)
|
||||
|
||||
|
||||
def _create_binary_sensor(knx_module: XKNX, config: ConfigType) -> XknxBinarySensor:
|
||||
"""Return a KNX binary sensor to be used within XKNX."""
|
||||
device_name = config[CONF_NAME]
|
||||
|
@ -3,13 +3,15 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from xknx import XKNX
|
||||
from xknx.devices import Notification as XknxNotification
|
||||
|
||||
from homeassistant.components.notify import BaseNotificationService
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, KNX_ADDRESS
|
||||
|
||||
|
||||
async def async_get_service(
|
||||
@ -18,10 +20,21 @@ async def async_get_service(
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> KNXNotificationService | None:
|
||||
"""Get the KNX notification service."""
|
||||
if not discovery_info or not discovery_info["platform_config"]:
|
||||
return None
|
||||
|
||||
platform_config = discovery_info["platform_config"]
|
||||
xknx: XKNX = hass.data[DOMAIN].xknx
|
||||
|
||||
notification_devices = []
|
||||
for device in hass.data[DOMAIN].xknx.devices:
|
||||
if isinstance(device, XknxNotification):
|
||||
notification_devices.append(device)
|
||||
for device_config in platform_config:
|
||||
notification_devices.append(
|
||||
XknxNotification(
|
||||
xknx,
|
||||
name=device_config[CONF_NAME],
|
||||
group_address=device_config[KNX_ADDRESS],
|
||||
)
|
||||
)
|
||||
return (
|
||||
KNXNotificationService(notification_devices) if notification_devices else None
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user