From c67017915cb987fce1a9229b0b3eb5ba866e8a6e Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Tue, 3 Sep 2024 14:19:21 +0100 Subject: [PATCH 1/6] Add Sonoff SWV quirk --- zhaquirks/sonoff/swv.py | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 zhaquirks/sonoff/swv.py diff --git a/zhaquirks/sonoff/swv.py b/zhaquirks/sonoff/swv.py new file mode 100644 index 0000000000..090212f86a --- /dev/null +++ b/zhaquirks/sonoff/swv.py @@ -0,0 +1,47 @@ +"""Sonoff SWV - Zigbee smart water valve.""" + +from zigpy.quirks import CustomCluster +from zigpy.quirks.v2 import EntityPlatform, EntityType, QuirkBuilder +import zigpy.types as t +from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef + + +class ValveState(t.enum8): + """Water valve state.""" + + Normal = 0 + Water_Shortage = 1 + Water_Leakage = 2 + Water_Shortage_And_Leakage = 3 + + +class EwelinkCluster(CustomCluster): + """Ewelink specific cluster.""" + + cluster_id = 0xFC11 + + class AttributeDefs(BaseAttributeDefs): + """Attribute definitions.""" + + water_valve_state = ZCLAttributeDef( + id=0x500C, + type=ValveState, + ) + + @property + def _is_manuf_specific(self): + return False + + +( + QuirkBuilder("SONOFF", "SWV") + .replaces(EwelinkCluster) + .enum( + EwelinkCluster.AttributeDefs.water_valve_state.name, + ValveState, + EwelinkCluster.cluster_id, + entity_platform=EntityPlatform.SENSOR, + entity_type=EntityType.DIAGNOSTIC, + ) + .add_to_registry() +) From 6f2d01d59ce1477ad68382f7962d6b7a46b03564 Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Mon, 25 Nov 2024 03:48:42 +0100 Subject: [PATCH 2/6] Add translation key and fallback name --- zhaquirks/sonoff/swv.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zhaquirks/sonoff/swv.py b/zhaquirks/sonoff/swv.py index 090212f86a..bcf07674b3 100644 --- a/zhaquirks/sonoff/swv.py +++ b/zhaquirks/sonoff/swv.py @@ -42,6 +42,8 @@ def _is_manuf_specific(self): EwelinkCluster.cluster_id, entity_platform=EntityPlatform.SENSOR, entity_type=EntityType.DIAGNOSTIC, + translation_key="water_valve_state", + fallback_name="Water valve state" ) .add_to_registry() ) From e65c83476b7db2ed88e81c6b4af691e75a92daa3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 02:48:47 +0000 Subject: [PATCH 3/6] Apply pre-commit auto fixes --- zhaquirks/sonoff/swv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zhaquirks/sonoff/swv.py b/zhaquirks/sonoff/swv.py index bcf07674b3..02db261ba1 100644 --- a/zhaquirks/sonoff/swv.py +++ b/zhaquirks/sonoff/swv.py @@ -43,7 +43,7 @@ def _is_manuf_specific(self): entity_platform=EntityPlatform.SENSOR, entity_type=EntityType.DIAGNOSTIC, translation_key="water_valve_state", - fallback_name="Water valve state" + fallback_name="Water valve state", ) .add_to_registry() ) From 21b400145fce4dd19cef182a3e9b6ef5dc1413d1 Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Tue, 26 Nov 2024 18:58:24 +0100 Subject: [PATCH 4/6] Remove enum sensor for initial PR --- zhaquirks/sonoff/swv.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/zhaquirks/sonoff/swv.py b/zhaquirks/sonoff/swv.py index 02db261ba1..c731d43558 100644 --- a/zhaquirks/sonoff/swv.py +++ b/zhaquirks/sonoff/swv.py @@ -36,14 +36,5 @@ def _is_manuf_specific(self): ( QuirkBuilder("SONOFF", "SWV") .replaces(EwelinkCluster) - .enum( - EwelinkCluster.AttributeDefs.water_valve_state.name, - ValveState, - EwelinkCluster.cluster_id, - entity_platform=EntityPlatform.SENSOR, - entity_type=EntityType.DIAGNOSTIC, - translation_key="water_valve_state", - fallback_name="Water valve state", - ) .add_to_registry() ) From b2f7eec330aec8c44952adbe7369494ae727a6a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:02:20 +0000 Subject: [PATCH 5/6] Apply pre-commit auto fixes --- zhaquirks/sonoff/swv.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/zhaquirks/sonoff/swv.py b/zhaquirks/sonoff/swv.py index c731d43558..dff502e1f6 100644 --- a/zhaquirks/sonoff/swv.py +++ b/zhaquirks/sonoff/swv.py @@ -1,7 +1,7 @@ """Sonoff SWV - Zigbee smart water valve.""" from zigpy.quirks import CustomCluster -from zigpy.quirks.v2 import EntityPlatform, EntityType, QuirkBuilder +from zigpy.quirks.v2 import QuirkBuilder import zigpy.types as t from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef @@ -33,8 +33,4 @@ def _is_manuf_specific(self): return False -( - QuirkBuilder("SONOFF", "SWV") - .replaces(EwelinkCluster) - .add_to_registry() -) +(QuirkBuilder("SONOFF", "SWV").replaces(EwelinkCluster).add_to_registry()) From 0438e959290d967a4e5962a85a622ed2c0f50d2a Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Tue, 26 Nov 2024 19:05:01 +0100 Subject: [PATCH 6/6] Try skipping formatting for v2 quirk def --- zhaquirks/sonoff/swv.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zhaquirks/sonoff/swv.py b/zhaquirks/sonoff/swv.py index dff502e1f6..3389b8b2f2 100644 --- a/zhaquirks/sonoff/swv.py +++ b/zhaquirks/sonoff/swv.py @@ -33,4 +33,8 @@ def _is_manuf_specific(self): return False -(QuirkBuilder("SONOFF", "SWV").replaces(EwelinkCluster).add_to_registry()) +( + QuirkBuilder("SONOFF", "SWV") + .replaces(EwelinkCluster) + .add_to_registry() +) # fmt: skip