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>
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
"""Button platform for Reticulum."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .const import DOMAIN
|
|
from .entity import ReticulumEntity
|
|
from .reticulum_client import ReticulumError, ReticulumManager
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up Reticulum buttons."""
|
|
manager: ReticulumManager = hass.data[DOMAIN][entry.entry_id].manager
|
|
async_add_entities(
|
|
[
|
|
ReticulumAnnounceButton(manager, entry.entry_id),
|
|
ReticulumSyncButton(manager, entry.entry_id),
|
|
]
|
|
)
|
|
|
|
|
|
class ReticulumAnnounceButton(ReticulumEntity, ButtonEntity):
|
|
"""Announce our LXMF destination on demand."""
|
|
|
|
_attr_translation_key = "announce"
|
|
_attr_icon = "mdi:bullhorn"
|
|
|
|
def __init__(self, manager: ReticulumManager, entry_id: str) -> None:
|
|
super().__init__(manager, entry_id)
|
|
self._attr_unique_id = f"{entry_id}_announce"
|
|
|
|
async def async_press(self) -> None:
|
|
try:
|
|
await self._manager.async_announce()
|
|
except ReticulumError as err:
|
|
_LOGGER.warning("Announce failed: %s", err)
|
|
|
|
|
|
class ReticulumSyncButton(ReticulumEntity, ButtonEntity):
|
|
"""Pull queued messages from the configured propagation node."""
|
|
|
|
_attr_translation_key = "sync"
|
|
_attr_icon = "mdi:sync"
|
|
|
|
def __init__(self, manager: ReticulumManager, entry_id: str) -> None:
|
|
super().__init__(manager, entry_id)
|
|
self._attr_unique_id = f"{entry_id}_sync"
|
|
|
|
async def async_press(self) -> None:
|
|
try:
|
|
await self._manager.async_sync_propagation()
|
|
except ReticulumError as err:
|
|
_LOGGER.warning("Propagation sync failed: %s", err)
|