Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

tuya-device-handlers

Latest version: v2026.12.2

Overview

Last scanned
27 Nov 2026
Published
27 Nov 2026
PyPI package Publisher: epenet, martinhjelmare
26 Stars
94 Forks
6 Versions
17.3K Downloads
Python Repo language

Scan summary

tuya-device-handlers was last scanned on 27 Nov 2026 at version 2026.12.2. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 6 versions; the latest 2 were published within 4 days (24–27 Nov 2026).
  • Findings: No rules fired in version 2026.12.2.
  • Downloads: 17,280 downloads.

Versions

6 versions published
Versions and the rules that fired in each
VersionPublishedStatus
2026.12.2 LATEST 27 Nov 2026 No rules fired
2026.12.1 24 Nov 2026 No rules fired
2026.12.0 17 Nov 2026 No rules fired
0.0.34 4 Nov 2026 Not shown
0.0.33 30 Oct 2026 Not shown

No rules fired in 2026.12.2

Findings

Findings for v2026.12.2. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 2026.12.2; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

Tuya quirks library

PyPI Python Version License

Tests Open in Dev Containers

pre-commit ruff

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.

If function, status_range and status are all empty, the cloud told Home Assistant nothing about the device and it gets no entities. See Finding the datapoints to get them from the device's thing model instead.

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/.

New to this and not a programmer? For a fully worked, copy-paste walkthrough of one of the most common fixes — a device sending ENUM values (e.g. extra mode presets) that Home Assistant rejects as Found invalid ENUM value ... — see Recipe: add missing ENUM values. It covers writing the quirk, testing it live, and opening a PR end to end.

Entities missing — all of them, or just some? A quirk can only rewrite a device's datapoints; turning them into entities is Home Assistant's job, and it can only do that for a category and a DPCode it knows. If a datapoint is absent from the diagnostics, a quirk can add it; if it's present but never becomes an entity, the fix belongs in core. See Recipe: missing entities.

Cover position backwards? A closed blind shows as open, or the open button closes it. See Recipe: inverted covers.

3. Test it inside Home Assistant
  1. 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.

  2. Watch the logs — you should see the warning Loaded custom quirks. Please contribute them to https://github.com/home-assistant-libs/tuya-device-handlers. If the import fails, the traceback is logged. The per-file Loading custom quirk module … lines are only logged with debug logging on for tuya_device_handlers.

  3. Verify the device's entities reflect your changes. Download diagnostics again: quirk shows the quirk file that applied, and function / status_range show the patched maps.

  4. To see reports and commands as they happen, turn on debug logging by calling the logger.set_level action from Developer tools → Actions. (Enable debug logging on the Tuya integration page covers the integration and tuya_sharing, but not this library, so it won't show quirk loading.)

    action: logger.set_level
    data:
      tuya_device_handlers: debug
      tuya_sharing: debug
      homeassistant.components.tuya: debug

    Reload the Tuya integration again, so that the quirk loading is logged too. Then use the device from its app or its buttons, and try each entity from Home Assistant. Useful lines to look for (the device ID is the id field in your diagnostics):

    Log line Meaning
    Loading custom quirk module … Your quirk file was imported (an import error is logged here).
    mq _on_device_report unknown dpId: … A report arrived for a dpid with no mapping: see Finding the datapoints.
    mq _on_device_report after strategy convert code=…,value=… A report arrived and your quirk mapped its dpid to a code.
    Received update for device <id> … {'<code>': <value>} Home Assistant applied the report to the device.
    Sending commands for device <id>: [{'code': …, 'value': …}] Home Assistant sent a command.
    response before decrypt ret = {'code': '2008', … 'success': False} The Tuya cloud rejected that command: a quirk can't fix that, see Commands rejected by the cloud.

    Set the log levels back afterwards (warning, or whatever your configuration.yaml sets), or restart Home Assistant.

Contributing your quirk

Once your quirk works, please open a pull request so other Home Assistant users benefit.

  1. Fork and clone this repository, then run uv sync.

  2. Move your quirk file from <config>/tuya_quirks/ to src/tuya_device_handlers/devices/<category>/. The filename should match <category>_<product_id_lowercased>.py.

  3. Add a device fixture JSON at tests/fixtures/devices/<category>_<product_id>.json. Build it from your Home Assistant diagnostics download: keep only the contents of the top-level data property (the captured device payload), then remove its id, terminal_id, and home_assistant keys. Name the file from the payload's own category and product_id fields. For example:

    python3 -c "
    import json
    d = json.load(open('diagnostics.json'))['data']
    for k in ('id', 'terminal_id', 'home_assistant'):
        d.pop(k, None)
    name = f\"tests/fixtures/devices/{d['category']}_{d['product_id']}.json\"
    with open(name, 'w') as f:
        json.dump(d, f, indent=2, ensure_ascii=False)
        f.write('\n')
    print(name)
    "
  4. Add a test under tests/devices/<category>/ covering the patched behaviour.

  5. Run the test suite locally:

    uv run pytest --cov tuya_device_handlers tests
  6. 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.

Device quirks are not written on request: if your device needs one, write it yourself following Writing a quirk, then contribute it. Issues and pull requests without activity are marked as stale and then closed automatically; comment to keep them open.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases tuya-device-handlers

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Vulnerability Insights

Compromised Claude Code extensions (versions 2.1.312 & 2.1.313) in Cursor try to install a backdoor

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Frame 2085668439 (1)
Group 1261154229