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

19 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-26 20:57 +0000

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

2 

3from typing import Any 

4 

5from homeassistant.core import HomeAssistant, callback 

6from homeassistant.exceptions import HomeAssistantError 

7 

8SUPERNOTIFY_DOMAIN = "supernotify" 

9 

10 

11@callback 

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

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

14 

15 

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

17 try: 

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

19 except HomeAssistantError: 

20 # an older Supernotify without the action 

21 return {} 

22 return dict(response) if response else {} 

23 

24 

25async def deliveries(hass: HomeAssistant) -> list[str]: 

26 """Delivery names, both those configured and those Supernotify set up itself""" 

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

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

29 names: set[str] = { 

30 state.attributes["name"] 

31 for state in hass.states.async_all("switch") 

32 if state.entity_id.startswith(f"switch.{SUPERNOTIFY_DOMAIN}_delivery_") and state.attributes.get("name") 

33 } 

34 for implicit in (await _enquire(hass, "enquire_implicit_deliveries")).values(): 

35 names.update(implicit) 

36 names.update((await _enquire(hass, "enquire_configuration")).get("delivery") or {}) 

37 return sorted(names)