flexmeasures.api.common.schemas.sensors

Classes

class flexmeasures.api.common.schemas.sensors.SensorField(entity_type: str = 'sensor', fm_scheme: str = 'fm1', *args, **kwargs)

Field that de-serializes to a Sensor, and serializes a Sensor into an entity address (string).

__init__(entity_type: str = 'sensor', fm_scheme: str = 'fm1', *args, **kwargs)
Parameters:
  • entity_type – “sensor” (in the future, possibly also another type of resource that is assigned an entity address)

  • fm_scheme – “fm0” or “fm1”

_deserialize(value, attr, obj, **kwargs) Sensor

De-serialize to a Sensor.

_serialize(value: Sensor, attr, data, **kwargs)

Serialize to an entity address.

class flexmeasures.api.common.schemas.sensors.SensorIdField(*, strict: bool = False, **kwargs)

Field that represents a sensor ID. It de-serializes from the sensor id to a sensor instance.

_deserialize(sensor_id: int, attr, obj, **kwargs) Sensor

Deserialize value. Concrete Field classes should implement this method.

Parameters:
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load <marshmallow.Schema.load>.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – In case of formatting or validation failure.

Returns:

The deserialized value.

Changed in version 3.0.0: Added **kwargs to signature.

_serialize(sensor: Sensor, attr, data, **kwargs) int

Return a string if self.as_string=True, otherwise return this field’s num_type.

class flexmeasures.api.common.schemas.sensors.UnitField(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: types.Validator | typing.Iterable[types.Validator] | None = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)

Field that represents a unit.

_deserialize(value, attr, data, **kwargs) str

Deserialize value. Concrete Field classes should implement this method.

Parameters:
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load <marshmallow.Schema.load>.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – In case of formatting or validation failure.

Returns:

The deserialized value.

Changed in version 3.0.0: Added **kwargs to signature.

_serialize(value: str, attr, obj, **kwargs) str

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ""
        return str(value).title()
Parameters:
  • value – The value to be serialized.

  • attr – The attribute or key on the object to be serialized.

  • obj – The object the value was pulled from.

  • kwargs – Field-specific keyword arguments.

Returns:

The serialized value

Exceptions

exception flexmeasures.api.common.schemas.sensors.EntityAddressValidationError(message: str | list | dict, field_name: str = '_schema', data: Mapping[str, Any] | Iterable[Mapping[str, Any]] | None = None, valid_data: list[dict[str, Any]] | dict[str, Any] | None = None, **kwargs)