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>
This commit is contained in:
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: async def async_set_config(call: ServiceCall) -> None:
"""Set a Fully Kiosk Browser config value on the device.""" """Set a Fully Kiosk Browser config value on the device."""
for coordinator in await collect_coordinators(call.data[ATTR_DEVICE_ID]): 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. # Fully API has different methods for setting string and bool values.
# check if call.data[ATTR_VALUE] is a bool # check if call.data[ATTR_VALUE] is a bool
if isinstance(call.data[ATTR_VALUE], bool) or call.data[ if isinstance(value, bool) or (
ATTR_VALUE isinstance(value, str) and value.lower() in ("true", "false")
].lower() in ("true", "false"): ):
await coordinator.fully.setConfigurationBool( await coordinator.fully.setConfigurationBool(key, value)
call.data[ATTR_KEY], call.data[ATTR_VALUE]
)
else: else:
await coordinator.fully.setConfigurationString( # Convert any int values to string
call.data[ATTR_KEY], call.data[ATTR_VALUE] if isinstance(value, int):
) value = str(value)
await coordinator.fully.setConfigurationString(key, value)
# Register all the above services # Register all the above services
service_mapping = [ 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_DEVICE_ID): cv.ensure_list,
vol.Required(ATTR_KEY): cv.string, 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) 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" key = "test_key"
value = "true" value = "true"
await hass.services.async_call( await hass.services.async_call(