Coverage for custom_components/supernotify/context.py: 39%
33 statements
« prev ^ index » next coverage.py v7.10.6, created at 2026-01-07 15:35 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2026-01-07 15:35 +0000
1from __future__ import annotations
3import logging
4from pathlib import Path
5from typing import TYPE_CHECKING, Any
7from homeassistant.helpers.typing import ConfigType
9if TYPE_CHECKING:
10 from .archive import NotificationArchive
11 from .common import DupeChecker
12 from .media_grab import MediaStorage
13 from .scenario import ScenarioRegistry
14 from .snoozer import Snoozer
15from homeassistant.helpers import condition as condition
17from . import (
18 CONF_CAMERA,
19)
20from .common import ensure_list
22if TYPE_CHECKING:
23 from homeassistant.helpers.typing import ConfigType
25 from .delivery import DeliveryRegistry
26 from .hass_api import HomeAssistantAPI
27 from .people import PeopleRegistry
28 from .transport import Transport
31_LOGGER = logging.getLogger(__name__)
34class Context:
35 def __init__(
36 self,
37 hass_api: HomeAssistantAPI,
38 people_registry: PeopleRegistry,
39 scenario_registry: ScenarioRegistry,
40 delivery_registry: DeliveryRegistry,
41 dupe_checker: DupeChecker,
42 archive: NotificationArchive,
43 media_storage: MediaStorage,
44 snoozer: Snoozer,
45 links: list[str] | None = None,
46 recipients: list[dict[str, Any]] | None = None,
47 mobile_actions: ConfigType | None = None,
48 template_path: str | None = None,
49 cameras: list[ConfigType] | None = None,
50 **kwargs: Any,
51 ) -> None:
52 self.delivery_registry: DeliveryRegistry = delivery_registry
53 self.snoozer: Snoozer = snoozer
54 self.dupe_checker = dupe_checker
55 self.people_registry: PeopleRegistry = people_registry
56 self.scenario_registry: ScenarioRegistry = scenario_registry
57 self.archive: NotificationArchive = archive
58 self.hass_api: HomeAssistantAPI = hass_api
59 self.media_storage: MediaStorage = media_storage
60 self.links: list[dict[str, Any]] = ensure_list(links)
62 self._recipients: list[dict[str, Any]] = ensure_list(recipients)
63 self.mobile_actions: ConfigType = mobile_actions or {}
64 self.custom_template_path: Path | None = Path(template_path) if template_path else None
66 self.cameras: dict[str, Any] = {c[CONF_CAMERA]: c for c in cameras} if cameras else {}
67 self.snoozer = snoozer
68 if kwargs:
69 _LOGGER.warning("SUPERNOTIFY Context threw away kwargs: %s", kwargs)
71 async def initialize(self) -> None:
72 if self.custom_template_path and not self.custom_template_path.exists():
73 _LOGGER.warning("SUPERNOTIFY custom template path not found at %s", self.custom_template_path)
74 self.custom_template_path = None
76 def configure_for_tests(self, transport_instances: list[Transport] | None = None) -> None:
77 self.delivery_registry._transport_instances = transport_instances