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

23 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-12 15:40 +0000

1"""Appliance Auto Notify - automatic notifications for household appliance cycles""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING 

6 

7from homeassistant.const import CONF_TYPE 

8from homeassistant.helpers import config_validation as cv 

9 

10from .const import DOMAIN, TYPE_DISCOVERY, TYPE_POWER 

11from .discovery import async_discover, async_start_discovery 

12from .watcher import ApplianceWatcher, HomeConnectWatcher, PowerWatcher 

13 

14if TYPE_CHECKING: 

15 from homeassistant.config_entries import ConfigEntry 

16 from homeassistant.core import HomeAssistant 

17 from homeassistant.helpers.typing import ConfigType 

18 

19CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) 

20 

21type AppliancesConfigEntry = ConfigEntry[ApplianceWatcher] 

22 

23 

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

25 async_start_discovery(hass) 

26 return True 

27 

28 

29async def async_setup_entry(hass: HomeAssistant, entry: AppliancesConfigEntry) -> bool: 

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

31 # nothing to watch, only to look again now that automatic discovery may have been switched 

32 async_discover(hass) 

33 return True 

34 watcher_class = PowerWatcher if entry.data.get(CONF_TYPE) == TYPE_POWER else HomeConnectWatcher 

35 watcher: ApplianceWatcher = watcher_class(hass, entry) 

36 watcher.async_start() 

37 entry.runtime_data = watcher 

38 return True 

39 

40 

41async def async_unload_entry(hass: HomeAssistant, entry: AppliancesConfigEntry) -> bool: 

42 # the watcher's listeners are removed by the entry's own unload callbacks 

43 return True