Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quirk for Sonoff SWV Smart Water Valve #3340

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions zhaquirks/sonoff/swv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Sonoff SWV - Zigbee smart water valve."""

import typing

from zigpy.quirks import CustomCluster
from zigpy.quirks.v2 import QuirkBuilder
from zigpy.quirks.v2.homeassistant.binary_sensor import BinarySensorDeviceClass
import zigpy.types as t
from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef


class ValveState(t.enum8):
"""Water valve state."""

Water_Shortage = 1
Water_Leakage = 2
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To show all the possible values if querying the cluster directly, can you also add the Normal (0) and Water leakage and shortage (3) values?



class EwelinkCluster(CustomCluster):
"""Ewelink specific cluster."""

cluster_id = 0xFC11

class AttributeDefs(BaseAttributeDefs):
"""Attribute definitions."""

water_supply_state = ZCLAttributeDef(
id=0x500C,
type=bool,
)

valve_leak_state = ZCLAttributeDef(
id=0x500C,
type=bool,
)

@property
def _is_manuf_specific(self):
return False

Check warning on line 39 in zhaquirks/sonoff/swv.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/sonoff/swv.py#L39

Added line #L39 was not covered by tests

def get(self, key: int | str, default: typing.Any | None = None) -> typing.Any:
"""Map binary sensors onto bits of shared attribute."""

value = super().get(key, default)
match key:
case self.AttributeDefs.water_supply_state.name:
return value & ValveState.Water_Shortage
case self.AttributeDefs.valve_leak_state.name:
return value & ValveState.Water_Leakage
raise ValueError(f"Unknown attribute {key}")

Check warning on line 50 in zhaquirks/sonoff/swv.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/sonoff/swv.py#L44-L50

Added lines #L44 - L50 were not covered by tests
Copy link
Contributor

@fgsch fgsch Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: I suppose key would only be one of the supported attributes but perhaps for unknown keys this should return the value?



(
QuirkBuilder("SONOFF", "SWV")
.replaces(EwelinkCluster)
.binary_sensor(
EwelinkCluster.AttributeDefs.water_supply_state.name,
EwelinkCluster.cluster_id,
device_class=BinarySensorDeviceClass.PROBLEM,
translation_key="water_supply",
fallback_name="Water supply status",
)
.binary_sensor(
EwelinkCluster.AttributeDefs.valve_leak_state.name,
EwelinkCluster.cluster_id,
device_class=BinarySensorDeviceClass.PROBLEM,
translation_key="valve_leak",
fallback_name="Valve leak status",
)
.add_to_registry()
)
Loading