Move quiet hours from hub config to per-call service params
All checks were successful
Validate / Hassfest (push) Successful in 1m19s
All checks were successful
Validate / Hassfest (push) Successful in 1m19s
Quiet hours are now specified per send_telegram_notification call via quiet_hours_start/quiet_hours_end params instead of being a hub-wide integration option. This allows different automations to use different quiet hours windows (or none at all). - Remove quiet_hours_start/end from config options UI and const.py - Add quiet_hours_start/end as optional HH:MM params on the service - Remove ignore_quiet_hours param (omit quiet hours params to send immediately) - Queue stores quiet_hours_end per item; each unique end time gets its own async_track_time_change timer for replay - On startup, items whose quiet hours have passed are sent immediately - Add async_remove_indices() to NotificationQueue for selective removal - Timers are cleaned up when no more items need them Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,8 +41,6 @@ from .const import (
|
||||
CONF_ALBUM_ID,
|
||||
CONF_ALBUM_NAME,
|
||||
CONF_HUB_NAME,
|
||||
CONF_QUIET_HOURS_END,
|
||||
CONF_QUIET_HOURS_START,
|
||||
CONF_TELEGRAM_BOT_TOKEN,
|
||||
DOMAIN,
|
||||
SERVICE_GET_ASSETS,
|
||||
@@ -246,7 +244,8 @@ async def async_setup_entry(
|
||||
vol.Optional("chat_action", default="typing"): vol.Any(
|
||||
None, vol.In(["", "typing", "upload_photo", "upload_video", "upload_document"])
|
||||
),
|
||||
vol.Optional("ignore_quiet_hours", default=False): bool,
|
||||
vol.Optional("quiet_hours_start"): vol.Match(r"^\d{2}:\d{2}$"),
|
||||
vol.Optional("quiet_hours_end"): vol.Match(r"^\d{2}:\d{2}$"),
|
||||
},
|
||||
"async_send_telegram_notification",
|
||||
supports_response=SupportsResponse.OPTIONAL,
|
||||
@@ -337,13 +336,12 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
)
|
||||
return {"assets": assets}
|
||||
|
||||
def _is_quiet_hours(self) -> bool:
|
||||
"""Check if current time is within configured quiet hours."""
|
||||
@staticmethod
|
||||
def _is_quiet_hours(start_str: str | None, end_str: str | None) -> bool:
|
||||
"""Check if current time is within quiet hours."""
|
||||
from datetime import time as dt_time
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
start_str = self._entry.options.get(CONF_QUIET_HOURS_START, "")
|
||||
end_str = self._entry.options.get(CONF_QUIET_HOURS_END, "")
|
||||
if not start_str or not end_str:
|
||||
return False
|
||||
|
||||
@@ -375,7 +373,8 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
max_asset_data_size: int | None = None,
|
||||
send_large_photos_as_documents: bool = False,
|
||||
chat_action: str | None = "typing",
|
||||
ignore_quiet_hours: bool = False,
|
||||
quiet_hours_start: str | None = None,
|
||||
quiet_hours_end: str | None = None,
|
||||
) -> ServiceResponse:
|
||||
"""Send notification to Telegram.
|
||||
|
||||
@@ -393,7 +392,8 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
and the service will return immediately.
|
||||
"""
|
||||
# Check quiet hours — queue notification if active
|
||||
if not ignore_quiet_hours and self._is_quiet_hours():
|
||||
if self._is_quiet_hours(quiet_hours_start, quiet_hours_end):
|
||||
from . import _register_queue_timers, ImmichConfigEntry
|
||||
queue: NotificationQueue = self.hass.data[DOMAIN][self._entry.entry_id]["notification_queue"]
|
||||
await queue.async_enqueue({
|
||||
"entity_id": self.entity_id,
|
||||
@@ -409,7 +409,11 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
"max_asset_data_size": max_asset_data_size,
|
||||
"send_large_photos_as_documents": send_large_photos_as_documents,
|
||||
"chat_action": chat_action,
|
||||
"quiet_hours_start": quiet_hours_start,
|
||||
"quiet_hours_end": quiet_hours_end,
|
||||
})
|
||||
# Register timer for this end time if not already registered
|
||||
_register_queue_timers(self.hass, self._entry)
|
||||
return {"success": True, "status": "queued_quiet_hours"}
|
||||
|
||||
# If non-blocking mode, create a background task and return immediately
|
||||
|
||||
Reference in New Issue
Block a user