Skip to content
Merged
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
7 changes: 3 additions & 4 deletions tests/test_tuya_builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for TuyaQuirkBuilder."""

from collections.abc import ByteString
import datetime
from unittest import mock

Expand Down Expand Up @@ -166,13 +165,13 @@ class ModTuyaMCUCluster(TuyaMCUCluster):
class Tuya3PhaseElectricalMeasurement(ElectricalMeasurement, TuyaLocalCluster):
"""Tuya Electrical Measurement cluster."""

def dpToPower(data: ByteString) -> int:
def dpToPower(data: bytes) -> int:
return data[0]

def dpToCurrent(data: ByteString) -> int:
def dpToCurrent(data: bytes) -> int:
return data[1]

def dpToVoltage(data: ByteString) -> int:
def dpToVoltage(data: bytes) -> int:
return data[2]

entry = (
Expand Down
10 changes: 4 additions & 6 deletions zhaquirks/tuya/ts0601_power.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tuya Power Meter."""

from collections.abc import ByteString

from zigpy.quirks.v2 import EntityType, SensorDeviceClass, SensorStateClass
from zigpy.quirks.v2.homeassistant import (
PERCENTAGE,
Expand All @@ -18,7 +16,7 @@
from zhaquirks.tuya.builder import TuyaQuirkBuilder


def dp_to_power(data: ByteString) -> int:
def dp_to_power(data: bytes) -> int:
"""Convert DP data to power value."""
# From https://github.com/Koenkk/zigbee2mqtt/issues/18603#issuecomment-2277697295
power = int(data)
Expand All @@ -27,7 +25,7 @@ def dp_to_power(data: ByteString) -> int:
return power


def multi_dp_to_power(data: ByteString) -> int:
def multi_dp_to_power(data: bytes) -> int:
"""Convert DP data to power value."""
# Support negative power readings
# From https://github.com/Koenkk/zigbee2mqtt/issues/18603#issuecomment-2277697295
Expand All @@ -37,12 +35,12 @@ def multi_dp_to_power(data: ByteString) -> int:
return power


def multi_dp_to_current(data: ByteString) -> int:
def multi_dp_to_current(data: bytes) -> int:
"""Convert DP data to current value."""
return data[4] | (data[3] << 8)


def multi_dp_to_voltage(data: ByteString) -> int:
def multi_dp_to_voltage(data: bytes) -> int:
"""Convert DP data to voltage value."""
return data[1] | (data[0] << 8)

Expand Down
Loading