From 34827571baa30991d66c6c3bd751fb6c87f69736 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Tue, 27 Jun 2023 14:42:18 -0400 Subject: [PATCH] Add set_config service to Fully Kiosk Browser integration (#95318) Co-authored-by: Paulus Schoutsen Co-authored-by: Paulus Schoutsen --- homeassistant/components/fully_kiosk/const.py | 3 ++ .../components/fully_kiosk/services.py | 34 +++++++++++++ .../components/fully_kiosk/services.yaml | 22 +++++++++ tests/components/fully_kiosk/test_services.py | 49 +++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/homeassistant/components/fully_kiosk/const.py b/homeassistant/components/fully_kiosk/const.py index b4fe90e01eb..3db33d21ef0 100644 --- a/homeassistant/components/fully_kiosk/const.py +++ b/homeassistant/components/fully_kiosk/const.py @@ -25,6 +25,9 @@ MEDIA_SUPPORT_FULLYKIOSK = ( SERVICE_LOAD_URL = "load_url" SERVICE_START_APPLICATION = "start_application" +SERVICE_SET_CONFIG = "set_config" ATTR_URL = "url" ATTR_APPLICATION = "application" +ATTR_KEY = "key" +ATTR_VALUE = "value" diff --git a/homeassistant/components/fully_kiosk/services.py b/homeassistant/components/fully_kiosk/services.py index b3c5886187a..5106fd2e06e 100644 --- a/homeassistant/components/fully_kiosk/services.py +++ b/homeassistant/components/fully_kiosk/services.py @@ -12,9 +12,12 @@ import homeassistant.helpers.device_registry as dr from .const import ( ATTR_APPLICATION, + ATTR_KEY, ATTR_URL, + ATTR_VALUE, DOMAIN, SERVICE_LOAD_URL, + SERVICE_SET_CONFIG, SERVICE_START_APPLICATION, ) from .coordinator import FullyKioskDataUpdateCoordinator @@ -62,6 +65,22 @@ async def async_setup_services(hass: HomeAssistant) -> None: for coordinator in await collect_coordinators(call.data[ATTR_DEVICE_ID]): await coordinator.fully.startApplication(call.data[ATTR_APPLICATION]) + async def async_set_config(call: ServiceCall) -> None: + """Set a Fully Kiosk Browser config value on the device.""" + for coordinator in await collect_coordinators(call.data[ATTR_DEVICE_ID]): + # Fully API has different methods for setting string and bool values. + # check if call.data[ATTR_VALUE] is a bool + if isinstance(call.data[ATTR_VALUE], bool) or call.data[ + ATTR_VALUE + ].lower() in ("true", "false"): + await coordinator.fully.setConfigurationBool( + call.data[ATTR_KEY], call.data[ATTR_VALUE] + ) + else: + await coordinator.fully.setConfigurationString( + call.data[ATTR_KEY], call.data[ATTR_VALUE] + ) + # Register all the above services service_mapping = [ (async_load_url, SERVICE_LOAD_URL, ATTR_URL), @@ -81,3 +100,18 @@ async def async_setup_services(hass: HomeAssistant) -> None: ) ), ) + + hass.services.async_register( + DOMAIN, + SERVICE_SET_CONFIG, + async_set_config, + schema=vol.Schema( + vol.All( + { + vol.Required(ATTR_DEVICE_ID): cv.ensure_list, + vol.Required(ATTR_KEY): cv.string, + vol.Required(ATTR_VALUE): vol.Any(str, bool), + } + ) + ), + ) diff --git a/homeassistant/components/fully_kiosk/services.yaml b/homeassistant/components/fully_kiosk/services.yaml index 88178e35809..1f75e4a0347 100644 --- a/homeassistant/components/fully_kiosk/services.yaml +++ b/homeassistant/components/fully_kiosk/services.yaml @@ -13,6 +13,28 @@ load_url: selector: text: +set_config: + name: Set Configuration + description: Set a configuration parameter on Fully Kiosk Browser. + target: + device: + integration: fully_kiosk + fields: + key: + name: Key + description: Configuration parameter to set. + example: "motionSensitivity" + required: true + selector: + text: + value: + name: Value + description: Value for the configuration parameter. + example: "90" + required: true + selector: + text: + start_application: name: Start Application description: Start an application on the device running Fully Kiosk Browser. diff --git a/tests/components/fully_kiosk/test_services.py b/tests/components/fully_kiosk/test_services.py index 504aa4893e6..11d5a74f3d7 100644 --- a/tests/components/fully_kiosk/test_services.py +++ b/tests/components/fully_kiosk/test_services.py @@ -5,9 +5,12 @@ import pytest from homeassistant.components.fully_kiosk.const import ( ATTR_APPLICATION, + ATTR_KEY, ATTR_URL, + ATTR_VALUE, DOMAIN, SERVICE_LOAD_URL, + SERVICE_SET_CONFIG, SERVICE_START_APPLICATION, ) from homeassistant.const import ATTR_DEVICE_ID @@ -51,6 +54,52 @@ async def test_services( mock_fully_kiosk.startApplication.assert_called_once_with(app) + key = "test_key" + value = "test_value" + + await hass.services.async_call( + DOMAIN, + SERVICE_SET_CONFIG, + { + ATTR_DEVICE_ID: [device_entry.id], + ATTR_KEY: key, + ATTR_VALUE: value, + }, + blocking=True, + ) + + mock_fully_kiosk.setConfigurationString.assert_called_once_with(key, value) + + key = "test_key" + value = "true" + await hass.services.async_call( + DOMAIN, + SERVICE_SET_CONFIG, + { + ATTR_DEVICE_ID: [device_entry.id], + ATTR_KEY: key, + ATTR_VALUE: value, + }, + blocking=True, + ) + + mock_fully_kiosk.setConfigurationBool.assert_called_once_with(key, value) + + key = "test_key" + value = True + await hass.services.async_call( + DOMAIN, + SERVICE_SET_CONFIG, + { + ATTR_DEVICE_ID: [device_entry.id], + ATTR_KEY: key, + ATTR_VALUE: value, + }, + blocking=True, + ) + + mock_fully_kiosk.setConfigurationBool.assert_called_with(key, value) + async def test_service_unloaded_entry( hass: HomeAssistant,