Count sent messages at send time; implement first-contact greeting

- messages_sent now increments when a message is queued (async_send_message),
  not only when a delivery proof returns. LXMessage's delivery callback only
  fires on a returned proof (LXMessage.py ~566), which many peers/methods never
  send, so the "Messages sent" sensor was stuck at 0 for messages that were
  actually delivered. The delivery callback now only emits the event.
- Implement the previously-inert "greeting" option: send it automatically the
  first time each sender contacts HA (tracked per sender in RuntimeData).
- Clarify the notify entity (rename to "Send message" / "Отправить сообщение")
  and document greeting + notify in strings/translations/README.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
claude
2026-07-22 19:28:26 +03:00
parent 3be19028b1
commit 9ae6bb09c4
7 changed files with 32 additions and 12 deletions

View File

@@ -80,6 +80,8 @@ class RuntimeData:
# Maps a peer address -> the HA conversation_id we opened for it, so
# each remote user keeps its own Assist conversation context.
self.conversation_ids: dict[str, str] = {}
# Senders we've already greeted this session (first-contact greeting).
self.greeted: set[str] = set()
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@@ -236,6 +238,12 @@ def _make_incoming_handler(
_LOGGER.debug("Ignoring message from non-allowed sender %s", source)
return
# First-contact greeting: send the configured greeting once per sender.
greeting = (options.get(CONF_GREETING) or "").strip()
if greeting and source not in runtime.greeted:
runtime.greeted.add(source)
await _reply(runtime.manager, source, greeting, "Home Assistant")
if not options.get(CONF_ENABLE_ASSIST, True):
return