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
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"""Tests for reminder time parsing."""
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from custom_components.meshcore_agent.core.timeparse import (
|
||||
TimeParseError,
|
||||
parse_when,
|
||||
)
|
||||
|
||||
NOW = datetime(2026, 12, 1, 10, 0, 0, tzinfo=timezone.utc) # a Tuesday
|
||||
|
||||
|
||||
def assert_future(value: datetime):
|
||||
assert value > NOW
|
||||
|
||||
|
||||
def test_relative_minutes_hours_days():
|
||||
assert parse_when("in 30m", NOW) == NOW + timedelta(minutes=30)
|
||||
assert parse_when("in 2h", NOW) == NOW + timedelta(hours=2)
|
||||
assert parse_when("in 1d", NOW) == NOW + timedelta(days=1)
|
||||
assert parse_when("in 1h30m", NOW) == NOW + timedelta(hours=1, minutes=30)
|
||||
assert parse_when("In 45 M", NOW) == NOW + timedelta(minutes=45)
|
||||
|
||||
|
||||
def test_relative_rejects_zero():
|
||||
with pytest.raises(TimeParseError):
|
||||
parse_when("in 0m", NOW)
|
||||
|
||||
|
||||
def test_clock_time_same_day():
|
||||
assert parse_when("14:30", NOW) == NOW.replace(hour=14, minute=30)
|
||||
assert parse_when("today 14:30", NOW) == NOW.replace(hour=14, minute=30)
|
||||
with pytest.raises(TimeParseError):
|
||||
parse_when("today 09:15", NOW) # already passed
|
||||
|
||||
|
||||
def test_clock_time_rolls_to_tomorrow():
|
||||
assert parse_when("09:00", NOW) == (NOW + timedelta(days=1)).replace(hour=9)
|
||||
assert parse_when("tomorrow 09:00", NOW) == (NOW + timedelta(days=1)).replace(hour=9)
|
||||
# tomorrow always rolls even if the time already passed today
|
||||
assert parse_when("tomorrow 11:00", NOW) == (NOW + timedelta(days=1)).replace(hour=11)
|
||||
|
||||
|
||||
def test_weekday():
|
||||
# Now is Tuesday; monday is next Monday.
|
||||
expected = (NOW + timedelta(days=6)).replace(hour=8)
|
||||
assert parse_when("monday 08:00", NOW) == expected
|
||||
# Friday is later this week.
|
||||
assert parse_when("friday 18:00", NOW) == (NOW + timedelta(days=3)).replace(hour=18)
|
||||
# Tuesday same day, later hour.
|
||||
assert parse_when("tuesday 12:00", NOW) == NOW.replace(hour=12)
|
||||
# Tuesday same hour rolls a week ahead.
|
||||
assert parse_when("tuesday 10:00", NOW) == (NOW + timedelta(days=7)).replace(hour=10)
|
||||
|
||||
|
||||
def test_absolute_date():
|
||||
assert parse_when("2026-12-24 14:30", NOW) == datetime(
|
||||
2026, 12, 24, 14, 30, tzinfo=timezone.utc
|
||||
)
|
||||
# Date without time defaults to 09:00.
|
||||
assert parse_when("2026-12-24", NOW) == datetime(
|
||||
2026, 12, 24, 9, 0, tzinfo=timezone.utc
|
||||
)
|
||||
|
||||
|
||||
def test_invalid_inputs():
|
||||
for bad in ("", "gibberish", "in ", "25:00", "tomorrow 24:30", "2026-13-01", "2026-02-30 10:00"):
|
||||
with pytest.raises((TimeParseError, ValueError)):
|
||||
parse_when(bad, NOW)
|
||||
|
||||
|
||||
def test_requires_aware_now():
|
||||
naive = datetime(2026, 12, 1, 10, 0)
|
||||
with pytest.raises(ValueError):
|
||||
parse_when("in 30m", naive)
|
||||
Reference in New Issue
Block a user