Skip to content

Commit

Permalink
Allow custom tuya_meterig value converter.
Browse files Browse the repository at this point in the history
Convert RoyalGardineer valve water consumed value from deciliters to liters.
  • Loading branch information
mrrstux committed Nov 27, 2024
1 parent 0a0f667 commit 376f5da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
19 changes: 10 additions & 9 deletions zhaquirks/tuya/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
from enum import Enum
from typing import Any, Optional

from zhaquirks.tuya import (
TUYA_CLUSTER_ID,
PowerConfiguration,
TuyaLocalCluster,
TuyaPowerConfigurationCluster2AAA,
)
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster, TuyaOnOffNM
from zigpy.quirks import _DEVICE_REGISTRY
from zigpy.quirks.registry import DeviceRegistry
from zigpy.quirks.v2 import QuirkBuilder, QuirksV2RegistryEntry
Expand All @@ -20,14 +27,6 @@
)
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks.tuya import (
TUYA_CLUSTER_ID,
PowerConfiguration,
TuyaLocalCluster,
TuyaPowerConfigurationCluster2AAA,
)
from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster, TuyaOnOffNM


class TuyaRelativeHumidity(RelativeHumidity, TuyaLocalCluster):
"""Tuya local RelativeHumidity cluster."""
Expand Down Expand Up @@ -93,13 +92,15 @@ def tuya_battery(
def tuya_metering(
self,
dp_id: int,
converter: Optional[Callable[[Any], Any]] = None,
metering_cfg: TuyaLocalCluster = TuyaValveWaterConsumed,
) -> QuirkBuilder:
"""Add a Tuya Metering Configuration."""
self.tuya_dp(
dp_id,
metering_cfg.ep_attribute,
"current_summ_delivered",
attribute_name="current_summ_delivered",
converter=converter,
)
self.adds(metering_cfg)
return self
Expand Down
23 changes: 11 additions & 12 deletions zhaquirks/tuya/ts0601_valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

from datetime import datetime, timedelta, timezone

from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.quirks.v2 import EntityPlatform, EntityType
from zigpy.quirks.v2.homeassistant import UnitOfTime
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import Basic, Groups, Identify, OnOff, Ota, Scenes, Time
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks import DoublingPowerConfigurationCluster
from zhaquirks.const import (
DEVICE_TYPE,
Expand All @@ -35,6 +25,15 @@
TuyaOnOff,
TuyaPowerConfigurationCluster,
)
from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.quirks.v2 import EntityPlatform, EntityType
from zigpy.quirks.v2.homeassistant import UnitOfTime
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import Basic, Groups, Identify, OnOff, Ota, Scenes, Time
from zigpy.zcl.clusters.smartenergy import Metering


class TuyaValveWaterConsumed(Metering, TuyaLocalCluster):
Expand Down Expand Up @@ -592,8 +591,8 @@ class RoyalGardineerTimerState(t.enum8):
TuyaQuirkBuilder("_TZE200_2wg5qrjy", "TS0601")
.tuya_onoff(dp_id=1)
.tuya_battery(dp_id=7, power_cfg=TuyaPowerConfigurationCluster2AA)
# Might need a converter: x // 10
.tuya_metering(dp_id=5)
# Water consumed (value comes in deciliters - convert it to liters)
.tuya_metering(dp_id=5, converter=lambda x: x // 10)
# Timer time left/remaining (raw value in seconds)
.tuya_number(
dp_id=11,
Expand Down

0 comments on commit 376f5da

Please sign in to comment.