Some checks failed
Validate / Hassfest (push) Has been cancelled
Wire the integration to delegate all HA-independent logic to immich-watcher-core, eliminating ~2300 lines of duplicated code. Changes: - const.py: Import shared constants from core, keep HA-specific ones - storage.py: Create HAStorageBackend adapter wrapping HA's Store, use core TelegramFileCache and NotificationQueue via adapter - coordinator.py: Delegate to core ImmichClient for API calls, detect_album_changes() for change detection, and asset_utils for filtering/sorting/URL building. Keep HA-specific event firing. - sensor.py: Replace ~1300 lines of Telegram code with 15-line delegation to core TelegramClient. Keep entity classes unchanged. - __init__.py: Use factory functions for creating core instances with HA storage backends - manifest.json: Add immich-watcher-core dependency Integration line count: 3600 -> 1295 lines (-64%) Zero behavior changes for end users. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3.0 KiB
3.0 KiB
Phase 2: Wire Core Library into HAOS Integration
Status: In progress Parent: primary-plan.md
Goal
Refactor the HAOS integration to delegate to immich-watcher-core for all HA-independent logic, reducing duplication and preparing for the standalone server.
Important: HACS Compatibility
HACS requires custom_components/<domain>/ at the repository root. We cannot move it to packages/haos/. Instead:
custom_components/stays at repo root- The integration imports from
immich_watcher_core(the core library) manifest.jsonlistsimmich-watcher-coreinrequirements(for future PyPI publish)- During development,
pip install -e packages/coremakes imports work - For HACS distribution, we'll publish the core to PyPI
Tasks
1. Update manifest.json [ ]
- Add
immich-watcher-coreto requirements list - Do NOT bump version (only plans/core changed, not integration content yet)
2. Refactor const.py [ ]
- Import shared constants from
immich_watcher_core.constants - Keep HA-specific constants (DOMAIN, CONF_, PLATFORMS, SERVICE_) local
- Re-export shared constants for backward compatibility with other integration files
3. Refactor storage.py [ ]
- Create
HAStorageBackendadapter wrappinghomeassistant.helpers.storage.Storethat satisfiesStorageBackendprotocol from core - Replace
TelegramFileCachewith core's version usingHAStorageBackend - Replace
NotificationQueuewith core's version usingHAStorageBackend - Keep
ImmichAlbumStorageas-is (HA-specific album state management)
4. Refactor coordinator.py [ ]
- Remove dataclass definitions (SharedLinkInfo, AssetInfo, AlbumData, AlbumChange) — import from core
- Replace Immich API methods with
ImmichClientfrom core - Replace
_detect_change()withdetect_album_changes()from core - Replace
_build_asset_detail()and URL helpers withasset_utilsfrom core - Replace
async_get_assets()filtering/sorting withfilter_assets()+sort_assets()from core - Keep HA-specific:
DataUpdateCoordinatorsubclass,_fire_events(),async_get_clientsession()
5. Refactor sensor.py [ ]
- Remove Telegram constants, helper functions, and all
_send_telegram_*methods - Replace with
TelegramClientfrom core in_execute_telegram_notification() - Keep HA-specific: entity classes, service registration, platform setup
6. Update init.py [ ]
- Update imports for new storage classes (HAStorageBackend adapter)
- Create TelegramFileCache instances using core class + HA adapter
7. Verify [ ]
- All existing entities, services, and events work identically
- Telegram notifications work with caching
- Quiet hours queueing works
- No HA import in core library (verify with grep)
Acceptance Criteria
- Integration imports and delegates to
immich_watcher_core - Zero behavior changes for end users
- No duplicated logic between core and integration
- Core library has no HA imports (verified)
ImmichAlbumStorageis the only storage class still HA-native