Skip to main content

homie-spec is a Python library that handles the v4 Homie Convention

Project description

homie-spec

PyPI pyversions GitHub license PyPI version shields.io

Maintenance Coverage Build Status

homie-spec is a Python library that models 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

MIT

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

homie-spec-0.5.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

homie_spec-0.5.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file homie-spec-0.5.0.tar.gz.

File metadata

  • Download URL: homie-spec-0.5.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.13.0-1029-azure

File hashes

Hashes for homie-spec-0.5.0.tar.gz
Algorithm Hash digest
SHA256 abe90f3d2f67b91cec87e9db45e0c3d584e89bb22932d82ddc0281051df2fd95
MD5 8e8161bb044b18c9f6a45292e2b1802d
BLAKE2b-256 fe297129d1332ec15214605820028bbf3257150d2155714f3418d6fa9a2d481c

See more details on using hashes here.

File details

Details for the file homie_spec-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: homie_spec-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.13.0-1029-azure

File hashes

Hashes for homie_spec-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 197b40090b474c5a033dafb61763ef4b96ca9f0b78e6743837e3dd270ee25987
MD5 47b68a8a7459524e45cf613fb288c68b
BLAKE2b-256 2b5150c53d8eee9e21d7ee12079028deba830e8c9ac4753cfb9008516635b43c

See more details on using hashes here.

Supported by

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