Coverage for custom_components/supernotify/button.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-08 17:42 +0000

1"""Button platform: reset every runtime override in one press. 

2 

3The same as calling supernotify.reset_overrides with no `kind` - every scenario, recipient, 

4delivery and transport switched on or off at runtime is put back to its configured state. 

5""" 

6 

7from __future__ import annotations 

8 

9from typing import TYPE_CHECKING 

10 

11from homeassistant.components.button import ButtonEntity 

12from homeassistant.const import EntityCategory 

13 

14from .hass_api import ha_device_info 

15 

16if TYPE_CHECKING: 

17 from homeassistant.core import HomeAssistant 

18 from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback 

19 

20 from . import SupernotifyConfigEntry 

21 from .engine import SupernotifyEngine 

22 

23# Entities are pushed, never polled, and their actions only change local state 

24PARALLEL_UPDATES = 0 

25 

26 

27async def async_setup_entry( 

28 hass: HomeAssistant, 

29 entry: SupernotifyConfigEntry, 

30 async_add_entities: AddConfigEntryEntitiesCallback, 

31) -> None: 

32 """Add the reset overrides button.""" 

33 _ = hass 

34 async_add_entities([SupernotifyResetOverridesButton(entry.runtime_data, entry.entry_id)]) 

35 

36 

37class SupernotifyResetOverridesButton(ButtonEntity): 

38 """Put everything switched on or off at runtime back to its configured state.""" 

39 

40 _attr_has_entity_name = True 

41 _attr_entity_category = EntityCategory.CONFIG 

42 _attr_translation_key = "reset_overrides" 

43 _attr_unique_id = "reset_overrides" 

44 _attr_should_poll = False 

45 

46 def __init__(self, engine: SupernotifyEngine, entry_id: str) -> None: 

47 self._engine = engine 

48 self._attr_device_info = ha_device_info(entry_id) 

49 

50 async def async_press(self) -> None: 

51 self._engine.reset_overrides(context=self._context)