1 """Services for the Fully Kiosk Browser integration."""
3 from __future__
import annotations
5 import voluptuous
as vol
22 SERVICE_START_APPLICATION,
24 from .coordinator
import FullyKioskDataUpdateCoordinator
28 """Set up the services for the Fully Kiosk Browser integration."""
30 async
def collect_coordinators(
31 device_ids: list[str],
32 ) -> list[FullyKioskDataUpdateCoordinator]:
33 config_entries = list[ConfigEntry]()
34 registry = dr.async_get(hass)
35 for target
in device_ids:
36 device = registry.async_get(target)
38 device_entries = list[ConfigEntry]()
39 for entry_id
in device.config_entries:
40 entry = hass.config_entries.async_get_entry(entry_id)
41 if entry
and entry.domain == DOMAIN:
42 device_entries.append(entry)
43 if not device_entries:
45 f
"Device '{target}' is not a {DOMAIN} device"
47 config_entries.extend(device_entries)
50 f
"Device '{target}' not found in device registry"
52 coordinators = list[FullyKioskDataUpdateCoordinator]()
53 for config_entry
in config_entries:
54 if config_entry.state != ConfigEntryState.LOADED:
56 coordinators.append(config_entry.runtime_data)
59 async
def async_load_url(call: ServiceCall) ->
None:
60 """Load a URL on the Fully Kiosk Browser."""
61 for coordinator
in await collect_coordinators(call.data[ATTR_DEVICE_ID]):
62 await coordinator.fully.loadUrl(call.data[ATTR_URL])
64 async
def async_start_app(call: ServiceCall) ->
None:
65 """Start an app on the device."""
66 for coordinator
in await collect_coordinators(call.data[ATTR_DEVICE_ID]):
67 await coordinator.fully.startApplication(call.data[ATTR_APPLICATION])
69 async
def async_set_config(call: ServiceCall) ->
None:
70 """Set a Fully Kiosk Browser config value on the device."""
71 for coordinator
in await collect_coordinators(call.data[ATTR_DEVICE_ID]):
72 key = call.data[ATTR_KEY]
73 value = call.data[ATTR_VALUE]
77 if isinstance(value, bool)
or (
78 isinstance(value, str)
and value.lower()
in (
"true",
"false")
80 await coordinator.fully.setConfigurationBool(key, value)
83 if isinstance(value, int):
86 await coordinator.fully.setConfigurationString(key, value)
90 (async_load_url, SERVICE_LOAD_URL, ATTR_URL),
91 (async_start_app, SERVICE_START_APPLICATION, ATTR_APPLICATION),
93 for service_handler, service_name, attrib
in service_mapping:
94 hass.services.async_register(
101 vol.Required(ATTR_DEVICE_ID): cv.ensure_list,
102 vol.Required(attrib): cv.string,
108 hass.services.async_register(
115 vol.Required(ATTR_DEVICE_ID): cv.ensure_list,
116 vol.Required(ATTR_KEY): cv.string,
117 vol.Required(ATTR_VALUE): vol.Any(str, bool, int),
None async_setup_services(HomeAssistant hass)