Coverage for custom_components/camera_autonotify/__init__.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-22 21:32 +0000

1"""Camera AutoNotify - automatic notifications for Frigate camera reviews""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING 

6 

7from homeassistant.components import mqtt 

8from homeassistant.const import CONF_TYPE 

9from homeassistant.exceptions import ConfigEntryNotReady 

10from homeassistant.helpers import config_validation as cv 

11 

12from .const import CONF_SOURCE_ENTRY_ID, DOMAIN, TYPE_DISCOVERY 

13from .device import async_register_device 

14from .discovery import async_discover, async_start_discovery 

15from .frigate import frigate_config, topic_prefix 

16from .hub import ReviewWatcher, async_watch 

17 

18if TYPE_CHECKING: 

19 from homeassistant.config_entries import ConfigEntry 

20 from homeassistant.core import HomeAssistant 

21 from homeassistant.helpers.typing import ConfigType 

22 

23CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) 

24 

25type CameraAutoNotifyConfigEntry = ConfigEntry[ReviewWatcher | None] 

26 

27 

28async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: 

29 async_start_discovery(hass) 

30 return True 

31 

32 

33async def async_setup_entry(hass: HomeAssistant, entry: CameraAutoNotifyConfigEntry) -> bool: 

34 entry.runtime_data = None 

35 if entry.data.get(CONF_TYPE) == TYPE_DISCOVERY: 

36 # nothing to watch, only to look again now that what's discovered may have been switched 

37 async_discover(hass) 

38 return True 

39 config = frigate_config(hass, entry.data[CONF_SOURCE_ENTRY_ID]) 

40 if config is None: 

41 raise ConfigEntryNotReady("Frigate isn't set up yet") 

42 if not await mqtt.async_wait_for_mqtt_client(hass): 

43 raise ConfigEntryNotReady("MQTT isn't available") 

44 watcher = ReviewWatcher(hass, entry) 

45 entry.async_on_unload(await async_watch(hass, topic_prefix(config), watcher)) 

46 entry.runtime_data = watcher 

47 async_register_device(hass, entry, entry.title) 

48 return True 

49 

50 

51async def async_unload_entry(hass: HomeAssistant, entry: CameraAutoNotifyConfigEntry) -> bool: 

52 # the subscription and timers are stopped by the entry's own unload callbacks 

53 return True