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

27 statements  

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

1"""The parts of Supernotify used, all through its actions and entities so there's no import dependency""" 

2 

3from __future__ import annotations 

4 

5from typing import Any 

6 

7from homeassistant.core import HomeAssistant, callback 

8 

9from .const import SUPERNOTIFY_DOMAIN 

10 

11 

12@callback 

13def supernotify_available(hass: HomeAssistant) -> bool: 

14 return hass.services.has_service(SUPERNOTIFY_DOMAIN, "notify") 

15 

16 

17async def _enquire(hass: HomeAssistant, action: str) -> dict[str, Any]: 

18 response = await hass.services.async_call(SUPERNOTIFY_DOMAIN, action, blocking=True, return_response=True) 

19 return dict(response) if response else {} 

20 

21 

22async def deliveries_by_transport(hass: HomeAssistant) -> dict[str, list[str]]: 

23 """Delivery names for each transport, both those configured and those Supernotify set up itself""" 

24 by_transport: dict[str, list[str]] = {} 

25 # every delivery has a switch, the only place to find one Supernotify set up itself but that 

26 # Delivery Control has made explicit or scenario only, so is neither implicit nor configured 

27 for state in hass.states.async_all("switch"): 

28 if state.entity_id.startswith(f"switch.{SUPERNOTIFY_DOMAIN}_delivery_"): 

29 name, transport = state.attributes.get("name"), state.attributes.get("transport") 

30 if name and transport: 

31 by_transport.setdefault(transport, []).append(name) 

32 implicit = await _enquire(hass, "enquire_implicit_deliveries") 

33 for transport, names in implicit.items(): 

34 known = by_transport.setdefault(transport, []) 

35 known.extend(name for name in names if name not in known) 

36 configured = (await _enquire(hass, "enquire_configuration")).get("delivery") or {} 

37 for name, delivery in configured.items(): 

38 names = by_transport.setdefault(delivery.get("transport", name), []) 

39 if name not in names: 

40 names.append(name) 

41 return by_transport