Repository: zigpy/zha-device-handlers

Issue:
SmartThings moisturev4 sensor wrong device class
The SmartThings moisturev4 sensor has the wrong device class.  It shows up as a generic on/off device, and not as a moisture sensor.

This is because the `zone_type` attribute returns `0` instead of `0x2A` as it should.

It is already detected with the `zhaquirks.smartthings.iasv4.SmartThingsIASV4` quirk, which is shared with the "motionv4" device.  It isn't that hard to replace that `zone_type` attribute.  But it seems like the "motionv4" and "moisturev4" should probably be split into two different files/classes.



Discussion:
Alternatively you could customize device class through config panel -> customization -> pick device, select device class and override it.
I'd rather not duplicate the entire quirk and add a custom cluster for something that is easily overridden in HA. As @Adminiuga stated you can override the device class in HA. 
Interesting, not the response I expected, but I understand.

I may revisit this shortly. It just isn’t high up on the priority list since there is a work around.
I was thinking about this at some point and while yeah, we could create a quirks whick takes the device type, but:
1. If more devices with wrong device class pop up, how do you stay up to date? 
2. In case of an open/close sensor HA has device classes for doors, garage doors etc while Zigbee doesn't (I could be wrong) so overriding from HA seemed to be a better option to me
I understand what both you are saying.  I expected that I would implement this new quirk, but I wanted to create an issue to discuss it first.  I have seen (and experienced) writing a bunch of code only for it to be quickly rejected at the pull request.

To me it seems like it would make it easier for people to migrate to Home Assistant (especially from SmartThings, using these sensors) if things worked out of the box.  Also it just seemed like the "correct" way to fix the issue, short of changing the firmware in the sensor.

I think making the default "correct" (in this case moisture sensor is an obvious choice) and of course still allowing for the user to change the class for some ambiguous device seems like it would be the best of all.
PRs are always welcome :)

On Sun, Sep 29, 2019, 13:45 presslab-us <notifications@github.com> wrote:

> I understand what both you are saying. I expected that I would implement
> this new quirk, but I wanted to create an issue to discuss it first. I have
> seen (and experienced) writing a bunch of code only for it to be quickly
> rejected at the pull request.
>
> To me it seems like it would make it easier for people to migrate to Home
> Assistant (especially from SmartThings, using these sensors) if things
> worked out of the box. Also it just seemed like the "correct" way to fix
> the issue, short of changing the firmware in the sensor.
>
> I think making the default "correct" (in this case moisture sensor is an
> obvious choice) and of course still allowing for the user to change the
> class for some ambiguous device seems like it would be the best of all.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/dmulcahey/zha-device-handlers/issues/170?email_source=notifications&email_token=ABMOM4ERBEXWUKHUWRDXH73QMDSS3A5CNFSM4I3PVPIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD732QVI#issuecomment-536324181>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABMOM4DL7P6Q6TJDNMFFHWLQMDSS3ANCNFSM4I3PVPIA>
> .
>

If you want to implement it, go for it 😁

Resolving patch:
diff --git a/zhaquirks/smartthings/moisturev4.py b/zhaquirks/smartthings/moisturev4.py
new file mode 100644
--- /dev/null
+++ b/zhaquirks/smartthings/moisturev4.py
@@ -0,0 +1,76 @@
+"""Device handler for smartthings moistureV4 sensor."""
+from zigpy.profiles import zha
+from zigpy.quirks import CustomDevice
+from zigpy.zcl.clusters.general import Basic, BinaryInput, Identify, Ota, PollControl
+from zigpy.zcl.clusters.measurement import TemperatureMeasurement
+from zigpy.zcl.clusters.security import IasZone
+
+from zhaquirks.centralite import PowerConfigurationCluster
+
+from . import SMART_THINGS
+from ..const import (
+    DEVICE_TYPE,
+    ENDPOINTS,
+    INPUT_CLUSTERS,
+    MODELS_INFO,
+    OUTPUT_CLUSTERS,
+    PROFILE_ID,
+)
+
+
+class CustomIasZone(IasZone):
+    """Custom IasZone cluster."""
+
+    MOISTURE_TYPE = 0x002A
+    ZONE_TYPE = 0x0001
+
+    def _update_attribute(self, attrid, value):
+        if attrid == self.ZONE_TYPE:
+            super()._update_attribute(attrid, self.MOISTURE_TYPE)
+        else:
+            super()._update_attribute(attrid, value)
+
+
+class SmartThingsMoistureV4(CustomDevice):
+    """SmartThingsMoistureV4."""
+
+    signature = {
+        #  <SimpleDescriptor endpoint=1 profile=260 device_type=1026
+        #  device_version=0
+        #  input_clusters=[0, 1, 3, 15, 1026, 1280, 32]
+        #  output_clusters=[25]>
+        MODELS_INFO: [(SMART_THINGS, "moisturev4")],
+        ENDPOINTS: {
+            1: {
+                PROFILE_ID: zha.PROFILE_ID,
+                DEVICE_TYPE: zha.DeviceType.IAS_ZONE,
+                INPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    PowerConfigurationCluster.cluster_id,
+                    Identify.cluster_id,
+                    BinaryInput.cluster_id,
+                    PollControl.cluster_id,
+                    TemperatureMeasurement.cluster_id,
+                    IasZone.cluster_id,
+                ],
+                OUTPUT_CLUSTERS: [Ota.cluster_id],
+            }
+        },
+    }
+
+    replacement = {
+        ENDPOINTS: {
+            1: {
+                INPUT_CLUSTERS: [
+                    Basic.cluster_id,
+                    PowerConfigurationCluster,
+                    Identify.cluster_id,
+                    BinaryInput.cluster_id,
+                    PollControl.cluster_id,
+                    TemperatureMeasurement.cluster_id,
+                    CustomIasZone,
+                ],
+                OUTPUT_CLUSTERS: [Ota.cluster_id],
+            }
+        }
+    }
diff --git a/zhaquirks/smartthings/iasv4.py b/zhaquirks/smartthings/motionv4.py
similarity index 89%
rename from zhaquirks/smartthings/iasv4.py
rename to zhaquirks/smartthings/motionv4.py
--- a/zhaquirks/smartthings/iasv4.py
+++ b/zhaquirks/smartthings/motionv4.py
@@ -1,4 +1,4 @@
-"""Device handler for smartthings IAS V4 sensors."""
+"""Device handler for smartthings motionV4 sensors."""
 from zigpy.profiles import zha
 from zigpy.quirks import CustomDevice
 from zigpy.zcl.clusters.general import Basic, BinaryInput, Identify, Ota, PollControl
@@ -18,15 +18,15 @@
 )
 
 
-class SmartThingsIASV4(CustomDevice):
-    """SmartThingsIASV4."""
+class SmartThingsMotionV4(CustomDevice):
+    """SmartThingsMotionV4."""
 
     signature = {
         #  <SimpleDescriptor endpoint=1 profile=260 device_type=1026
         #  device_version=0
         #  input_clusters=[0, 1, 3, 15, 1026, 1280, 32]
         #  output_clusters=[25]>
-        MODELS_INFO: [(SMART_THINGS, "motionv4"), (SMART_THINGS, "moisturev4")],
+        MODELS_INFO: [(SMART_THINGS, "motionv4")],
         ENDPOINTS: {
             1: {
                 PROFILE_ID: zha.PROFILE_ID,


Test patch: