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>
This commit is contained in:
57
custom_components/reticulum/notify.py
Normal file
57
custom_components/reticulum/notify.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user