mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Validate data read from light_profiles.csv
This commit is contained in:
parent
4f3dc2ce8b
commit
6d914126fa
@ -86,7 +86,7 @@ LIGHT_TURN_ON_SCHEMA = vol.Schema({
|
|||||||
ATTR_ENTITY_ID: cv.entity_ids,
|
ATTR_ENTITY_ID: cv.entity_ids,
|
||||||
ATTR_PROFILE: str,
|
ATTR_PROFILE: str,
|
||||||
ATTR_TRANSITION: VALID_TRANSITION,
|
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)),
|
ATTR_RGB_COLOR: vol.All(vol.ExactSequence((cv.byte, cv.byte, cv.byte)),
|
||||||
vol.Coerce(tuple)),
|
vol.Coerce(tuple)),
|
||||||
ATTR_XY_COLOR: vol.All(vol.ExactSequence((cv.small_float, cv.small_float)),
|
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,
|
ATTR_TRANSITION: VALID_TRANSITION,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
PROFILE_SCHEMA = vol.Schema(
|
||||||
|
vol.ExactSequence((str, cv.small_float, cv.small_float, cv.byte))
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -185,15 +189,12 @@ def setup(hass, config):
|
|||||||
next(reader, None)
|
next(reader, None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for profile_id, color_x, color_y, brightness in reader:
|
for rec in reader:
|
||||||
profiles[profile_id] = (float(color_x), float(color_y),
|
profile, color_x, color_y, brightness = PROFILE_SCHEMA(rec)
|
||||||
int(brightness))
|
profiles[profile] = (color_x, color_y, brightness)
|
||||||
except ValueError:
|
except vol.MultipleInvalid as ex:
|
||||||
# ValueError if not 4 values per row
|
_LOGGER.error("Error parsing light profile from %s: %s",
|
||||||
# ValueError if convert to float/int failed
|
profile_path, ex)
|
||||||
_LOGGER.error(
|
|
||||||
"Error parsing light profiles from %s", profile_path)
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_light_service(service):
|
def handle_light_service(service):
|
||||||
|
@ -12,8 +12,8 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||||||
vol.Required(CONF_PLATFORM): str,
|
vol.Required(CONF_PLATFORM): str,
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
byte = vol.All(int, vol.Range(min=0, max=255))
|
byte = vol.All(vol.Coerce(int), vol.Range(min=0, max=255))
|
||||||
small_float = vol.All(float, vol.Range(min=0, max=1))
|
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))
|
latitude = vol.All(vol.Coerce(float), vol.Range(min=-90, max=90))
|
||||||
longitude = vol.All(vol.Coerce(float), vol.Range(min=-180, max=180))
|
longitude = vol.All(vol.Coerce(float), vol.Range(min=-180, max=180))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user