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
« 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"""
3from __future__ import annotations
5from typing import TYPE_CHECKING
7from homeassistant.const import CONF_TYPE
8from homeassistant.helpers import config_validation as cv
10from .const import DOMAIN, TYPE_DISCOVERY, TYPE_POWER
11from .discovery import async_discover, async_start_discovery
12from .watcher import ApplianceWatcher, HomeConnectWatcher, PowerWatcher
14if TYPE_CHECKING:
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.typing import ConfigType
19CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
21type AppliancesConfigEntry = ConfigEntry[ApplianceWatcher]
24async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
25 async_start_discovery(hass)
26 return True
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
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