Refactor from one-entry-one-identity to a hub config entry (shared RNS stack) plus config subentries of type "identity", each an independent LXMF identity with its own LXMRouter, address, device and entities. This is required because LXMRouter allows only one delivery identity per instance. - ReticulumStack: owns the single process-wide RNS instance, peer discovery and interface telemetry (hub device). - IdentityManager: one per subentry, its own LXMRouter/identity/destination and delivery callback (identity device). Signal handlers suppressed and atexit handlers tamed for each router too. - Config subentry flow (add / reconfigure identity); a first identity is seeded on stack creation. Editable announce display name = subentry title. - Per-identity "Regenerate identity" button: new address + re-announce (clears the router's single delivery destination first). - Services and events gain an "identity" field to target/distinguish identities. - Per-identity assist bridge, greeting-when-assist-off, allow-list, notify, announce/sync buttons, message counters; hub-level connectivity/telemetry/peers. Verified against current HA config_entries/entity_platform/selector and RNS/LXMF sources. Docs and en/ru translations updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
111 lines
4.4 KiB
Python
111 lines
4.4 KiB
Python
"""Constants for the Reticulum integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Final
|
|
|
|
DOMAIN: Final = "reticulum"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Configuration keys
|
|
# ---------------------------------------------------------------------------
|
|
CONF_TARGET_HOST: Final = "target_host"
|
|
CONF_TARGET_PORT: Final = "target_port"
|
|
CONF_INTERFACE_NAME: Final = "interface_name"
|
|
CONF_DISPLAY_NAME: Final = "display_name"
|
|
|
|
# Options
|
|
CONF_ENABLE_ASSIST: Final = "enable_assist"
|
|
CONF_ASSIST_AGENT: Final = "assist_agent"
|
|
CONF_ASSIST_LANGUAGE: Final = "assist_language"
|
|
CONF_ALLOWED_IDENTITIES: Final = "allowed_identities"
|
|
CONF_ALLOW_ALL: Final = "allow_all_senders"
|
|
CONF_DEFAULT_RECIPIENT: Final = "default_recipient"
|
|
CONF_ANNOUNCE_INTERVAL: Final = "announce_interval"
|
|
CONF_PROPAGATION_NODE: Final = "propagation_node"
|
|
CONF_SYNC_INTERVAL: Final = "sync_interval"
|
|
CONF_DELIVERY_METHOD: Final = "delivery_method"
|
|
CONF_STAMP_COST: Final = "stamp_cost"
|
|
CONF_LOGLEVEL: Final = "loglevel"
|
|
CONF_GREETING: Final = "greeting"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Defaults
|
|
# ---------------------------------------------------------------------------
|
|
DEFAULT_INTERFACE_NAME: Final = "HA TCP Client"
|
|
DEFAULT_DISPLAY_NAME: Final = "Home Assistant"
|
|
DEFAULT_TARGET_PORT: Final = 4242
|
|
DEFAULT_ANNOUNCE_INTERVAL: Final = 1800 # seconds; 0 disables periodic announce
|
|
DEFAULT_SYNC_INTERVAL: Final = 0 # seconds; 0 disables propagation-node sync
|
|
DEFAULT_DELIVERY_METHOD: Final = "direct"
|
|
DEFAULT_STAMP_COST: Final = 0
|
|
DEFAULT_LOGLEVEL: Final = 3 # RNS.LOG_NOTICE
|
|
|
|
DELIVERY_METHODS: Final = ["direct", "opportunistic", "propagated"]
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Subentries
|
|
# ---------------------------------------------------------------------------
|
|
# The config entry is the shared Reticulum stack (RNS + TCP interface); each
|
|
# LXMF identity is a config subentry of this type.
|
|
SUBENTRY_TYPE_IDENTITY: Final = "identity"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Storage
|
|
# ---------------------------------------------------------------------------
|
|
STORAGE_SUBDIR: Final = "reticulum"
|
|
IDENTITIES_SUBDIR: Final = "identities"
|
|
IDENTITY_FILENAME: Final = "identity"
|
|
CONFIG_FILENAME: Final = "config"
|
|
ATTACHMENTS_SUBDIR: Final = "attachments"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Dispatcher signals
|
|
# ---------------------------------------------------------------------------
|
|
# Per-stack and per-identity update signals; suffix with entry_id / subentry_id.
|
|
SIGNAL_STACK_PREFIX: Final = f"{DOMAIN}_stack"
|
|
SIGNAL_IDENTITY_PREFIX: Final = f"{DOMAIN}_identity"
|
|
|
|
|
|
def stack_signal(entry_id: str) -> str:
|
|
"""Dispatcher signal for a stack (hub) state update."""
|
|
return f"{SIGNAL_STACK_PREFIX}_{entry_id}"
|
|
|
|
|
|
def identity_signal(subentry_id: str) -> str:
|
|
"""Dispatcher signal for an identity state update."""
|
|
return f"{SIGNAL_IDENTITY_PREFIX}_{subentry_id}"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Events
|
|
# ---------------------------------------------------------------------------
|
|
EVENT_MESSAGE_RECEIVED: Final = f"{DOMAIN}_message_received"
|
|
EVENT_MESSAGE_DELIVERED: Final = f"{DOMAIN}_message_delivered"
|
|
EVENT_MESSAGE_FAILED: Final = f"{DOMAIN}_message_failed"
|
|
EVENT_ANNOUNCE_RECEIVED: Final = f"{DOMAIN}_announce_received"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Services
|
|
# ---------------------------------------------------------------------------
|
|
SERVICE_SEND_MESSAGE: Final = "send_message"
|
|
SERVICE_ANNOUNCE: Final = "announce"
|
|
SERVICE_REQUEST_PATH: Final = "request_path"
|
|
SERVICE_SYNC_PROPAGATION: Final = "sync_propagation"
|
|
SERVICE_SET_PROPAGATION_NODE: Final = "set_propagation_node"
|
|
|
|
ATTR_DESTINATION: Final = "destination"
|
|
ATTR_CONTENT: Final = "content"
|
|
ATTR_TITLE: Final = "title"
|
|
ATTR_METHOD: Final = "method"
|
|
ATTR_FIELDS: Final = "fields"
|
|
ATTR_MAX_MESSAGES: Final = "max_messages"
|
|
# Which identity a domain service should act through (title or LXMF address).
|
|
# Omit to use the only/first identity.
|
|
ATTR_IDENTITY: Final = "identity"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# LXMF address geometry
|
|
# ---------------------------------------------------------------------------
|
|
# Reticulum truncated destination hashes are 16 bytes -> 32 hex chars.
|
|
DEST_HASH_LEN: Final = 32
|