Files
ha-reticulum/custom_components/reticulum/notify.py
claude b40c527515 Add Reticulum/LXMF integration for Home Assistant
Custom integration connecting Home Assistant to a Reticulum network over a
TCPClientInterface and exchanging LXMF messages, with an Assist conversation
bridge, notify entity, sensors (incl. interface telemetry), buttons, services,
bus events and device triggers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 18:08:12 +03:00

58 lines
2.2 KiB
Python

"""Notify platform for Reticulum.
Exposes a ``notify`` entity that sends an LXMF message to the configured
default recipient. For arbitrary destinations use the ``reticulum.send_message``
service instead.
"""
from __future__ import annotations
from homeassistant.components.notify import NotifyEntity, NotifyEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import CONF_DEFAULT_RECIPIENT, CONF_DELIVERY_METHOD, DEFAULT_DELIVERY_METHOD, DOMAIN
from .entity import ReticulumEntity
from .reticulum_client import ReticulumError, ReticulumManager
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Reticulum notify entity."""
manager: ReticulumManager = hass.data[DOMAIN][entry.entry_id].manager
async_add_entities([ReticulumNotify(manager, entry)])
class ReticulumNotify(ReticulumEntity, NotifyEntity):
"""Send LXMF messages to the default recipient."""
_attr_translation_key = "message"
_attr_icon = "mdi:message-fast"
_attr_supported_features = NotifyEntityFeature.TITLE
def __init__(self, manager: ReticulumManager, entry: ConfigEntry) -> None:
super().__init__(manager, entry.entry_id)
self._entry = entry
self._attr_unique_id = f"{entry.entry_id}_notify"
async def async_send_message(self, message: str, title: str | None = None) -> None:
recipient = self._entry.options.get(CONF_DEFAULT_RECIPIENT)
if not recipient:
raise ServiceValidationError(
"No default recipient configured. Set one in the Reticulum "
"integration options, or use the reticulum.send_message service "
"with an explicit destination."
)
method = self._entry.options.get(CONF_DELIVERY_METHOD, DEFAULT_DELIVERY_METHOD)
try:
await self._manager.async_send_message(
recipient, message, title=title or "", method=method
)
except ReticulumError as err:
raise ServiceValidationError(str(err)) from err