Home Assistant Unofficial Reference 2024.12.1
timers.py
Go to the documentation of this file.
1 """Timers for the mobile app."""
2 
3 from datetime import timedelta
4 
5 from homeassistant.components import notify
6 from homeassistant.components.intent import TimerEventType, TimerInfo
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_DEVICE_ID
9 from homeassistant.core import HomeAssistant, callback
10 
11 from . import device_action
12 
13 
14 @callback
16  hass: HomeAssistant,
17  entry: ConfigEntry,
18  event_type: TimerEventType,
19  timer_info: TimerInfo,
20 ) -> None:
21  """Handle timer events."""
22  if event_type != TimerEventType.FINISHED:
23  return
24 
25  if timer_info.name:
26  message = f"{timer_info.name} finished"
27  else:
28  message = f"{timedelta(seconds=timer_info.created_seconds)} timer finished"
29 
30  entry.async_create_task(
31  hass,
32  device_action.async_call_action_from_config(
33  hass,
34  {
35  CONF_DEVICE_ID: timer_info.device_id,
36  notify.ATTR_MESSAGE: message,
37  notify.ATTR_DATA: {
38  "group": "timers",
39  # Android
40  "channel": "Timers",
41  "importance": "high",
42  "ttl": 0,
43  "priority": "high",
44  # iOS
45  "push": {
46  "interruption-level": "time-sensitive",
47  },
48  },
49  },
50  {},
51  None,
52  ),
53  "mobile_app_timer_notification",
54  )
None async_handle_timer_event(HomeAssistant hass, ConfigEntry entry, TimerEventType event_type, TimerInfo timer_info)
Definition: timers.py:20