Module homie_spec

homie-spec is a Python library that handles the v4 Homie Convention.

Expand source code
"homie-spec is a Python library that handles the v4 Homie Convention."

from homie_spec.devices import Device  # noqa
from homie_spec.nodes import Node  # noqa
from homie_spec.properties import Property  # noqa
from homie_spec.messages import Message  # noqa


def broadcast_message(level: str, payload: str, homie_prefix: str = "homie") -> Message:
    """
    Homie defines a broadcast channel, so a controller is able
    to broadcast a message to all Homie devices.

    >>> broadcast_message("coup", "Goverment detected!").attrs
    {'topic': 'homie/$broadcast/coup', 'payload': 'Goverment detected!', 'retained': True, 'qos': 1}
    """
    return Message(level, payload, prefix=f"{homie_prefix}/$broadcast")

Sub-modules

homie_spec.devices

Exposes the Device class and DeviceState

homie_spec.messages

Exposes the Message class, that can be used to create MQTT styled messages.

homie_spec.nodes

Exposes the Node class

homie_spec.properties

Exposes the Property class, Datatype and multiple partial constructors

Functions

def broadcast_message(level: str, payload: str, homie_prefix: str = 'homie') -> Message

Homie defines a broadcast channel, so a controller is able to broadcast a message to all Homie devices.

>>> broadcast_message("coup", "Goverment detected!").attrs
{'topic': 'homie/$broadcast/coup', 'payload': 'Goverment detected!', 'retained': True, 'qos': 1}
Expand source code
def broadcast_message(level: str, payload: str, homie_prefix: str = "homie") -> Message:
    """
    Homie defines a broadcast channel, so a controller is able
    to broadcast a message to all Homie devices.

    >>> broadcast_message("coup", "Goverment detected!").attrs
    {'topic': 'homie/$broadcast/coup', 'payload': 'Goverment detected!', 'retained': True, 'qos': 1}
    """
    return Message(level, payload, prefix=f"{homie_prefix}/$broadcast")