Repository: zigpy/zha-device-handlers

Issue:
[Device Support Request] _TZ3210_e5t9bfdv TS0501B
This is a single channel LED controller that erroneously reports color support. I think it would need the same fix as _TZ3000_4whigl8i TS0501B. 

<details>
<summary>Device signature - this can be acquired by clicking on the "Zigbee Device Signature" button in the device settings</summary>

```
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": 260,
      "device_type": "0x0101",
      "in_clusters": [
        "0x0000",
        "0x0003",
        "0x0004",
        "0x0005",
        "0x0006",
        "0x0008",
        "0x0300",
        "0x1000",
        "0xef00"
      ],
      "out_clusters": [
        "0x000a",
        "0x0019"
      ]
    },
    "242": {
      "profile_id": 41440,
      "device_type": "0x0061",
      "in_clusters": [],
      "out_clusters": [
        "0x0021"
      ]
    }
  },
  "manufacturer": "_TZ3210_e5t9bfdv",
  "model": "TS0501B",
  "class": "zigpy.device.Device"
}
```

</details>

<details>
<summary>Diagnostic information - this can be acquired by clicking on the "Download Diagnostics" button in the device settings</summary>

```
{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.5.5",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.9",
    "docker": true,
    "arch": "x86_64",
    "timezone": "America/Chicago",
    "os_name": "Linux",
    "os_version": "5.15.41",
    "supervisor": "2022.05.2",
    "host_os": "Home Assistant OS 8.1",
    "docker_version": "20.10.14",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "simpleicons": {
      "version": "0.0.0",
      "requirements": []
    },
    "ble_monitor": {
      "version": "8.4.1",
      "requirements": [
        "pycryptodomex>=3.14.1",
        "janus>=1.0.0",
        "aioblescan>=0.2.12",
        "btsocket>=0.2.0",
        "pyric>=0.1.6.3"
      ]
    },
    "frigate": {
      "version": "2.2.2",
      "requirements": []
    },
    "alexa_media": {
      "version": "3.11.3",
      "requirements": [
        "alexapy==1.25.5",
        "packaging>=20.3",
        "wrapt>=1.12.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "config_flow": true,
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "requirements": [
      "bellows==0.29.0",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.73",
      "zigpy-deconz==0.16.0",
      "zigpy==0.45.1",
      "zigpy-xbee==0.14.0",
      "zigpy-zigate==0.7.4",
      "zigpy-znp==0.7.0"
    ],
    "usb": [
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*2652*",
        "known_devices": [
          "slae.sh cc2652rb stick"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*zigstar*",
        "known_devices": [
          "ZigStar Coordinators"
        ]
      },
      {
        "vid": "1CF1",
        "pid": "0030",
        "description": "*conbee*",
        "known_devices": [
          "Conbee II"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8A2A",
        "description": "*zigbee*",
        "known_devices": [
          "Nortek HUSBZB-1"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8B34",
        "description": "*bv 2010/10*",
        "known_devices": [
          "Bitron Video AV2010/10"
        ]
      }
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga"
    ],
    "zeroconf": [
      {
        "type": "_esphomelib._tcp.local.",
        "name": "tube*"
      }
    ],
    "after_dependencies": [
      "usb",
      "zeroconf"
    ],
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp"
    ],
    "is_built_in": true
  },
  "data": {
    "ieee": "**REDACTED**",
    "nwk": 50444,
    "manufacturer": "_TZ3210_e5t9bfdv",
    "model": "TS0501B",
    "name": "_TZ3210_e5t9bfdv TS0501B",
    "quirk_applied": false,
    "quirk_class": "zigpy.device.Device",
    "manufacturer_code": 4417,
    "power_source": "Mains",
    "lqi": 163,
    "rssi": null,
    "last_seen": "2022-05-23T11:57:10",
    "available": true,
    "device_type": "Router",
    "signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, manufacturer_code=4417, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": 260,
          "device_type": "0x0101",
          "in_clusters": [
            "0x0000",
            "0x0003",
            "0x0004",
            "0x0005",
            "0x0006",
            "0x0008",
            "0x0300",
            "0x1000",
            "0xef00"
          ],
          "out_clusters": [
            "0x000a",
            "0x0019"
          ]
        },
        "242": {
          "profile_id": 41440,
          "device_type": "0x0061",
          "in_clusters": [],
          "out_clusters": [
            "0x0021"
          ]
        }
      }
    },
    "entities": [
      {
        "entity_id": "button.tz3210_e5t9bfdv_ts0501b_28e3062e_identify",
        "name": "_TZ3210_e5t9bfdv TS0501B"
      },
      {
        "entity_id": "light.tz3210_e5t9bfdv_ts0501b_28e3062e_level_light_color_on_off",
        "name": "_TZ3210_e5t9bfdv TS0501B"
      }
    ],
    "neighbors": [
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Parent",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xD5A2",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "139"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x9125",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "148"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x13C3",
        "permit_joining": "Unknown",
        "depth": "2",
        "lqi": "54"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x7A5E",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "100"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xCB57",
        "permit_joining": "Unknown",
        "depth": "2",
        "lqi": "139"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x9BAE",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "106"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xAAC2",
        "permit_joining": "Unknown",
        "depth": "2",
        "lqi": "69"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xE3FD",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "78"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x3CDC",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "106"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x0C41",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "112"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xD722",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "88"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xAB0F",
        "permit_joining": "Unknown",
        "depth": "2",
        "lqi": "163"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xCDED",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "109"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xDECA",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "81"
      },
      {
        "device_type": "Coordinator",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x0000",
        "permit_joining": "Unknown",
        "depth": "0",
        "lqi": "151"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x36A2",
        "permit_joining": "Unknown",
        "depth": "3",
        "lqi": "69"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xE1F6",
        "permit_joining": "Unknown",
        "depth": "2",
        "lqi": "51"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x92CD",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "103"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x66B9",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "0"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0x6445",
        "permit_joining": "Unknown",
        "depth": "1",
        "lqi": "0"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Child",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xB27E",
        "permit_joining": "Unknown",
        "depth": "3",
        "lqi": "78"
      },
      {
        "device_type": "Router",
        "rx_on_when_idle": "On",
        "relationship": "Sibling",
        "extended_pan_id": "**REDACTED**",
        "ieee": "**REDACTED**",
        "nwk": "0xC337",
        "permit_joining": "Unknown",
        "depth": "3",
        "lqi": "39"
      }
    ],
    "endpoint_names": [
      {
        "name": "DIMMABLE_LIGHT"
      },
      {
        "name": "unknown 97 device_type of 0xa1e0 profile id"
      }
    ],
    "user_given_name": null,
    "device_reg_id": "fe54c254e0d13c7854270086ac05e524",
    "area_id": "381b81e7b08f4e66a3cebbe7cfe6c11e"
  }
}
```

