mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
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>
This commit is contained in:
parent
16fe79db75
commit
34827571ba
@ -25,6 +25,9 @@ MEDIA_SUPPORT_FULLYKIOSK = (
|
|||||||
|
|
||||||
SERVICE_LOAD_URL = "load_url"
|
SERVICE_LOAD_URL = "load_url"
|
||||||
SERVICE_START_APPLICATION = "start_application"
|
SERVICE_START_APPLICATION = "start_application"
|
||||||
|
SERVICE_SET_CONFIG = "set_config"
|
||||||
|
|
||||||
ATTR_URL = "url"
|
ATTR_URL = "url"
|
||||||
ATTR_APPLICATION = "application"
|
ATTR_APPLICATION = "application"
|
||||||
|
ATTR_KEY = "key"
|
||||||
|
ATTR_VALUE = "value"
|
||||||
|
@ -12,9 +12,12 @@ import homeassistant.helpers.device_registry as dr
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_APPLICATION,
|
ATTR_APPLICATION,
|
||||||
|
ATTR_KEY,
|
||||||
ATTR_URL,
|
ATTR_URL,
|
||||||
|
ATTR_VALUE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_LOAD_URL,
|
SERVICE_LOAD_URL,
|
||||||
|
SERVICE_SET_CONFIG,
|
||||||
SERVICE_START_APPLICATION,
|
SERVICE_START_APPLICATION,
|
||||||
)
|
)
|
||||||
from .coordinator import FullyKioskDataUpdateCoordinator
|
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]):
|
for coordinator in await collect_coordinators(call.data[ATTR_DEVICE_ID]):
|
||||||
await coordinator.fully.startApplication(call.data[ATTR_APPLICATION])
|
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
|
# Register all the above services
|
||||||
service_mapping = [
|
service_mapping = [
|
||||||
(async_load_url, SERVICE_LOAD_URL, ATTR_URL),
|
(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),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@ -13,6 +13,28 @@ load_url:
|
|||||||
selector:
|
selector:
|
||||||
text:
|
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:
|
start_application:
|
||||||
name: Start Application
|
name: Start Application
|
||||||
description: Start an application on the device running Fully Kiosk Browser.
|
description: Start an application on the device running Fully Kiosk Browser.
|
||||||
|
@ -5,9 +5,12 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant.components.fully_kiosk.const import (
|
from homeassistant.components.fully_kiosk.const import (
|
||||||
ATTR_APPLICATION,
|
ATTR_APPLICATION,
|
||||||
|
ATTR_KEY,
|
||||||
ATTR_URL,
|
ATTR_URL,
|
||||||
|
ATTR_VALUE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_LOAD_URL,
|
SERVICE_LOAD_URL,
|
||||||
|
SERVICE_SET_CONFIG,
|
||||||
SERVICE_START_APPLICATION,
|
SERVICE_START_APPLICATION,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_DEVICE_ID
|
from homeassistant.const import ATTR_DEVICE_ID
|
||||||
@ -51,6 +54,52 @@ async def test_services(
|
|||||||
|
|
||||||
mock_fully_kiosk.startApplication.assert_called_once_with(app)
|
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(
|
async def test_service_unloaded_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user