Recipes¶
The circuitpython_homie.recipes module holds any suggested recipes for easily
implementing common node properties.
Important
Callback methods are not templated for these properties. Users are advised to
write their own callback methods and set them to the desired property’s
callback attribute.
Colors¶
-
class circuitpython_homie.recipes.PropertyRGB(name: str, property_id: str =
None, **extra_attributes)[source]¶ A property that can be used to represent node’s color in RGB format.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:settableattribute is set toTrue(can be overridden with a keyword argument)init_valueis set to black"0,0,0"(can be overridden with a keyword argument)datatypeattribute is set to"color"(shall not be overridden)formatattribute is set to"rgb"(shall not be overridden)
-
class circuitpython_homie.recipes.PropertyHSV(name: str, property_id: str =
None, **extra_attributes)[source]¶ A property that can be used to represent node’s color in HSV format.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:init_valueis set to black"0,0,0"(can be overridden with a keyword argument)datatypeattribute is set to"color"(shall not be overridden)formatattribute is set to"hsv"(shall not be overridden)
Boolean¶
-
class circuitpython_homie.recipes.PropertyBool(name: str, property_id: str =
None, init_value=False, **extra_attributes)[source]¶ Bases:
HomiePropertyA property to represent boolean data.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:datatypeattribute is set to"boolean"(shall not be overridden)init_valueis set toFalse(can be overridden with a keyword argument)
Numbers¶
-
class circuitpython_homie.recipes.PropertyPercent(name: str, datatype: str =
'float', property_id: str =None, init_value=0, **extra_attributes)[source]¶ A property that represents a percentage.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:unitattribute is set to"%"(shall not be overridden)datatypeattribute is constrained to"integer"or its default"float"values (can be overridden with a keyword argument)formatattribute is set to"0:100", which describes an inclusive range from 0 to 100, but it is not have to be this range (can be overridden with a keyword argument)init_valuedefaults to0because percentage type payloads cannot be empty rings (can be overridden with a keyword argument)
-
class circuitpython_homie.recipes.PropertyInt(name: str, property_id: str =
None, init_value=0, **extra_attributes)[source]¶ A property to represent an integer.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:datatypeattribute is set to"integer"(shall not be overridden)init_valueis set to0(can be overridden with a keyword argument)formatattribute can optionally be used to define the constraining range. By default, theformatattribute is unspecified (can be overridden with a keyword argument).
-
class circuitpython_homie.recipes.PropertyFloat(name: str, property_id: str =
None, init_value=0.0, **extra_attributes)[source]¶ A property to represent an float.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:datatypeattribute is set to"float"(shall not be overridden)init_valueis set to0.0(can be overridden with a keyword argument)formatattribute can optionally be used to define the constraining range. By default, theformatattribute is unspecified (can be overridden with a keyword argument).
Time¶
-
class circuitpython_homie.recipes.PropertyDateTime(name: str, property_id: str =
None, init_value='2000-01-01T00:00:00', **extra_attributes)[source]¶ Bases:
HomiePropertyA property that represents a data and time in ISO 8601 format.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:datatypeattribute is set to"datetime"(shall not be overridden)init_valueis set to"2000-01-01T00:00:00"(can be overridden with a keyword argument)
Hint
Validation of the payload format can be done using the
datetimelibrary or theadafruit_datetimelibrary.- static convert(value: struct_time) str[source]¶
Takes a
struct_timeobject and returns astrin compliance with ISO 8601 standards.- Parameters¶
- value: struct_time¶
The
named tupleto translate.
- Returns¶
A ISO 8601 compliant formatted string in the form
YYYY-MM-DDTHH:MM:SS.
-
class circuitpython_homie.recipes.PropertyDuration(name: str, property_id: str =
None, init_value='PT0S', **extra_attributes)[source]¶ Bases:
HomiePropertyA property that represents a duration of time in ISO 8601 Duration format.
The parameters here follow the
HomiePropertyconstructor signature, but with a few exceptions:datatypeattribute is set to"duration"(shall not be overridden)init_valueis set to"PT0S"(can be overridden with a keyword argument)
Hint
Validation of the payload format can be done using the
datetimelibrary or theadafruit_datetimelibrary.- static convert(value: int | float) str[source]¶
Takes a a number of seconds and returns a
strin compliance with ISO 8601 Duration standards.Note
For minimality, this function will only convert a number of seconds into units of hours, minutes, and seconds.
- Parameters¶
- Returns¶
A ISO 8601 Duration compliant formatted string in the form
PTnHnMnS.Only units with a non-zero value are represented. For instance, a value of
59will return"PT59S"(representing 59 seconds), and a value of3609will return"PT1H9S"(representing 1 hour and 9 seconds).
Helpers¶
These module attributes help validation of certain values.
- circuitpython_homie.validate_id(_id: str) str[source]¶
Conform and validate a given ID to Homie specifications.
- Parameters¶
- Throws¶
If the given ID contains anything other than lowercase letters (a-z), numbers (0-9), or hyphens (
-), then this function will raise aValueErrorexception.- Returns¶
A valid ID from the value passed to the
_idparameter.
-
circuitpython_homie.DEVICE_STATES =
['init', 'ready', 'disconnected', 'sleeping', 'alert', 'lost']¶ A list of valid device states according to the Homie specification’s Life Cycle.