flexmeasures.utils.validation_utils

Functions

flexmeasures.utils.validation_utils.validate_color_hex(value)

Validates that a given value is a valid hex color code.

Parameters: :value: The color code to validate.

flexmeasures.utils.validation_utils.validate_rate_limit(value: str | None) None

Validate that a value is a rate limit which Flask-Limiter can make sense of.

Accepts limits like “500 per minute”, the special value “unlimited”, and None (which callers use to mean: fall back to the server-wide config setting).

Parameters:

value – The rate limit to validate.

Raises:

ValueError – When the value is not a parseable rate limit.

flexmeasures.utils.validation_utils.validate_url(value)

Validates that a given value is a valid URL format using regex.

Parameters: :value: The URL to validate.

flexmeasures.utils.validation_utils.validate_variable_quantity(variable_quantity: Quantity | list[dict] | Sensor, unit_validator: Callable, data_key: str)

Check if a given value is a sensor or a fixed value (e.g. string), then validate with the unit validator.

Parameters: :param variable_quantity: The value to be validated. :param unit_validator: The validation function used to validate the value’s unit. :param data_key: User-facing data-key of the field that is being validated.