Tools to create a Domoticz plugin for local-tuya devices.
Project description
local-tuya-domoticz-tools
Tools to create a Domoticz plugin for local-tuya devices.
💡 The Domoticz version should be
2022.1or higher.
Creating the plugin
To create a plugin, you will need to create 2 things.
Plugin metadata
This is the XML header that is used to populate the plugin creation page in Domoticz.
You can create it using local_tuya_domoticz_tools.PluginMetadata.
Starting the device.
To start the plugin, you need to create the device and register the units.
Check local_tuya_domoticz_tools.plugin.plugin.OnStart for the function signature.
Units should be created using manager.register(...).
For a switch unit, it would look like:
from typing import Dict
from local_tuya import DeviceConfig, ProtocolConfig
from local_tuya_domoticz_tools import UnitManager, switch_unit
from my_device import SwitchState, SwitchDevice
def on_start(
protocol_config: ProtocolConfig,
_: Dict[str, str],
manager: UnitManager[SwitchState],
) -> SwitchDevice:
device = SwitchDevice(config=DeviceConfig(protocol=protocol_config))
manager.register(
switch_unit(
id_=1,
name="power",
image=9,
command_func=device.switch,
),
lambda s: s.power,
)
return device
Units
Units represent a Domoticz device and is associated to a Domoticz hardware.
Manager
The role of the manager is to
- create/remove units:
registermethod - dispatch the commands from units:
on_commandmethod - update units state:
updatemethod
Unit types
- switch
- selector switch
- temperature (accepts values preprocessor)
- set point
For common units parameters, see the base.
Installing the plugin
You should provide a script that will be used to install the plugin. It would look like:
from local_tuya_domoticz_tools import install_plugin, PluginMetadata
def on_start(...):
...
if __name__ == "__main__":
install_plugin(
metadata=PluginMetadata(...),
on_start=on_start,
import_path="my_device.domoticz",
)
💡 Domoticz path defaults to
~/domoticza-poption can be passed to change that.
Filtering units
You can automatically add an option to the plugin to filter created units.
To enable it, you need to implement local_tuya_domoticz_tools.UnitId and add all unit IDs, then simply pass it to the install function. UnitManager.register will handle device deletion.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file local_tuya_domoticz_tools-1.2.0.tar.gz.
File metadata
- Download URL: local_tuya_domoticz_tools-1.2.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
519f0dc53ec436ecde9edfb43760ffd3f29f996655b45bff074ef10696e37682
|
|
| MD5 |
227722cc563956d0d502384526bf56ba
|
|
| BLAKE2b-256 |
a5c6c1294a3ef2ee1c33a244144a63dc77257c996e0686a45d0ba72aa24aa2c7
|
File details
Details for the file local_tuya_domoticz_tools-1.2.0-py3-none-any.whl.
File metadata
- Download URL: local_tuya_domoticz_tools-1.2.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
428c5fd899636db1fd5fa00a9e4d5d98f123f3f25cb09dc1da35b986e1297f1a
|
|
| MD5 |
4f5adca2ef8d145c3a1c7014ce3d7f75
|
|
| BLAKE2b-256 |
4f0c3ec0c8971e924d7c5e43f2a1ba8c2715eb120f8b0b770aa33a37b4cc2886
|