Просмотр исходного кода

Remove push-busy and CalDAV support from the Busy module

Busy is now ICS-only; the CalDAV sync path was dead code.
Drops push_caldav, _get_calendar_name, busy_calendar_name config field,
the push-busy CLI action, and its local-sync step.
ZiB 4 месяцев назад
Родитель
Сommit
a556e7394f

+ 0 - 2
room_cal/_utils.py

@@ -216,7 +216,6 @@ class GlobalConfig:
   prices: DefaultPrices = field(default_factory=DefaultPrices)
   reservation_window_days: int = 90
   long_window_days: int = 400
-  busy_calendar_name: str = 'Busy'
 
   @classmethod
   def from_dict(cls, d: dict) -> 'GlobalConfig':
@@ -226,7 +225,6 @@ class GlobalConfig:
       prices=DefaultPrices.from_dict(d.get('prices', {})),
       reservation_window_days=d.get('reservation_window_days', 90),
       long_window_days=d.get('long_window_days', 400),
-      busy_calendar_name=d.get('busy_calendar_name', 'Busy'),
     )
 
 

+ 1 - 11
room_cal/actions/_cli.py

@@ -11,7 +11,6 @@ Usage:
   room-cal fetch-prices 2026-07-01 2026-07-31 [--service airbnb]
   room-cal push-prices 2026-07-01 2026-07-31
   room-cal apply-discounts 2026-07-01 2026-07-31
-  room-cal push-busy 2026-07-01 2026-07-31
   room-cal local-sync 2026-07-01 2026-07-31
   room-cal local-refresh 2026-07-01 2026-07-31
   room-cal diff 2026-07-01 2026-07-31
@@ -115,14 +114,6 @@ async def _apply_discounts(start: date, end: date, args) -> None:
   print(f"  {len(results)} date(s) updated")
 
 
-async def _push_busy(start: date, end: date, args) -> None:
-  from room_cal.actions.push_busy import push_busy
-  result = await push_busy(start, end)
-  for d in result.data['busy']:
-    print(f"  busy: {d}")
-  print(f"  {len(result.data['busy'])} date(s) busy" + (" (changed)" if result.changed else ""))
-
-
 async def _local_sync(start: date, end: date, args) -> None:
   from room_cal.actions.local_sync import local_sync
   await local_sync(start, end)
