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 sensors for Sonoff SWV Smart Water Valve status #189

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions zha/application/platforms/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import TYPE_CHECKING

from zhaquirks.quirk_ids import DANFOSS_ALLY_THERMOSTAT
from zhaquirks.sonoff import swv as sonoff_swv
from zigpy.quirks.v2 import BinarySensorMetadata

from zha.application import Platform
Expand Down Expand Up @@ -400,3 +401,33 @@
_attr_translation_key: str = "preheat_status"
_attr_entity_registry_enabled_default = False
_attr_entity_category = EntityCategory.DIAGNOSTIC


@MULTI_MATCH(cluster_handler_names="sonoff_manufacturer", models={"SWV"})
class SonoffSWVValveLeakStatus(BinarySensor):
"""Danfoss proprietary attribute for showing the status of the adaptation run."""

_unique_id_suffix = "valve_leak_status"
_attribute_name = "valve_status"
_attr_translation_key: str = "valve_leak"
_attr_device_class = BinarySensorDeviceClass.PROBLEM

@staticmethod
def parse(value: bool | int) -> bool:
"""Parse the raw attribute into a bool state."""
return BinarySensor.parse(value & sonoff_swv.ValveStatusBitmap.Water_Leakage)

Check warning on line 418 in zha/application/platforms/binary_sensor/__init__.py

View check run for this annotation

Codecov / codecov/patch

zha/application/platforms/binary_sensor/__init__.py#L418

Added line #L418 was not covered by tests


@MULTI_MATCH(cluster_handler_names="sonoff_manufacturer", models={"SWV"})
class SonoffSWVWaterShortageStatus(BinarySensor):
"""Danfoss proprietary attribute for showing the status of the adaptation run."""

_unique_id_suffix = "water_supply_status"
_attribute_name = "valve_status"
_attr_translation_key: str = "water_supply"
_attr_device_class = BinarySensorDeviceClass.PROBLEM

@staticmethod
def parse(value: bool | int) -> bool:
"""Parse the raw attribute into a bool state."""
return BinarySensor.parse(value & sonoff_swv.ValveStatusBitmap.Water_Shortage)

Check warning on line 433 in zha/application/platforms/binary_sensor/__init__.py

View check run for this annotation

Codecov / codecov/patch

zha/application/platforms/binary_sensor/__init__.py#L433

Added line #L433 was not covered by tests
11 changes: 8 additions & 3 deletions zha/zigbee/cluster_handlers/manufacturerspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,19 @@

@registries.CLUSTER_HANDLER_ONLY_CLUSTERS.register(SONOFF_CLUSTER)
@registries.CLUSTER_HANDLER_REGISTRY.register(SONOFF_CLUSTER)
class SonoffPresenceSenorClusterHandler(ClusterHandler):
"""SonoffPresenceSensor cluster handler."""
class SonoffClusterHandler(ClusterHandler):
"""Sonoff Custom cluster handler."""

def __init__(self, cluster: zigpy.zcl.Cluster, endpoint: Endpoint) -> None:
"""Initialize SonoffPresenceSensor cluster handler."""
"""Initialize Sonoff cluster handler."""
super().__init__(cluster, endpoint)
if self.cluster.endpoint.model == "SNZB-06P":
self.ZCL_INIT_ATTRS = {"last_illumination_state": True}
elif self.cluster.endpoint.model == "SWV":
self.ZCL_INIT_ATTRS = {"valve_status": True}
self.REPORT_CONFIG = AttrReportConfig(

Check warning on line 463 in zha/zigbee/cluster_handlers/manufacturerspecific.py

View check run for this annotation

Codecov / codecov/patch

zha/zigbee/cluster_handlers/manufacturerspecific.py#L462-L463

Added lines #L462 - L463 were not covered by tests
attr="valve_status", config=REPORT_CONFIG_DEFAULT
)


@registries.CLUSTER_HANDLER_REGISTRY.register(
Expand Down