Fix Fully Kiosk set config service (#112840)

* Fixed a bug that prevented setting Fully Kiosk config values using a template

* Added test to cover change

* Fixed issue identified by Ruff

* Update services.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
pull/113036/head
amura11 2024-05-15 07:01:55 -06:00 committed by GitHub
parent 60193a3c2d
commit 2a9d29c5f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 10 deletions

View File

@ -69,18 +69,21 @@ async def async_setup_services(hass: HomeAssistant) -> None:
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]):
key = call.data[ATTR_KEY]
value = call.data[ATTR_VALUE]
# 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]
)
if isinstance(value, bool) or (
isinstance(value, str) and value.lower() in ("true", "false")
):
await coordinator.fully.setConfigurationBool(key, value)
else:
await coordinator.fully.setConfigurationString(
call.data[ATTR_KEY], call.data[ATTR_VALUE]
)
# Convert any int values to string
if isinstance(value, int):
value = str(value)
await coordinator.fully.setConfigurationString(key, value)
# Register all the above services
service_mapping = [
@ -111,7 +114,7 @@ async def async_setup_services(hass: HomeAssistant) -> None:
{
vol.Required(ATTR_DEVICE_ID): cv.ensure_list,
vol.Required(ATTR_KEY): cv.string,
vol.Required(ATTR_VALUE): vol.Any(str, bool),
vol.Required(ATTR_VALUE): vol.Any(str, bool, int),
}
)
),

View File

@ -71,6 +71,22 @@ async def test_services(
mock_fully_kiosk.setConfigurationString.assert_called_once_with(key, value)
key = "test_key"
value = 1234
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_with(key, str(value))
key = "test_key"
value = "true"
await hass.services.async_call(