Common parts for a task scheduler.

class mauzr.platform.scheduler.Scheduler

Bases: object

Schedules tasks that are executed by a single runner.

static idle(delay)

Wait the specified delay.

Raises:NotImplementedError – If not overwritten.

Called when a task was called to late.

Parameters:task (mauzr.platform.scheduler.Task) – A task that was executed with a delay.

Called when a task was enabled.

class mauzr.platform.scheduler.Task(scheduler, target, after, single)

Bases: object

Represents a single or recurring task that can be executed.

Note that the task has to be enabled before it can run.

  • scheduler (mauzr.platform.scheduler.Scheduler) – The scheduler to provide information to.
  • target (function) – Function to execute
  • after (int) – Time in ms to delay the execution of the target after task has been enabled.
  • single (bool) – If True the task is only executed once. If False the task is executed with the specified delay between executions.

Disable / cancel this task. No effect if already running.

enable(instant=False, after=None)

Enable the task.

  • instant (bool) – If true the first time the task will be executed without delay. Use this for startup.
  • after (int) – New afer value to set.

Self for convenience.

Return type:


Returns:True if the task in enabled.
Return type:bool

Execute the task.

Returns:True if the task if currently pending for execution.
Return type:bool
Returns:Time in milliseconds until the next execution.
Return type:int

Common base for MQTT clients.

class mauzr.platform.mqtt.Manager(core, cfgbase='mqtt', **kwargs)

Bases: object

Connect to an MQTT broker to exchange messages via topics.

  • core (object) – Core instance.
  • cfgbase (str) – Configuration entry for this unit.
  • kwargs (dict) – Keyword arguments that will be merged into the config.


  • hosts - A list of dicts containing host, port, user, password, and path to the CA certificiate.

Subscribe all subscriptions.

Parameters:session_present (bool) – True if the MQTT session is already created.

React to disconnections from the broker.

on_message(topic, payload, retained)

Handle messages received via the mqtt broker.

  • topic (str) – Topic of the message.
  • payload (object) – Payload of the message.
  • retained (bool) – If True this is a retained message.

Exception – Errors of callback.

publish(topic, payload, retain)

Publish a value to a topic.

  • topic (str) – Topic to publish to.
  • payload (object) – Value to publish.
  • retain (bool) – True if value shall be retained by the server.

Return value of underlying client.

Return type:



Exception – If paho fails.

setup_publish(topic, serializer, qos, default=None)

Prepare publishing to a topic.

  • topic (str) – Topic to publish to. May not contain wildcards.
  • serializer (object) – Serializer that converts outgoing values. If None, value is passed unprocessed.
  • qos (int) – QoS level to use.
  • default (object) – Value to publish on new sessions. May be None.

ValueError – If topic is invalid or is already configured in a conflicting manner.

subscribe(topic, callback, serializer, qos)

Subscribe to a topic.

  • topic (str) – Topic to subscribe to. Currently wildcard subcriptions are only supported for whole subdirectories, e.g. a/#, not a/+, a/+/b or a/#/b. If doing so you may not subscribe to a topic in this directory explicitly.
  • callback (function) – Callback to call when a message is received. Is called with topic and the (deserialized) message data as arguments.
  • serializer (object) – Serializer that converts incoming values. If None, value is passed unprocessed.
  • qos (int) – QoS level to request.

ValueError – If topic is invalid or already configured in a conflicting manner.