Homie Device¶
- class circuitpython_homie.HomieDevice(client: MQTT, name: str, device_id: str)[source]¶
A class to represent an instantiated Homie device.
- Parameters:¶
- client: MQTT¶
An instance of an MQTT client object that the device will use to communicate with a MQTT broker.
- name: str¶
The device’s human friendly name.
- device_id: str¶
A unique identifying string for the device. This should adhere to the Homie ID specifications. Meaning only lowercase letters (a-z) or numbers or hyphens (
-
) are allowed. This ID is prohibited from starting with a$
and cannot begin or end with a-
, thus these characters are stripped from the given input.
-
base_topic =
'homie'
¶ The base topic used for all
HomieDevice
instances (class attribute).
- begin(**mqtt_settings)[source]¶
Register this Homie device with the MQTT broker.
- client¶
The MQTT client object.
- enable_broadcast¶
A flag to control interaction with Homie’s
broadcast
topic.
- extensions¶
The supported Homie extensions (not implemented by this library).
-
implementation =
'CircuitPython on Linux'
¶ The
implementation
attribute used for allHomieDevice
instances (class attribute). The platform specified by default is taken fromsysname
.
- name¶
The device’s
name
attribute.
-
set_property(prop: HomieProperty, value, multi_node: bool =
False
)[source]¶ Change a specified property’s value and publish it to the MQTT broker.
- Parameters:¶
- prop: HomieProperty¶
the instance object representing the device node’s property.
- value¶
The new value for the property. The data type passed here will depend on the type of
HomieProperty
(specified by theprop
parameter) for which it is being applied.See also
The Recipes have derivatives of the
HomieProperty
class with validators implemented accordingly.- multi_node: bool =
False
¶ Set this to
True
if the property is associated with multiple devicenodes
. By default, only the first node found in association is updated on the MQTT broker.
- Throws:¶
If the property is not associated with one of the device’s
nodes
, then aValueError
exception is raised.
- set_state(state: str)[source]¶
Set the device’s
state
attribute on the MQTT broker.- Parameters:¶
- Throws:¶
If the specified
state
value is not a member ofDEVICE_STATES
, then aValueError
exception is raised.