</details>

<details>
<summary>Additional logs</summary>

```
Paste any additional debug logs here.
```

</details>



Discussion:
I think it's more like the `_TZ3210_9q49basr` one (although I think both quirks do exactly the same thing).
Could you try to add your device to the `ts0501bs.py` quirk?:
* https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0501bs.py

If you are not familiar, there are some guides about it. Maybe the most popular can be:
* https://github.com/zigpy/zha-device-handlers/discussions/693#discussioncomment-857274
Per "tuya standard" is all TS0501B Dimmable light lights https://developer.tuya.com/en/docs/iot-device-dev/tuya-endtocloud-logic?id=Kav5tfxsbsncf#title-14-Lights and i think its can being time using `MODEL` instead of `MODEL_INFO` and merger the 2 tuya quirks and also the LIDL ones to one more general quirk that is patching all tuya dimmebal light so user is not getting problems all the time with new versions.

And i think we can using the same Principe for more tuya devices that is in the tuya standard list and all or most is coming with the same bugs.

Edit: Tuya is reading the Mode ID and dont care of other Zigbee information if its finding one good one and if not its using the real Zigbee config the device is having and is using it and its working OK for tuya cloud and not Zigbee certifying the devices.
Not sure if can be done because of the diferent `TuyaManufCluster`. But I agree to merge all of them if not possible in the same quirk, at least at the same file.

2 quirks is deleting the color cluster and one is patching the attribute {0x400A: 0} on the color cluster (that shall not being present on one dimmer light). Witch way is right is one good question and the tuya manufacture cluster is not being used so all can being treated the same way.

One thinking of the LIDL ones is the A version i think its being Zigbee certificated versions but looks having the same bugs as the "normal" tuya B ones.
The tuya manufacture cluster can being used for "tuya scenes" switches but  we have not seen how they is using it and the TS004F and the remote LIDL have shipping is using normal Zigbee commands for changing the lights and no magic is being done as IKEA is doing with there remotes and lights with custom scene commands.
> 2 quirks is deleting the color cluster and one is patching the attribute {0x400A: 0} on the color cluster (that shall not being present on one dimmer light). Witch way is right is one good question and the tuya manufacture cluster is not being used so all can being treated the same way.

Attribute `0x400A` is the device `ColorCapabilities`:
* https://github.com/zigpy/zigpy/blob/b166e2e1f22c49bad201d7ecdf202f0fc9b7b087/zigpy/zcl/clusters/lighting.py#L118

I bet that setting to 0 will disable any color capabilities for the device, and probably would have the same effect that removing the cluster.


> I think it's more like the `_TZ3210_9q49basr` one (although I think both quirks do exactly the same thing). Could you try to add your device to the `ts0501bs.py` quirk?:
> 
>     * https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0501bs.py
> 
> 
> If you are not familiar, there are some guides about it. Maybe the most popular can be:
> 
>     * [Editing (ZHA) quirks in a (HA) container or local. #693 (comment)](https://github.com/zigpy/zha-device-handlers/discussions/693#discussioncomment-857274)

This works! I originally tried ts0501b.py and completely missed ts0501bs.py.
If device is working you can create the PR to add your device to the mainstream?

Just edit from the web the file content adding your device to the MODELS_INFO and follow the instructions:
* https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/tuya/ts0501bs.py

Reference this issue in the first PR comment as follows:
```
Fixes: #1579
```

This way other users will be able to use the device in ZHA thanks to you!
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Resolving patch:
diff --git a/zhaquirks/tuya/ts0501bs.py b/zhaquirks/tuya/ts0501bs.py
--- a/zhaquirks/tuya/ts0501bs.py
+++ b/zhaquirks/tuya/ts0501bs.py
@@ -30,7 +30,11 @@ class DimmableLedController(CustomDevice):
     """Tuya dimmable led controller single channel."""
 
     signature = {
-        MODELS_INFO: [("_TZ3210_9q49basr", "TS0501B")],
+        MODELS_INFO: [
+            ("_TZ3210_9q49basr", "TS0501B"),
+            ("_TZ3210_4zinq6io", "TS0501B"),
+            ("_TZ3210_e5t9bfdv", "TS0501B"),
+        ],
         ENDPOINTS: {
             # <SimpleDescriptor endpoint=1 profile=260 device_type=257
             # input_clusters=[0, 3, 4, 5, 6, 8, 768, 4096, 61184]


Test patch: