Rename Tuya parsing models (#150498)

This commit is contained in:
epenet
2025-08-12 18:02:26 +02:00
committed by GitHub
parent 218b0738ca
commit ad3174f6e6
2 changed files with 30 additions and 30 deletions

View File

@@ -99,23 +99,23 @@ class EnumTypeData:
return cls(dpcode, **parsed)
class ComplexTypeData:
"""Complex Type Data (for JSON/RAW parsing)."""
class ComplexValue:
"""Complex value (for JSON/RAW parsing)."""
@classmethod
def from_json(cls, data: str) -> Self:
"""Load JSON string and return a ComplexTypeData object."""
"""Load JSON string and return a ComplexValue object."""
raise NotImplementedError("from_json is not implemented for this type")
@classmethod
def from_raw(cls, data: str) -> Self | None:
"""Decode base64 string and return a ComplexTypeData object."""
"""Decode base64 string and return a ComplexValue object."""
raise NotImplementedError("from_raw is not implemented for this type")
@dataclass
class ElectricityTypeData(ComplexTypeData):
"""Electricity Type Data."""
class ElectricityValue(ComplexValue):
"""Electricity complex value."""
electriccurrent: str | None = None
power: str | None = None
@@ -123,12 +123,12 @@ class ElectricityTypeData(ComplexTypeData):
@classmethod
def from_json(cls, data: str) -> Self:
"""Load JSON string and return a ElectricityTypeData object."""
"""Load JSON string and return a ElectricityValue object."""
return cls(**json.loads(data.lower()))
@classmethod
def from_raw(cls, data: str) -> Self | None:
"""Decode base64 string and return a ElectricityTypeData object."""
"""Decode base64 string and return a ElectricityValue object."""
raw = base64.b64decode(data)
if len(raw) == 0:
return None

View File

@@ -42,7 +42,7 @@ from .const import (
UnitOfMeasurement,
)
from .entity import TuyaEntity
from .models import ComplexTypeData, ElectricityTypeData, EnumTypeData, IntegerTypeData
from .models import ComplexValue, ElectricityValue, EnumTypeData, IntegerTypeData
_WIND_DIRECTIONS = {
"north": 0.0,
@@ -68,7 +68,7 @@ _WIND_DIRECTIONS = {
class TuyaSensorEntityDescription(SensorEntityDescription):
"""Describes Tuya sensor entity."""
complex_type: type[ComplexTypeData] | None = None
complex_type: type[ComplexValue] | None = None
subkey: str | None = None
state_conversion: Callable[[Any], StateType] | None = None
@@ -398,7 +398,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
@@ -407,7 +407,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -416,7 +416,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="voltage",
),
TuyaSensorEntityDescription(
@@ -425,7 +425,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
@@ -434,7 +434,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -443,7 +443,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="voltage",
),
TuyaSensorEntityDescription(
@@ -452,7 +452,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
@@ -461,7 +461,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -470,7 +470,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="voltage",
),
TuyaSensorEntityDescription(
@@ -1396,7 +1396,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
translation_key="total_power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -1412,7 +1412,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
@@ -1421,7 +1421,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -1430,7 +1430,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="voltage",
),
TuyaSensorEntityDescription(
@@ -1439,7 +1439,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
@@ -1448,7 +1448,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -1457,7 +1457,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="voltage",
),
TuyaSensorEntityDescription(
@@ -1466,7 +1466,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
@@ -1475,7 +1475,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="power",
),
TuyaSensorEntityDescription(
@@ -1484,7 +1484,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
complex_type=ElectricityTypeData,
complex_type=ElectricityValue,
subkey="voltage",
),
),
@@ -1583,7 +1583,7 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
_status_range: DeviceStatusRange | None = None
_type: DPType | None = None
_type_data: IntegerTypeData | EnumTypeData | ComplexTypeData | None = None
_type_data: IntegerTypeData | EnumTypeData | None = None
_uom: UnitOfMeasurement | None = None
def __init__(