Files
claude 027ff685b7 Multiple identities via config subentries + regenerate + editable name
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>
2026-07-22 20:29:05 +03:00

57 lines
1.9 KiB
Python

"""Diagnostics support for Reticulum."""
from __future__ import annotations
from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .const import CONF_ALLOWED_IDENTITIES, CONF_DEFAULT_RECIPIENT, DOMAIN
TO_REDACT = {CONF_DEFAULT_RECIPIENT, CONF_ALLOWED_IDENTITIES}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for the hub entry and its identities."""
runtime = hass.data[DOMAIN][entry.entry_id]
stack = runtime.stack.state
identities = []
for subentry_id, manager in runtime.identities.items():
s = manager.state
subentry = entry.subentries.get(subentry_id)
identities.append(
{
"title": subentry.title if subentry else None,
"options": async_redact_data(
dict(subentry.data) if subentry else {}, TO_REDACT
),
"lxmf_address": s.lxmf_address,
"display_name": s.display_name,
"messages_received": s.messages_received,
"messages_sent": s.messages_sent,
"messages_failed": s.messages_failed,
}
)
return {
"entry": {"data": dict(entry.data), "options": dict(entry.options)},
"stack": {
"started": stack.started,
"interface_online": stack.interface_online,
"rxb": stack.tel_rxb,
"txb": stack.tel_txb,
"bitrate": stack.tel_bitrate,
"peer_count": len(stack.peers),
"peers": [
{"name": p.display_name, "hops": p.hops, "stamp_cost": p.stamp_cost}
for p in stack.peers.values()
],
},
"identities": identities,
}