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

30 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-08 17:42 +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 recipients: list[dict[str, Any]] | None = None, 

43 mobile_actions: ConfigType | None = None, 

44 template_path: str | None = None, 

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

46 **kwargs: Any, 

47 ) -> None: 

48 self.delivery_registry: DeliveryRegistry = delivery_registry 

49 self.snoozer: Snoozer = snoozer 

50 self.dupe_checker = dupe_checker 

51 self.people_registry: PeopleRegistry = people_registry 

52 self.scenario_registry: ScenarioRegistry = scenario_registry 

53 self.archive: NotificationArchive = archive 

54 self.hass_api: HomeAssistantAPI = hass_api 

55 self.media_storage: MediaStorage = media_storage 

56 

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

58 self.mobile_actions: ConfigType = mobile_actions or {} 

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

60 

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

62 if kwargs: 

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

64 

65 async def initialize(self) -> None: 

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

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

68 self.custom_template_path = None 

69 

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

71 self.delivery_registry._transport_instances = transport_instances