Tuya quirks library
Project description
Tuya quirks library
What is this?
tuya-device-handlers is a "quirks" library used by Home Assistant's Tuya integration to fix or normalise misbehaving Tuya devices. A quirk is matched against a device's product_id and patches its datapoints (function/status_range/local_strategy) before Home Assistant builds entities from them.
The library is shipped to end users via Home Assistant — you do not install it directly.
Writing a quirk
1. Find your device's product_id and datapoints
In Home Assistant: Settings → Devices & services → Tuya → your device → Download diagnostics. The JSON contains the product_id, the cloud-reported function / status_range maps, and the current status values. Use these to decide what needs patching.
2. Create a quirk file
Drop a Python file into your Home Assistant config folder at <config>/tuya_quirks/<category>_<product_id_lowercased>.py. The <category> prefix follows Tuya's official category codes (e.g. cz for plug/socket, wk for thermostat, cl for curtain).
Quirks are built using a fluent DeviceQuirk builder. Minimal example — redefine one datapoint and remove another:
from tuya_device_handlers import TUYA_QUIRKS_REGISTRY
from tuya_device_handlers.builder import DeviceQuirk
from tuya_device_handlers.const import DPMode
(
DeviceQuirk()
.applies_to(product_id="abcdEFGHijkl1234")
.add_dpid_integer(
dpid=18,
dpcode="cur_current",
dpmode=DPMode.READ,
unit="mA", min=0, max=30000, scale=0, step=1,
)
.remove_dpid(dpid=22, dpcode="phantom_dp")
.register(TUYA_QUIRKS_REGISTRY)
)
Each quirk file should contain exactly one DeviceQuirk()...register(...) chain at module top level — the file path is captured for reload tracking. Available builder methods include add_dpid_boolean, add_dpid_bitmap, add_dpid_enum, add_dpid_integer, and remove_dpid. For more complex needs (custom value scaling, platform-specific definitions), see the in-tree examples under src/tuya_device_handlers/devices/.
3. Test it inside Home Assistant
- Restart the Tuya integration (Settings → Devices & services → Tuya → ⋮ → Reload). Quirks under
<config>/tuya_quirks/are reloaded each time, so you don't need to restart Home Assistant itself. - Watch the logs — you should see
Loading custom quirk module …followed byLoaded custom quirks. Please contribute them to https://github.com/home-assistant-libs/tuya-device-handlers. If the import fails, the traceback is logged. - Verify the device's entities reflect your changes (download diagnostics again to confirm the patched function/status_range maps).
Contributing your quirk
Once your quirk works, please open a pull request so other Home Assistant users benefit.
-
Fork and clone this repository, then run
poetry install. -
Move your quirk file from
<config>/tuya_quirks/tosrc/tuya_device_handlers/devices/<category>/. The filename should match<category>_<product_id_lowercased>.py. -
Add a device fixture JSON at
tests/fixtures/devices/<category>_<product_id>.json. The easiest source is thefunction/status_range/statusblocks from your Home Assistant diagnostics download. -
Add a test under
tests/devices/<category>/covering the patched behaviour. -
Run the test suite locally:
poetry run pytest --cov tuya_device_handlers tests -
Open a pull request.
For broader contributor guidelines (issue reporting, dev setup, pre-commit hooks), see the Contributor Guide.
License
Distributed under the terms of the MIT license, Tuya quirks library is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
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
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 tuya_device_handlers-0.0.21.tar.gz.
File metadata
- Download URL: tuya_device_handlers-0.0.21.tar.gz
- Upload date:
- Size: 39.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e442edd9b1449f4442e17434e484f15858d61f089f8012258894a4486bbbe4d9
|
|
| MD5 |
b0b4652394b25f949f7f6651546bb485
|
|
| BLAKE2b-256 |
0e0c34d423c0f326e7f6417d292d4450175cc3ef566378568f88753ae2a75e4f
|
Provenance
The following attestation bundles were made for tuya_device_handlers-0.0.21.tar.gz:
Publisher:
release.yaml on home-assistant-libs/tuya-device-handlers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tuya_device_handlers-0.0.21.tar.gz -
Subject digest:
e442edd9b1449f4442e17434e484f15858d61f089f8012258894a4486bbbe4d9 - Sigstore transparency entry: 1640074150
- Sigstore integration time:
-
Permalink:
home-assistant-libs/tuya-device-handlers@6796ab9337cd43bda6a6e42418774d3840740585 -
Branch / Tag:
refs/tags/v0.0.21 - Owner: https://github.com/home-assistant-libs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@6796ab9337cd43bda6a6e42418774d3840740585 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tuya_device_handlers-0.0.21-py3-none-any.whl.
File metadata
- Download URL: tuya_device_handlers-0.0.21-py3-none-any.whl
- Upload date:
- Size: 62.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06f0281ffae540937754d802727a1495cd9e8f90710c1b932a930db9cf5ea588
|
|
| MD5 |
623a0d2125f1a336438fd426830a2556
|
|
| BLAKE2b-256 |
c0f4d7dd7f5811809d5dee691ea92228b6f44e95a4421a400eb77b362a154b36
|
Provenance
The following attestation bundles were made for tuya_device_handlers-0.0.21-py3-none-any.whl:
Publisher:
release.yaml on home-assistant-libs/tuya-device-handlers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tuya_device_handlers-0.0.21-py3-none-any.whl -
Subject digest:
06f0281ffae540937754d802727a1495cd9e8f90710c1b932a930db9cf5ea588 - Sigstore transparency entry: 1640074304
- Sigstore integration time:
-
Permalink:
home-assistant-libs/tuya-device-handlers@6796ab9337cd43bda6a6e42418774d3840740585 -
Branch / Tag:
refs/tags/v0.0.21 - Owner: https://github.com/home-assistant-libs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@6796ab9337cd43bda6a6e42418774d3840740585 -
Trigger Event:
release
-
Statement type: