Repository: zigpy/zha-device-handlers

Issue:
[BUG] incompatible changes for Tuya TS0001 inwall switch 
**Describe the bug**
All light entities associated to Tuya TS0001 wall switches stopped working and new entities in switch domain were created after update to HomeAssistant 2021.12b1

**To Reproduce**
Steps to reproduce the behavior:
1. Upgrade from HA 2021.11.x to 2021.12b1 that includes latest revision of this package as of today.

**Expected behavior**
Old entities remained as is and no automations are broken.

**Screenshots**
N/A

**Additional context**

Previously, it was handled as an standard Zigbee device, without any quirk.

After upgrade, it was handled using quirk zhaquirks.tuya.ts000x.Switch_1G_GPP

It seems that this quirk is exposing the device as a smart plug but is an "inwall" light switch designed to operate lights.

See
https://a.aliexpress.com/_vsVqkq

It only happen to the 1 gang switches. 2 gang switches still work okay.


Discussion:
It seems related with this line: https://github.com/zigpy/zha-device-handlers/blob/a4c6cdb9e531b9f643567c32e8cd8bacc64840cd/zhaquirks/tuya/ts000x.py#L71

Previous versions were using zha.DeviceType.ON_OFF_LIGHT instead.

Can we change it?
2 gang switches are still working because there are only quirks for TS0001 (1 gang) and TS0003 (3 gang devices) but not for TS0002. 

So it is still handled as an standard zigbee device.
I agree 100% with you and i was asking the maintainer then adding the new functions then the user was liking having it as **ON_OFF_PLUG_IN_UNIT** that i think its little strange.

I can doing one PR and putting the "real " device type back and letting the maintainer deciding if hi like have it.

Can you posting the signature for your TS0002 so we can adding it and getting the extra functions the 1 and 3 gang have getting (not the ON_OFF_PLUG_IN_UNIT thing !!) ?
I copied the TS0003 definition, removed the endpoint 3 and changed the MODEL to TS0002 and works almost perfectly.

Cluster TuyaZBExternalSwitchTypeCluster is not working for the second endpoint but it seems a hardware issue: the cluster in the first endpoint affects both endpoints and you cannot setup a momentary push button in one endpoint and a toggle switch in another. Maybe we should remove the second cluster.
Or maybe the manufacturer fixes the issue at some point... who knows!
We have with tuya devices here so its not 110% the same on all devices like I have one LIDL 3 plug power strip with 4 USB and one user have one newer one and cant steering the plugs individual but with tuya ZBGW its possible (its missing endpoint 2 and 3).

And some attribute is not implanted and other not or not working = tuya.

I think its better letting it as it is and  waiting for if tuya is releasing one new firmware !!

Do you like making on PR with the change `DEVICE_TYPE` back to its original and adding the the 2 gang ?

I can doing it  but is better if having the device in the hand and can testing it working so no small errors in in the code (copy and paste error).

If you doing it write its fixing one braking thing.
I will try. I have to travel for next two weeks, so no promise.

On Wed, 8 Dec 2021 at 09:19 MattWestb ***@***.***> wrote:

> We have with tuya devices here so its not 110% the same on all devices
> like I have one LIDL 3 plug power strip with 4 USB and one user have one
> newer one and cant steering the plugs individual but with tuya ZBGW its
> possible (its missing endpoint 2 and 3).
>
> And some attribute is not implanted and other not or not working = tuya.
>
> I think its better letting it as it is and waiting for if tuya is
> releasing one new firmware !!
>
> Do you like making on PR with the change DEVICE_TYPE back to its original
> and adding the the 2 gang ?
>
> I can doing it but is better if having the device in the hand and can
> testing it working so no small errors in in the code (copy and paste error).
>
> If you doing it write its fixing one braking thing.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/zigpy/zha-device-handlers/issues/1209#issuecomment-988594511>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABM4WB3RA4IBVPIUBVYDZELUP4IK3ANCNFSM5JSIKO7A>
> .
>

OK i was thinking getting one fast fix before the release of HA 2021.12 but i think its too late.

I making one PR with your changes and hoping it going well and perhaps it can going in the bug fix fro HA.

Resolving patch:
diff --git a/zhaquirks/tuya/ts000x.py b/zhaquirks/tuya/ts000x.py
--- a/zhaquirks/tuya/ts000x.py
+++ b/zhaquirks/tuya/ts000x.py
@@ -68,7 +68,7 @@ class Switch_1G_GPP(CustomDevice):
         ENDPOINTS: {
             1: {
                 PROFILE_ID: zha.PROFILE_ID,
-                DEVICE_TYPE: zha.DeviceType.ON_OFF_PLUG_IN_UNIT,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                 INPUT_CLUSTERS: [
                     Basic.cluster_id,
                     Identify.cluster_id,
@@ -84,6 +84,94 @@ class Switch_1G_GPP(CustomDevice):
     }
 
 
+class Switch_2G_GPP(CustomDevice):
+    """Tuya 2 gang switch module with restore power state support."""
+
+    signature = {
+        MODEL: "TS0002",
+        ENDPOINTS: {
+            # <SimpleDescriptor endpoint=1 profile=260 device_type=256
+            # device_version=1
+            # input_clusters=[0, 3, 4, 5, 6, 57344, 57345]
+            # output_clusters=[10, 25]>
+            1: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
+                INPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    Identify.cluster_id,
+                    Groups.cluster_id,
+                    Scenes.cluster_id,
+                    OnOff.cluster_id,
+                    TuyaZBE000Cluster.cluster_id,
+                    TuyaZBExternalSwitchTypeCluster.cluster_id,
+                ],
+                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
+            },
+            # <SimpleDescriptor endpoint=2 profile=260 device_type=256
+            # device_version=1
+            # input_clusters=[4, 5, 6, 57345]
+            # output_clusters=[]>
+            2: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
+                INPUT_CLUSTERS: [
+                    Groups.cluster_id,
+                    Scenes.cluster_id,
+                    OnOff.cluster_id,
+                    TuyaZBExternalSwitchTypeCluster.cluster_id,
+                ],
+                OUTPUT_CLUSTERS: [],
+            },
+            # <SimpleDescriptor endpoint=242 profile=41440 device_type=97
+            # device_version=0
+            # input_clusters=[]
+            # output_clusters=[33]>
+            242: {
+                PROFILE_ID: 41440,
+                DEVICE_TYPE: 97,
+                INPUT_CLUSTERS: [],
+                OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
+            },
+        },
+    }
+    replacement = {
+        ENDPOINTS: {
+            1: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
+                INPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    Identify.cluster_id,
+                    Groups.cluster_id,
+                    Scenes.cluster_id,
+                    TuyaZBOnOffAttributeCluster,
+                    TuyaZBE000Cluster,
+                    TuyaZBExternalSwitchTypeCluster,
+                ],
+                OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
+            },
+            2: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
+                INPUT_CLUSTERS: [
+                    Groups.cluster_id,
+                    Scenes.cluster_id,
+                    TuyaZBOnOffAttributeCluster,
+                    TuyaZBExternalSwitchTypeCluster,
+                ],
+                OUTPUT_CLUSTERS: [],
+            },
+            242: {
+                PROFILE_ID: 41440,
+                DEVICE_TYPE: 97,
+                INPUT_CLUSTERS: [],
+                OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
+            },
+        },
+    }
+
+
 class Switch_3G_GPP(CustomDevice):
     """Tuya 3 gang switch module with restore power state support."""
 
@@ -154,7 +242,7 @@ class Switch_3G_GPP(CustomDevice):
         ENDPOINTS: {
             1: {
                 PROFILE_ID: zha.PROFILE_ID,
-                DEVICE_TYPE: zha.DeviceType.ON_OFF_PLUG_IN_UNIT,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                 INPUT_CLUSTERS: [
                     Basic.cluster_id,
                     Identify.cluster_id,
@@ -168,7 +256,7 @@ class Switch_3G_GPP(CustomDevice):
             },
             2: {
                 PROFILE_ID: zha.PROFILE_ID,
-                DEVICE_TYPE: zha.DeviceType.ON_OFF_PLUG_IN_UNIT,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                 INPUT_CLUSTERS: [
                     Groups.cluster_id,
                     Scenes.cluster_id,
@@ -179,7 +267,7 @@ class Switch_3G_GPP(CustomDevice):
             },
             3: {
                 PROFILE_ID: zha.PROFILE_ID,
-                DEVICE_TYPE: zha.DeviceType.ON_OFF_PLUG_IN_UNIT,
+                DEVICE_TYPE: zha.DeviceType.ON_OFF_LIGHT,
                 INPUT_CLUSTERS: [
                     Groups.cluster_id,
                     Scenes.cluster_id,


Test patch: