Homie Property¶
-
class circuitpython_homie.HomieProperty(name: str, datatype: str =
'string', property_id: str =None, init_value='', **extra_attributes)[source]¶ A class to represent a single property of a Homie device’s node.
- Parameters¶
- name: str¶
The human friendly name of the node.
- datatype: str =
'string'¶ The node’s
datatype. Valid data types are defined inPAYLOAD_TYPES. Default is"string".- property_id: str =
None¶ A unique identifying
strto use in the generated MQTT topic. If this parameter is not specified, then thenameparameter will be used (providing it conforms to Homie specifications - seevalidate_id()).- init_value=
''¶ The property’s initial value.
- Throws¶
A
ValueErrorcan indicate if the specifieddatatypeorproperty_idis invalid. The exception’s message will indicate which value.
Warning
All attributes for this class should be considered read-only after calling
HomieDevice.begin(). This is because the attributes published to the MQTT broker are not dynamically updated without callingHomieDevice.begin()after changing the attributes’ value.- property callback¶
This attribute shall hold a pointer to a callback function that is called when the property’s value changes via broker subscription.
Conventionally, this will require echoing the data back to the broker as confirmation.
See also
Use
HomieDevice.set_property()to echo back a confirmation to the MQTT broker.prop1 = HomieProperty("signage", settable=True) def new_signage(client: MQTT, topic, :str, message: str): # let `my_device` be the instantiated HomieDevice object my_device.set_property(prop1, message) # confirm with broker # Optionally do something with the new value print("received:", prop1.value) prop1.callback = new_signage
- datatype¶
The property’s
datatypeattribute.
- is_retained() bool[source]¶
By default, all properties are published as retained topics. This can be controlled by declaring a
retainedboolattribute.>>> prop1 = HomieProperty("demo-1") >>> prop1.is_retained() True >>> prop2 = HomieProperty("demo-2", retained=False) >>> prop2.is_retained() False
- is_settable() bool[source]¶
Can this property be manipulated from the broker? This is controlled by the declaring a
settableboolattribute. By default, all properties are not settable.>>> prop1 = HomieProperty("demo-1") >>> prop1.is_settable() False >>> prop2 = HomieProperty("demo-2", settable=True) >>> prop2.is_settable() True
- name¶
The property’s human friendly
nameattribute
- property_id¶
The property’s ID as used in the generated MQTT topic.
- property value¶
The current value of the property.
Read Only
This function will not update the value on the MQTT broker. Instead use
HomieDevice.set_property()to do that.