fix: avisar por Telegram los dias desactivados por adelantado

Con el horizonte de 35 dias las ausencias se detectan semanas antes y el
aviso del mismo dia no llegaba nunca. Ahora se avisa una vez al dia
siempre que hoy este desactivado.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 12:36:03 +01:00
parent f2ed694f98
commit d440d5899e

View File

@@ -7,6 +7,7 @@ siguiente evento, asi que un fichaje no se desvia mas de unas decimas.
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import html
import logging import logging
import random import random
import signal import signal
@@ -137,6 +138,13 @@ class Service:
await self.notify(f"⚠️ Google Calendar falló ({e}). Se sigue con el plan.") await self.notify(f"⚠️ Google Calendar falló ({e}). Se sigue con el plan.")
return None return None
async def _avisar_dia_libre(self, day: date, motivo: str) -> None:
"""Avisa una sola vez por dia de que hoy no se ficha (aunque se reinicie)."""
if self.store.get("aviso_dia_libre") == day.isoformat():
return
self.store.put("aviso_dia_libre", day.isoformat())
await self.notify(f"🌴 Hoy no se ficha: <i>{html.escape(motivo)}</i>")
# --------------------------------------------------------------------- plan # --------------------------------------------------------------------- plan
def _plan_al_dia(self, day: date, cal) -> bool: def _plan_al_dia(self, day: date, cal) -> bool:
"""El plan guardado sigue cuadrando con el calendario de Timenet.""" """El plan guardado sigue cuadrando con el calendario de Timenet."""
@@ -157,6 +165,8 @@ class Service:
ov = self.store.get_override(day) ov = self.store.get_override(day)
if ov and ov["action"] == "off": if ov and ov["action"] == "off":
if day == self.today():
await self._avisar_dia_libre(day, ov["reason"] or "día desactivado")
return [] return []
if not cal.is_workday(day): if not cal.is_workday(day):
@@ -172,7 +182,7 @@ class Service:
if ausencia: if ausencia:
self.store.set_override(day, "off", f"Google Calendar: {ausencia}") self.store.set_override(day, "off", f"Google Calendar: {ausencia}")
if day == self.today(): if day == self.today():
await self.notify(f"🌴 Hoy no se ficha: <i>{ausencia}</i> (Google Calendar)") await self._avisar_dia_libre(day, f"Google Calendar: {ausencia}")
return [] return []
plan = self.planner.plan_day(cal, day, random.Random()) plan = self.planner.plan_day(cal, day, random.Random())