Skip to main content

Python library to talk to the twist-innovation api

Project description

Twist Innovation API

Overview

This is the Twist Innovation API – a Python library for interacting with Twist Innovation devices via MQTT.

Installation

You can install this package using pip:

pip install twist-innovation-api

Alternatively, if you have cloned the repository, install it locally:

pip install .

Contributing the Project (without installing in pip)

This repo can be tested with the include main.py. With this main.py, you don't need to install the package. If you just want to install and use, go to Usage

Configuration

Before running the project, you need to create a configuration file named config.yaml in the project root directory. This file should contain your MQTT broker details:

mqtt_broker: "your-mqtt-broker.com"
mqtt_user: "your-username"
mqtt_pass: "your-password"
mqtt_port: 1883  # Default MQTT port

Testing

You can test the package using the included main.py file. Ensure you have a valid config.yaml file set up, then run:

python main.py

Building

To build the package, run the following command:

python -m build

Pushing to PyPi

To push the package to PyPi, run the following command:

twine upload dist/*

Usage

Import the package in your Python scripts:

from twist import TwistAPI, TwistModel

# Other includes for this example
import asyncio
from typing import Callable

# Initialize the mqtt broker here and define the functions needed

# Create a callback function
callback_f: Callable[[str, str], None] | None = None

# Callback function when a Mqtt message is received from the broker and forward it to the twist API
def on_message(client, userdata, msg):
    if callback_f is not None:
        callback_f(msg.topic, msg.payload.decode())

# Publish message to the broker
def mqtt_publish(topic, payload):
    pass

# Subscribe to a topic from the broker
def mqtt_subscribe(topic, callback):
    global callback_f
    callback_f = callback

# Callback function when a model received an update
def on_model_update(model: TwistModel):
    model.print_context()

async def main():
    twist_api = TwistAPI(8, on_model_update)
    twist_api.add_mqtt(mqtt_publish, mqtt_subscribe)
    twist_model_list: list[TwistModel] = await twist_api.search_models()

    while True:
        await asyncio.sleep(1)


if __name__ == "__main__":
    asyncio.run(main())

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue.

Contact

For any issues or questions, reach out via the GitHub Issues.

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

twist_innovation_api-0.0.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twist_innovation_api-0.0.1-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file twist_innovation_api-0.0.1.tar.gz.

File metadata

  • Download URL: twist_innovation_api-0.0.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for twist_innovation_api-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0b77d712d425ea7fa046cd49ae5abff746ae16a4619314658b80c836bbb8dafe
MD5 8d086ebd7fd75bb3d2ba98eb3882cb33
BLAKE2b-256 93da9a20bb400e7f4d55b768fe1e589ae7e940717cd84de3fc725a731bc332f3

See more details on using hashes here.

File details

Details for the file twist_innovation_api-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for twist_innovation_api-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4089a26c3edbcac4e3a0e887d182b92fe6cc9c028cb6426d32f174e42fb0fe90
MD5 5fd24fad42be8881bab1976d3c2d98a8
BLAKE2b-256 6c222ee8e10b796af121a3b9299e8601d8497d44c5b19cc1e70c7b701f3d0b62

See more details on using hashes here.

Supported by

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