Converts MQTT messages from qt-openzwave into Python objects and events
Project description
python-openzwave-mqtt
Python library for the OpenZWave MQTT implementation.
Consumes MQTT output from https://github.com/OpenZWave/qt-openzwave
For Home Assistant integration, see the custom component homeassistant-zwave_mqtt.
Install
- Python 3.7+ is required. We support the two latest Python 3 versions released at any one time.
pip install python-openzwave-mqtt
Structure
Each object maps to one or two parts in the topic. A topic can contain the following parts:
<Prefix>
: the prefix of each topic. This is ignored in the processing. Usuallyopenzwave/
.<CollectionType>/<CollectionID>
: The collection type and the ID of the item in the collection. Example:value/3
<CollectionID>
: Some objects will have a direct collection that is not typed in the topic. Example is the OZW instance in<Prefix>/1
<ObjectType>
: If there is only a single instance of a type under a parent. For examplenode/2/statistics
.
Example
A message is sent to topic openzwave/1/node/2/statistics
. This maps to:
Type | ID |
---|---|
Prefix | - |
OZWInstance |
1 |
OZWNode |
2 |
OZWNodeStatistics |
- |
Message ordering
We work with signals to signal listeners when things change. However, when we connect to MQTT we will receive a lot of retained messages at once. To prevent signals being sent out of order, we will hold all messages for children until the parent has received its information.
This has been disabled for OZWManager
and OZWInstance
.
If we receive messages on the following topics:
openzwave/1/node/2/statistics
openzwave/1/node/2
We will process the messages in the reverse order:
openzwave/1/node/2
openzwave/1/node/2/statistics
Modelling Rules
This library should not aim to do fancy things. We should, as much as possible, represent the data from MQTT as-is. We don't want to change names besides making them Pythonic (CamelCase -> snake_case).
Automatic added helpers
Models will have automatic helpers added based on their child models. For example, the Node
model has the following child collections:
def create_collections(self):
"""Create collections that Node supports."""
return {
# A collection of children
"instance": ItemCollection(OZWNodeInstance),
# A single child
"statistics": OZWNodeStatistics,
}
This means that Node
has the following automatic functions created:
get_instance(item_id)
to get an instance by ID.instances()
to get an iterator over all available instances.get_statistics()
get the direct child.
Gathering Data
This library is instantiated using messages received from MQTT. To make development easier, we have created two helper scripts. One that will dump all MQTT messages and one that will read messages from a text file and instantiate an OZWManager
with all the data. This can be used to develop, test or reproduce bugs.
python3 -m script.dump_mqtt > dump.csv
python3 -m script.instance_from_file dump.csv
Development
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 python-openzwave-mqtt-1.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f47abc26b1bdfc02f5130144c30d155942193b8bbec95434afd9307451b0cae6 |
|
MD5 | 17b9a5b839cb1696d3579ab239757e87 |
|
BLAKE2b-256 | 17e2c82126a4bb81e181c20cb68630fa3631315e1a6e18f1dae4602be401e446 |
Hashes for python_openzwave_mqtt-1.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fb2483287b91935f1d9839dd0bc33b10076d66671021c3444a8081077f6955e |
|
MD5 | 023cb21118fdb7cb875c25b42c33e3b5 |
|
BLAKE2b-256 | e450be0f850e3bf0520c1a54fe30dc4efd99c497aaed04ab13a81f340e80446d |