homie-spec is a Python library that handles the v4 Homie Convention
Project description
homie-spec
homie-spec is a Python library that handles the v4 Homie Convention.
This package has no dependencies other than Python >=3.6. Since it doesn't implement MQTT this also means it's fairly useless on it's own, as it has no ability to interact with any MQTT broker on it's own.
The goal of this package is to provide a data-driven library to easily create devices
, nodes
and properties
. These can also be published to be used by anyone.
Another package (WIP), will bridge the MQTT protocol and homie-spec
.
Relevant external links:
Installation
Use the package manager pip to install homie-spec
.
pip install homie-spec
Usage
from homie_spec import Device, Node, Property
from homie_spec.properties import Datatype
localtime = Node(
name="Local time",
typeOf="clock",
properties={
"color-repr": Property(
name="Color representation", datatype=Datatype.COLOR, get=lambda: "233,102,23"
),
"time": Property(
name="HH:MM representation", datatype=Datatype.STRING, get=lambda: "20:20"
),
},
)
desktop = Device(id="desktop", name="Desktop Computer", nodes={"local-time": localtime})
for msg in desktop.messages():
print(msg.attrs)
print(desktop.getter_message('local-time/time').attrs)
print(desktop.getter_message('local-time/color-repr').attrs)
"""
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/$state', 'payload': 'init'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/$name', 'payload': 'Desktop Computer'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/$homie', 'payload': '4.0.0'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/$implementation', 'payload': 'homie-spec'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/$nodes', 'payload': 'local-time'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/$name', 'payload': 'Local time'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/$type', 'payload': 'clock'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/$properties', 'payload': 'color-repr,time'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/color-repr/$name', 'payload': 'Color representation'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/color-repr/$datatype', 'payload': 'color'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/time/$name', 'payload': 'HH:MM representation'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/time/$datatype', 'payload': 'string'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/$state', 'payload': 'ready'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/time', 'payload': '20:20'}
{'retained': True, 'qos': 1, 'topic': 'homie/desktop/local-time/color-repr', 'payload': '233,102,23'}
"""
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for homie_spec-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad708b6eb44a7e677cc476694f04bee36369a1e14dcc1f8b04e3dc73b4b4d83b |
|
MD5 | 7992c090502ea76af8c8b01ef67a0786 |
|
BLAKE2b-256 | b3b36d0a5fb39c87f060aeee82fe56098711819c8501d2c8217b209c0e10f645 |