Data

Data conversion helpers.

mauzr.data.BC

alias of BoolCondition

class mauzr.data.BoolCondition

Bases: enum.Enum

Condition for boolean channels.

FORCE_OFF = 0
FORCE_ON = 1
FREE = 2
mauzr.data.aggregate(core, handler, default, inputs, output)

Aggregates multiple topics to a single one.

Parameters:
  • core (object) – Core instance.
  • handler (callable) – Callable used for aggregation. Receives a dict of topic states, the current topic and the current value as arguments and is expected to return the new output value or None.
  • default (object) – Initial values to publish. May be None.
  • inputs (tuple) – A list of tuples describing each input by listing topic and serializer. When a message arrives for these topics, it is added to the value list and passed to the hander callable.
  • output (tuple) – Topic, serializer and QoS of input.

Required core units:

  • mqtt
mauzr.data.convert(core, mapper, retain, default, input, output)

Convert the messages of one topic into messages in some other.

Parameters:
  • core (object) – Core instance.
  • mapper (object) – If input has this value, the payload will be published.
  • retain (bool) – If True the retain flag is set.
  • default (object) – Initial values to publish. May be None.
  • input (tuple) – Topic, deserializer and QoS of input.
  • output (tuple) – Topic, serializer and QoS of input.

Required core units:

  • mqtt
mauzr.data.delay(core, condition, amount, payload, retain, input, output)

Allows to send payload when a condition is met after a defined delay.

Parameters:
  • core (object) – Core instance.
  • condition (callable) – If this callable returns True when called with an incoming message as argument, the timer ist started.
  • amount (int) – Delay after which to trigger the message sending.
  • payload (object) – Message to send when timer expires.
  • retain (bool) – If True the retain flag is set.
  • input (tuple) – Topic, deserializer and QoS of input.
  • output (tuple) – Topic, serializer and QoS of input.

Required core units:

  • mqtt
mauzr.data.from_string(core, topic, retain, ser, converter)

Convert string messages from a topic into another topic and type.

Parameters:
  • core (object) – Core instance.
  • topic (str) – Message will be read from topic + “/str” and published to topic.
  • retain (Bool) – If the published message shall be retained.
  • ser (object) – Serializer to use for serialization
  • converter (callable) – Callable to convert deserialized string value to something interpretable by the serializer.
mauzr.data.gate_bool(core, topic)

Control a bool topic by applying a condition for it

Parameters:
  • core (object) – Core instance.
  • topic (str) – Output topic to manage.

Required core units:

  • mqtt

Input Topics:

  • topic/condition (!H) - BoolCondition describing what the output may do.
  • topic/request (?) - Bool requesting the output to be enabled or disabled.
  • topic/request/toggle (?) - Request the output to be toggled.

Output Topics:

  • topic (?) - Bool describing if the output in enabled.
  • topic/on_allowed (`?) - Bool describing if output may be
    requested to be enabled.
  • topic/off_allowed (?) - Bool describing if output may be
    requested to be disabled.
mauzr.data.to_string(core, topic, ser, converter=<class 'str'>)

Convert messages from a topic into another topic as string.

Parameters:
  • core (object) – Core instance.
  • topic (str) – Message will be read from topic and published to topic + “/str”.
  • ser (object) – Serializer to use for deserialization
  • converter (callable) – Callable to convert deserialized value to string.