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 initial Sonoff smart water valve quirk #3346

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Changes from 2 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
47 changes: 47 additions & 0 deletions zhaquirks/sonoff/swv.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +12 to +15
Copy link
Collaborator

@TheJulianJES TheJulianJES Nov 25, 2024

Choose a reason for hiding this comment

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

Would two separate binary sensors make more sense for this? (instead of an enum sensor)
We can't really parse it this via v2 quirks (yet), so just wondering.

Copy link

Choose a reason for hiding this comment

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

I would vote for 2 binary sensors. This would make it more convenient for triggers and alerts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

zigpy/zha#305 and zigpy/zha#303 would be required for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TheJulianJES what about the approach in #3340 to have 2 binary sensors?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would work, but we're creating "fake" attributes there, which isn't optimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TheJulianJES While the work is being decided, can we get this without the enum so at least people can fiddle with the attributes directly using e.g. zha toolkit?

Or you reckon zigpy/zha#305 and zigpy/zha#303 would be handled relatively soon?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's temporarily remove the quirks v2 enum sensor then. We should be able to get the quirk in the HA Core 2024.12 beta for tomorrow then.
Not sure on the timeline of the "attribute converters" yet. I hope we can get to it soon, but no promises.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, thank you!



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,
TheJulianJES marked this conversation as resolved.
Show resolved Hide resolved
)
.add_to_registry()
)
Loading