@@ -348,8 +339,7 @@ _ACTIONS: dict[str, tuple] = {
   'fetch-prices':         (_fetch_prices,         'Fetch service API list prices and write net prices to CalDAV'),
   'push-prices':          (_push_prices,          'Read local CalDAV price events and push list prices to all services'),
   'apply-discounts':      (_apply_discounts,      'Re-apply discount events to price calendar and push changed list prices'),
-  'push-busy':            (_push_busy,            'Sync Busy export calendar from local closed and reservation events'),
-  'local-sync':           (_local_sync,           'Fetch all iCal feeds, apply rules, fill prices, and sync Busy — no service API calls'),
+  'local-sync':           (_local_sync,           'Fetch all iCal feeds, apply rules, and fill prices — no service API calls'),
   'local-refresh':        (_local_refresh,        'Re-write all local Room calendar events (prices, closed, discounts, reservations)'),
   'remote-sync':          (_remote_sync,          'Integrity-check and repair service-side data (e.g. Booking.com rooms_to_sell drift)'),
   'diff':                 (_diff,                 'Compare local CalDAV data to live service APIs and report all differences (read-only)'),

+ 0 - 5
room_cal/actions/local_sync.py

@@ -14,7 +14,6 @@ async def local_sync(start_date: date, end_date: date) -> None:
   1. iCal feeds + user_cal → Closed events (inputs for closed-type rules)
   2. fill_prices → price events must exist before apply_discounts runs
   3. apply_rules → rule-based closed/discounts, then apply_discounts over all prices
-  4. push_busy → reads final closed + reservation state
 
   No service API calls.
   """
@@ -22,7 +21,6 @@ async def local_sync(start_date: date, end_date: date) -> None:
   from room_cal.actions.fetch_user_cal import fetch_user_cal
   from room_cal.actions.fill_prices import fill_prices
   from room_cal.actions.apply_rules import apply_rules
-  from room_cal.actions.push_busy import push_busy
 
   for entry in get_config().calendars:
     result = await fetch_feed(start_date, end_date, feed_name=entry.name)
@@ -37,6 +35,3 @@ async def local_sync(start_date: date, end_date: date) -> None:
   rule_results = await apply_rules(start_date, end_date)
   total = sum(len(v) for v in rule_results.values())
   _log.info("rules: %d event(s) synced", total)
-
-  busy_result = await push_busy(start_date, end_date)
-  _log.info("push-busy: %d date(s) busy%s", len(busy_result.data['busy']), " (changed)" if busy_result.changed else "")

+ 0 - 16
room_cal/actions/push_busy.py

@@ -1,16 +0,0 @@
-from datetime import date
-
-from room_cal.busy import get_dates, push_caldav
-from room_cal._utils import FetchResult
-
-ACTION_SPEC = ('push-busy', [])
-
-
-async def push_busy(start_date: date, end_date: date) -> FetchResult[dict]:
-  """Sync busy dates to the CalDAV busy calendar.
-
-  A day is busy when it has a Closed event or falls within a guest reservation.
-  """
-  busy_dates = await get_dates(start_date, end_date)
-  added, removed = await push_caldav(busy_dates, start_date, end_date)
-  return FetchResult(data={'busy': busy_dates}, changed=bool(added or removed))

+ 1 - 35
room_cal/busy/__init__.py

@@ -4,14 +4,9 @@ from datetime import date, timedelta
 
 from room_cal.closed import Closed
 from room_cal.reservations import Reservation
-from room_cal._utils import get_config, iter_dates
+from room_cal._utils import iter_dates
 
 _BUSY_TITLE = 'Busy'
-DEFAULT_CALENDAR_NAME = 'Busy'
-
-
-def _get_calendar_name() -> str:
-  return get_config().global_.busy_calendar_name or DEFAULT_CALENDAR_NAME
 
 
 async def get_dates(start_date: date, end_date: date) -> list[date]:
@@ -65,32 +60,3 @@ def fingerprint(busy_dates: list[date]) -> str:
   """Stable hash of a sorted busy date list, for cache invalidation."""
   key = ','.join(d.isoformat() for d in busy_dates)
   return hashlib.sha256(key.encode()).hexdigest()
-
-
-async def push_caldav(busy_dates: list[date], start_date: date, end_date: date) -> tuple[list[date], list[date]]:
-  """Sync busy_dates to the CalDAV busy calendar over [start_date, end_date].
-
-  Returns (added, removed) date lists.
-  """
-  from room_cal.store import get_calendar
-
-  cal = get_calendar(_get_calendar_name())
-  existing = await cal.fetch_date_range(start_date, end_date)
-
-  existing_by_date = {
-    e['start'].date(): e
-    for e in existing
-    if e['all_day'] and e['title'] == _BUSY_TITLE
-  }
-  target = set(busy_dates)
-  extant = set(existing_by_date)
-
-  to_add = sorted(target - extant)
-  to_remove = sorted(extant - target)
-
-  for d in to_remove:
-    await cal.delete_event(existing_by_date[d])
-  for d in to_add:
-    await cal.create_event(d, _BUSY_TITLE)
-
-  return to_add, to_remove

+ 1 - 2
room_cal/config-all.json

@@ -78,8 +78,7 @@
       "weekend": 72
     },
     "reservation_window_days": 90,
-    "long_window_days": 400,
-    "busy_calendar_name": "Busy"
+    "long_window_days": 400
   },
   "services": {
     "airbnb": {