1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-22 00:10:16 +01:00
Files
core/homeassistant/components/system_bridge/notify.py
T
epenet 6f7fa85d18 Use runtime_data in system_bridge integration (#167880)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 11:53:53 +02:00

79 lines
2.2 KiB
Python

"""Support for System Bridge notification service."""
from __future__ import annotations
import logging
from typing import Any
from systembridgeconnector.models.notification import Notification
from homeassistant.components.notify import (
ATTR_DATA,
ATTR_TITLE,
ATTR_TITLE_DEFAULT,
BaseNotificationService,
)
from homeassistant.const import ATTR_ICON, CONF_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .coordinator import SystemBridgeConfigEntry, SystemBridgeDataUpdateCoordinator
_LOGGER = logging.getLogger(__name__)
ATTR_ACTIONS = "actions"
ATTR_AUDIO = "audio"
ATTR_IMAGE = "image"
ATTR_TIMEOUT = "timeout"
async def async_get_service(
hass: HomeAssistant,
config: ConfigType,
discovery_info: DiscoveryInfoType | None = None,
) -> SystemBridgeNotificationService | None:
"""Get the System Bridge notification service."""
if discovery_info is None:
return None
entry: SystemBridgeConfigEntry | None = hass.config_entries.async_get_entry(
discovery_info[CONF_ENTITY_ID]
)
if entry is None:
return None
return SystemBridgeNotificationService(entry.runtime_data)
class SystemBridgeNotificationService(BaseNotificationService):
"""Implement the notification service for System Bridge."""
def __init__(
self,
coordinator: SystemBridgeDataUpdateCoordinator,
) -> None:
"""Initialize the service."""
self._coordinator: SystemBridgeDataUpdateCoordinator = coordinator
async def async_send_message(
self,
message: str = "",
**kwargs: Any,
) -> None:
"""Send a message."""
data = kwargs.get(ATTR_DATA, {}) or {}
notification = Notification(
actions=data.get(ATTR_ACTIONS),
audio=data.get(ATTR_AUDIO),
icon=data.get(ATTR_ICON),
image=data.get(ATTR_IMAGE),
message=message,
timeout=data.get(ATTR_TIMEOUT),
title=kwargs.get(ATTR_TITLE, data.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)),
)
_LOGGER.debug("Sending notification: %s", notification)
await self._coordinator.websocket_client.send_notification(notification)