Skip to main content

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. Usually openzwave/.
  • <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 example node/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:

  1. openzwave/1/node/2/statistics
  2. openzwave/1/node/2

We will process the messages in the reverse order:

  1. openzwave/1/node/2
  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

  • Install all requirements:

    pip install -r requirements_dev.txt
    
  • We use black to format the code:

    black ./
    
  • Use tox to run tests and linting:

    tox
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-openzwave-mqtt-1.3.2.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

python_openzwave_mqtt-1.3.2-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file python-openzwave-mqtt-1.3.2.tar.gz.

File metadata

  • Download URL: python-openzwave-mqtt-1.3.2.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for python-openzwave-mqtt-1.3.2.tar.gz
Algorithm Hash digest
SHA256 218013c61c7963d1ebccee68ad65af6ccec06c99cbfa65baf4116c5a1d3e68f6
MD5 4a0b8878de0dac2fabeff8d4b663bc4f
BLAKE2b-256 800c61bb0391ce48ad4554569c95ab9c5a2d233a40ba5d0d1be86f8b5bb74da2

See more details on using hashes here.

File details

Details for the file python_openzwave_mqtt-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: python_openzwave_mqtt-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for python_openzwave_mqtt-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0bd6fdb0ff79b3d2edf3833716f76a95f611af6fa68330dfe64b7b253ed20d6d
MD5 c7e01321b55ee33714de1e93e9b635b6
BLAKE2b-256 25202db236342c16d288ccc191cc5b9ecb17009657d968213c3019fbf8369e6a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page