Standardize Vizio update service schema (#38636)

* update voluptuous schema to match standards and to handle data transformations

* improve test
This commit is contained in:
Raman Gupta 2020-08-07 22:29:54 -04:00 committed by GitHub
parent 50cd6be18d
commit 0d5e279509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View File

@ -34,9 +34,9 @@ ATTR_SETTING_NAME = "setting_name"
ATTR_NEW_VALUE = "new_value"
UPDATE_SETTING_SCHEMA = {
vol.Required(ATTR_SETTING_TYPE): cv.string,
vol.Required(ATTR_SETTING_NAME): cv.string,
vol.Required(ATTR_NEW_VALUE): vol.Or(vol.Coerce(int), cv.string),
vol.Required(ATTR_SETTING_TYPE): vol.All(cv.string, vol.Lower, cv.slugify),
vol.Required(ATTR_SETTING_NAME): vol.All(cv.string, vol.Lower, cv.slugify),
vol.Required(ATTR_NEW_VALUE): vol.Any(vol.Coerce(int), cv.string),
}
CONF_ADDITIONAL_CONFIGS = "additional_configs"

View File

@ -291,9 +291,7 @@ class VizioDevice(MediaPlayerEntity):
) -> None:
"""Update a setting when update_setting service is called."""
await self._device.set_setting(
setting_type.lower().replace(" ", "_"),
setting_name.lower().replace(" ", "_"),
new_value,
setting_type, setting_name, new_value,
)
async def async_added_to_hass(self):

View File

@ -387,12 +387,26 @@ async def test_services(
SERVICE_SELECT_SOUND_MODE,
{ATTR_SOUND_MODE: "Music"},
)
# Test that the update_setting service does config validation/transformation correctly
await _test_service(
hass,
DOMAIN,
"set_setting",
SERVICE_UPDATE_SETTING,
{"setting_type": "Audio", "setting_name": "AV Delay", "new_value": "0"},
"audio",
"av_delay",
0,
)
await _test_service(
hass,
DOMAIN,
"set_setting",
SERVICE_UPDATE_SETTING,
{"setting_type": "Audio", "setting_name": "EQ", "new_value": "Music"},
"audio",
"eq",
"Music",
)