1 """Support for LaMetric time services."""
3 from __future__
import annotations
5 from demetriek
import (
18 import voluptuous
as vol
36 from .coordinator
import LaMetricDataUpdateCoordinator
37 from .helpers
import async_get_coordinator_by_device_id
39 SERVICE_BASE_SCHEMA = vol.Schema(
41 vol.Required(CONF_DEVICE_ID): cv.string,
42 vol.Optional(CONF_CYCLES, default=1): cv.positive_int,
43 vol.Optional(CONF_ICON_TYPE, default=NotificationIconType.NONE): vol.Coerce(
46 vol.Optional(CONF_PRIORITY, default=NotificationPriority.INFO): vol.Coerce(
49 vol.Optional(CONF_SOUND): vol.Any(
50 vol.Coerce(AlarmSound), vol.Coerce(NotificationSound)
55 SERVICE_MESSAGE_SCHEMA = SERVICE_BASE_SCHEMA.extend(
57 vol.Required(CONF_MESSAGE): cv.string,
58 vol.Optional(CONF_ICON): cv.string,
62 SERVICE_CHART_SCHEMA = SERVICE_BASE_SCHEMA.extend(
64 vol.Required(CONF_DATA): vol.All(cv.ensure_list, [vol.Coerce(int)]),
71 """Set up services for the LaMetric integration."""
73 async
def _async_service_chart(call: ServiceCall) ->
None:
74 """Send a chart to a LaMetric device."""
76 hass, call.data[CONF_DEVICE_ID]
79 coordinator, call, [Chart(data=call.data[CONF_DATA])]
82 async
def _async_service_message(call: ServiceCall) ->
None:
83 """Send a message to a LaMetric device."""
85 hass, call.data[CONF_DEVICE_ID]
92 icon=call.data.get(CONF_ICON),
93 text=call.data[CONF_MESSAGE],
98 hass.services.async_register(
101 _async_service_chart,
102 schema=SERVICE_CHART_SCHEMA,
105 hass.services.async_register(
108 _async_service_message,
109 schema=SERVICE_MESSAGE_SCHEMA,
114 coordinator: LaMetricDataUpdateCoordinator,
116 frames: list[Chart | Goal | Simple],
118 """Send a notification to an LaMetric device."""
120 if CONF_SOUND
in call.data:
121 sound = Sound(sound=call.data[CONF_SOUND], category=
None)
123 notification = Notification(
124 icon_type=NotificationIconType(call.data[CONF_ICON_TYPE]),
125 priority=NotificationPriority(call.data.get(CONF_PRIORITY)),
128 cycles=call.data[CONF_CYCLES],
134 await coordinator.lametric.notify(notification=notification)
135 except LaMetricError
as ex:
LaMetricDataUpdateCoordinator async_get_coordinator_by_device_id(HomeAssistant hass, str device_id)
None async_send_notification(LaMetricDataUpdateCoordinator coordinator, ServiceCall call, list[Chart|Goal|Simple] frames)
None async_setup_services(HomeAssistant hass)