Bugfix group order (#3323)

* Add ordered dict config validator

* Have group component use ordered dict config validator

* Improve config_validation testing

* update doc string config_validation.ordered_dict

* validate full dict entries

* Further simplify ordered_dict validator.

* Lint fix
This commit is contained in:
Paulus Schoutsen committed 2016-09-21 08:34:22 -07:00
1 parent a6673f6741
commit 287f9c9bda
4 files changed
+84 -9

No files matched your search

+2 -2
View File
@@ -46,12 +46,12 @@ def _conf_preprocess(value):
CONFIG_SCHEMA = vol.Schema({
DOMAIN: {cv.match_all: vol.Schema(vol.All(_conf_preprocess, {
DOMAIN: cv.ordered_dict(vol.All(_conf_preprocess, {
vol.Optional(CONF_ENTITIES): vol.Any(cv.entity_ids, None),
CONF_VIEW: cv.boolean,
CONF_NAME: cv.string,
CONF_ICON: cv.icon,
}))}
}, cv.match_all))
}, extra=vol.ALLOW_EXTRA)
# List of ON/OFF state tuples for groupable states
@@ -1,4 +1,5 @@
"""Helpers for config validation using voluptuous."""
from collections import OrderedDict
from datetime import timedelta
import os
from urllib.parse import urlparse
@@ -290,6 +291,27 @@ def url(value: Any) -> str:
raise vol.Invalid('invalid url')
def ordered_dict(value_validator, key_validator=match_all):
"""Validate an ordered dict validator that maintains ordering.
value_validator will be applied to each value of the dictionary.
key_validator (optional) will be applied to each key of the dictionary.
"""
item_validator = vol.Schema({key_validator: value_validator})
def validator(value):
"""Validate ordered dict."""
config = OrderedDict()
for key, val in value.items():
v_res = item_validator({key: val})
config.update(v_res)
return config
return validator
# Validator helpers
def key_dependency(key, dependency):