Skip to content

Commit

Permalink
Add set_config service to Fully Kiosk Browser integration (#95318)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
  • Loading branch information
3 people authored Jun 27, 2023
1 parent 16fe79d commit 3482757
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/fully_kiosk/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

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"
34 changes: 34 additions & 0 deletions homeassistant/components/fully_kiosk/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

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
Expand Down Expand Up @@ -62,6 +65,22 @@ async def async_start_app(call: ServiceCall) -> 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),
Expand All @@ -81,3 +100,18 @@ async def async_start_app(call: ServiceCall) -> 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),
}
)
),
)
22 changes: 22 additions & 0 deletions homeassistant/components/fully_kiosk/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
49 changes: 49 additions & 0 deletions tests/components/fully_kiosk/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3482757

Please sign in to comment.