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). Flask-Limiter would also take several limits in one string (separated by semicolons), but we accept one, so that each budget is one number, and a reset clears the whole of it.

Parameters:

value – The rate limit to validate.

Raises:

ValueError – When the value is not a parseable rate limit, or holds more than one.

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:

Parameters:
  • variable_quantity – The value to be validated.

  • unit_validator – The validation function used to validate the value’s unit.

  • data_key – User-facing data-key of the field that is being validated.