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, inputs, handler, default, out_topic, serializer, qos)

Aggregates multiple topics to a single one.

Parameters:
  • core (object) – Core instance.
  • 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.
  • 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.
  • out_topic (str) – Output topic.
  • serializer (object) – Output serializer.
  • qos (int) – QoS for input and output.

Required core units:

  • mqtt
mauzr.data.convert(core, mapper, retain, default, in_topic, out_topic, deserializer, serializer, qos)

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.
  • in_topic (str) – Topic of the input.
  • out_topic (str) – Topic of the output.
  • deserializer (object) – Deserializer for the input.
  • serializer (object) – Serializer for the output.
  • qos (int) – QoS for input and output.

Required core units:

  • mqtt
mauzr.data.delay(core, condition, amount, payload, retain, in_topic, out_topic, deserializer, serializer, qos)

Allows to send a 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.
  • in_topic (str) – Input topic.
  • out_topic (str) – Output topic.
  • deserializer (object) – Deserializer for the input.
  • serializer (object) – Output serializer.
  • qos (int) – QoS for input and output.

Required core units:

  • mqtt
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/reqeust/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.merge(core, in_topics, out_topic, deserializer, serializer, default, qos)

Merge multiple topics into one.

Parameters:
  • core (object) – Core instance.
  • in_topics (tuple) – List of input topics.
  • out_topic (str) – Output topic
  • deserializer (object) – Deserializer for the inputs.
  • serializer (object) – Serializer for the output.
  • qos (int) – QoS for input and output.
  • default (object) – Default input value.
Raises:

ValueError – If length if in_topics does not match default.

Required core units:

  • mqtt
mauzr.data.split(core, in_topic, out_topics, deserializer, serializer, default, qos)

Split a single topic into multiple.

Parameters:
  • core (object) – Core instance.
  • in_topic (str) – Input topic.
  • out_topics (tuple) – List of output topics.
  • deserializer (object) – Deserializer for the input.
  • serializer (object) – Serializer for the outputs.
  • default (object) – Default output value.
  • qos (int) – QoS for input and output.

Required core units:

  • mqtt