Validate data read from light_profiles.csv
parent
4f3dc2ce8b
commit
6d914126fa
homeassistant
components/light
helpers
|
@ -86,7 +86,7 @@ LIGHT_TURN_ON_SCHEMA = vol.Schema({
|
|||
ATTR_ENTITY_ID: cv.entity_ids,
|
||||
ATTR_PROFILE: str,
|
||||
ATTR_TRANSITION: VALID_TRANSITION,
|
||||
ATTR_BRIGHTNESS: vol.All(int, vol.Range(min=0, max=255)),
|
||||
ATTR_BRIGHTNESS: cv.byte,
|
||||
ATTR_RGB_COLOR: vol.All(vol.ExactSequence((cv.byte, cv.byte, cv.byte)),
|
||||
vol.Coerce(tuple)),
|
||||
ATTR_XY_COLOR: vol.All(vol.ExactSequence((cv.small_float, cv.small_float)),
|
||||
|
@ -106,6 +106,10 @@ LIGHT_TOGGLE_SCHEMA = vol.Schema({
|
|||
ATTR_TRANSITION: VALID_TRANSITION,
|
||||
})
|
||||
|
||||
PROFILE_SCHEMA = vol.Schema(
|
||||
vol.ExactSequence((str, cv.small_float, cv.small_float, cv.byte))
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -185,15 +189,12 @@ def setup(hass, config):
|
|||
next(reader, None)
|
||||
|
||||
try:
|
||||
for profile_id, color_x, color_y, brightness in reader:
|
||||
profiles[profile_id] = (float(color_x), float(color_y),
|
||||
int(brightness))
|
||||
except ValueError:
|
||||
# ValueError if not 4 values per row
|
||||
# ValueError if convert to float/int failed
|
||||
_LOGGER.error(
|
||||
"Error parsing light profiles from %s", profile_path)
|
||||
|
||||
for rec in reader:
|
||||
profile, color_x, color_y, brightness = PROFILE_SCHEMA(rec)
|
||||
profiles[profile] = (color_x, color_y, brightness)
|
||||
except vol.MultipleInvalid as ex:
|
||||
_LOGGER.error("Error parsing light profile from %s: %s",
|
||||
profile_path, ex)
|
||||
return False
|
||||
|
||||
def handle_light_service(service):
|
||||
|
|
|
@ -12,8 +12,8 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||
vol.Required(CONF_PLATFORM): str,
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
byte = vol.All(int, vol.Range(min=0, max=255))
|
||||
small_float = vol.All(float, vol.Range(min=0, max=1))
|
||||
byte = vol.All(vol.Coerce(int), vol.Range(min=0, max=255))
|
||||
small_float = vol.All(vol.Coerce(float), vol.Range(min=0, max=1))
|
||||
latitude = vol.All(vol.Coerce(float), vol.Range(min=-90, max=90))
|
||||
longitude = vol.All(vol.Coerce(float), vol.Range(min=-180, max=180))
|
||||
|
||||
|
|
Loading…
Reference in New Issue