278 files

This commit is contained in:
Home Assistant Version Control
2026-09-13 20:38:58 +00:00
parent d7a0a08372
commit 1b4f5f68c6
278 changed files with 36892 additions and 7150 deletions
@@ -41,6 +41,7 @@ from .const import (
NOTIF_TYPE_WEEKLY_DIGEST,
)
from .models import NotificationRoute
from .timewindow import is_within_window, parse_hhmm
_LOGGER = logging.getLogger(__name__)
@@ -127,37 +128,10 @@ def _validate_group(value: str) -> str:
return value
def _parse_hhmm(value: str) -> tuple[int, int] | None:
"""Parse "HH:MM" into (hour, minute); None if blank/malformed."""
if not value:
return None
try:
hour, minute = map(int, value.split(":", 1))
except (ValueError, AttributeError):
return None
if 0 <= hour <= 23 and 0 <= minute <= 59:
return hour, minute
return None
def _is_within_quiet_hours(start: str, end: str, now) -> bool:
"""True if ``now`` (a datetime) falls inside the [start, end) HH:MM window.
Both bounds must be set, else quiet hours are disabled. A start later than
the end denotes an overnight window (e.g. 20:00-07:00). The end bound is
exclusive so a window of 07:00-07:00 (equal bounds) is treated as disabled.
"""
s = _parse_hhmm(start)
e = _parse_hhmm(end)
if s is None or e is None or s == e:
return False
cur = now.hour * 60 + now.minute
start_m = s[0] * 60 + s[1]
end_m = e[0] * 60 + e[1]
if start_m < end_m:
return start_m <= cur < end_m
# Overnight window: active from start through midnight to end.
return cur >= start_m or cur < end_m
# Quiet hours reuse the shared time-of-day window helpers (also used by
# time-locked rewards, #857).
_parse_hhmm = parse_hhmm
_is_within_quiet_hours = is_within_window
class _SafeDict(dict):