1 """Mobile app utility functions."""
3 from __future__
import annotations
6 from typing
import TYPE_CHECKING
16 ATTR_PUSH_WEBSOCKET_CHANNEL,
25 from .notify
import MobileAppNotificationService
30 """Get webhook ID from device ID."""
31 if DOMAIN
not in hass.data:
34 for cur_webhook_id, cur_device
in hass.data[DOMAIN][DATA_DEVICES].items():
35 if cur_device.id == device_id:
43 """Return if push notifications is supported."""
44 config_entry = hass.data[DOMAIN][DATA_CONFIG_ENTRIES][webhook_id]
45 app_data = config_entry.data[ATTR_APP_DATA]
47 ATTR_PUSH_TOKEN
in app_data
and ATTR_PUSH_URL
in app_data
48 )
or ATTR_PUSH_WEBSOCKET_CHANNEL
in app_data
53 """Return the notify service for this webhook ID."""
54 notify_service: MobileAppNotificationService = hass.data[DOMAIN][DATA_NOTIFY]
56 for target_service, target_webhook_id
in notify_service.registered_targets.items():
57 if target_webhook_id == webhook_id:
63 _CLOUD_HOOK_LOCK = asyncio.Lock()
67 hass: HomeAssistant, webhook_id: str, entry: ConfigEntry |
None
69 """Create a cloud hook."""
70 async
with _CLOUD_HOOK_LOCK:
71 hook = await cloud.async_get_or_create_cloudhook(hass, webhook_id)
73 hass.config_entries.async_update_entry(
74 entry, data={**entry.data, CONF_CLOUDHOOK_URL: hook}
bool supports_push(HomeAssistant hass, str webhook_id)
str async_create_cloud_hook(HomeAssistant hass, str webhook_id, ConfigEntry|None entry)
str|None get_notify_service(HomeAssistant hass, str webhook_id)
str|None webhook_id_from_device_id(HomeAssistant hass, str device_id)