Coverage for custom_components/supernotify/context.py: 97%

31 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-09-01 18:25 +0000

1from __future__ import annotations 

2 

3import logging 

4from typing import TYPE_CHECKING, Any 

5 

6from anyio import Path 

7from homeassistant.helpers.typing import ConfigType 

8 

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 

15 

16from .common import ensure_list 

17from .const import ( 

18 CONF_CAMERA, 

19) 

20 

21if TYPE_CHECKING: 

22 from .delivery import DeliveryRegistry 

23 from .hass_api import HomeAssistantAPI 

24 from .people import PeopleRegistry 

25 from .transport import Transport 

26 

27 

28_LOGGER = logging.getLogger(__name__) 

29 

30 

31class Context: 

32 def __init__( 

33 self, 

34 hass_api: HomeAssistantAPI, 

35 people_registry: PeopleRegistry, 

36 scenario_registry: ScenarioRegistry, 

37 delivery_registry: DeliveryRegistry, 

38 dupe_checker: DupeChecker, 

39 archive: NotificationArchive, 

40 media_storage: MediaStorage, 

41 snoozer: Snoozer, 

42 links: list[str] | None = None, 

43 recipients: list[dict[str, Any]] | None = None, 

44 mobile_actions: ConfigType | None = None, 

45 template_path: str | None = None, 

46 cameras: list[ConfigType] | None = None, 

47 **kwargs: Any, 

48 ) -> None: 

49 self.delivery_registry: DeliveryRegistry = delivery_registry 

50 self.snoozer: Snoozer = snoozer 

51 self.dupe_checker = dupe_checker 

52 self.people_registry: PeopleRegistry = people_registry 

53 self.scenario_registry: ScenarioRegistry = scenario_registry 

54 self.archive: NotificationArchive = archive 

55 self.hass_api: HomeAssistantAPI = hass_api 

56 self.media_storage: MediaStorage = media_storage 

57 self.links: list[dict[str, Any]] = ensure_list(links) 

58 

59 self._recipients: list[dict[str, Any]] = ensure_list(recipients) 

60 self.mobile_actions: ConfigType = mobile_actions or {} 

61 self.custom_template_path: Path | None = Path(template_path) if template_path else None 

62 

63 self.cameras: dict[str, Any] = {c[CONF_CAMERA]: c for c in cameras} if cameras else {} 

64 if kwargs: 

65 _LOGGER.warning("SUPERNOTIFY Context threw away kwargs: %s", kwargs) 

66 

67 async def initialize(self) -> None: 

68 if self.custom_template_path and not await self.custom_template_path.exists(): 

69 _LOGGER.warning("SUPERNOTIFY Custom template path not found at %s", self.custom_template_path) 

70 self.custom_template_path = None 

71 

72 def configure_for_tests(self, transport_instances: list[Transport] | None = None) -> None: 

73 self.delivery_registry._transport_instances = transport_instances