Add set_config service to Fully Kiosk Browser integration (#95318)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
pull/94194/head
Charles Garwood 2023-06-27 14:42:18 -04:00 committed by GitHub
parent 16fe79db75
commit 34827571ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 0 deletions

View File

@ -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"

View File

@ -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),
}
)
),
)

View File

@ -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.

View File

@ -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,