Files
meshcore-ha-agent/tests/test_adapter.py
T
Dejvino 8eba7fa24c Add MeshCore Agent HACS integration: todo module with reminders
Custom HA integration (domain meshcore_agent) that lets MeshCore nodes
manage a todo list over mesh messages:

- todo / todo list, todo add, todo done, todo uncheck, todo remove
- remind <n> <when> / remind off <n> (relative, clock, weekday, absolute)
- replies via meshcore.send_message / send_channel_message
- reminders scheduled with async_track_point_in_time and delivered to
  the sender who set them
- todo list also exposed as a HA todo entity
- config flow with sender allowlist, allow-all toggle, reply length cap
- pure-Python core (core/) covered by pytest; adapter flow tested with
  stubbed hass
2026-12-01 19:15:05 +01:00

39 lines
1.1 KiB
Python

"""Tests for the HA-independent parts of the adapter (truncation, targets)."""
from custom_components.meshcore_agent import target_from_event, truncate
from custom_components.meshcore_agent.core.store import Reminder
def test_truncate_short_untouched():
assert truncate("hello", 200) == "hello"
def test_truncate_long():
text = "a" * 300
out = truncate(text, 200)
assert len(out) == 200
assert out.endswith("...")
def test_truncate_prefers_newline():
text = "line one\n" + "b" * 300
out = truncate(text, 200)
assert out == "line one..."
def test_target_direct():
event = {"message_type": "direct", "pubkey_prefix": "abc123def456"}
assert target_from_event(event) == Reminder(
at="", kind="direct", target="abc123def456"
)
def test_target_channel():
event = {"message_type": "channel", "channel_idx": 2}
assert target_from_event(event) == Reminder(at="", kind="channel", target="2")
def test_target_missing():
assert target_from_event({"message_type": "direct"}) is None
assert target_from_event({"message_type": "channel"}) is None