mirror of
https://github.com/home-assistant/core.git
synced 2025-09-09 23:01:40 +02:00
Rename Tuya parsing models (#150498)
This commit is contained in:
@@ -99,23 +99,23 @@ class EnumTypeData:
|
|||||||
return cls(dpcode, **parsed)
|
return cls(dpcode, **parsed)
|
||||||
|
|
||||||
|
|
||||||
class ComplexTypeData:
|
class ComplexValue:
|
||||||
"""Complex Type Data (for JSON/RAW parsing)."""
|
"""Complex value (for JSON/RAW parsing)."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, data: str) -> Self:
|
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")
|
raise NotImplementedError("from_json is not implemented for this type")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_raw(cls, data: str) -> Self | None:
|
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")
|
raise NotImplementedError("from_raw is not implemented for this type")
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ElectricityTypeData(ComplexTypeData):
|
class ElectricityValue(ComplexValue):
|
||||||
"""Electricity Type Data."""
|
"""Electricity complex value."""
|
||||||
|
|
||||||
electriccurrent: str | None = None
|
electriccurrent: str | None = None
|
||||||
power: str | None = None
|
power: str | None = None
|
||||||
@@ -123,12 +123,12 @@ class ElectricityTypeData(ComplexTypeData):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, data: str) -> Self:
|
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()))
|
return cls(**json.loads(data.lower()))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_raw(cls, data: str) -> Self | None:
|
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)
|
raw = base64.b64decode(data)
|
||||||
if len(raw) == 0:
|
if len(raw) == 0:
|
||||||
return None
|
return None
|
||||||
|
@@ -42,7 +42,7 @@ from .const import (
|
|||||||
UnitOfMeasurement,
|
UnitOfMeasurement,
|
||||||
)
|
)
|
||||||
from .entity import TuyaEntity
|
from .entity import TuyaEntity
|
||||||
from .models import ComplexTypeData, ElectricityTypeData, EnumTypeData, IntegerTypeData
|
from .models import ComplexValue, ElectricityValue, EnumTypeData, IntegerTypeData
|
||||||
|
|
||||||
_WIND_DIRECTIONS = {
|
_WIND_DIRECTIONS = {
|
||||||
"north": 0.0,
|
"north": 0.0,
|
||||||
@@ -68,7 +68,7 @@ _WIND_DIRECTIONS = {
|
|||||||
class TuyaSensorEntityDescription(SensorEntityDescription):
|
class TuyaSensorEntityDescription(SensorEntityDescription):
|
||||||
"""Describes Tuya sensor entity."""
|
"""Describes Tuya sensor entity."""
|
||||||
|
|
||||||
complex_type: type[ComplexTypeData] | None = None
|
complex_type: type[ComplexValue] | None = None
|
||||||
subkey: str | None = None
|
subkey: str | None = None
|
||||||
state_conversion: Callable[[Any], StateType] | None = None
|
state_conversion: Callable[[Any], StateType] | None = None
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="electriccurrent",
|
subkey="electriccurrent",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -407,7 +407,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -416,7 +416,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="voltage",
|
subkey="voltage",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -425,7 +425,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="electriccurrent",
|
subkey="electriccurrent",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -434,7 +434,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -443,7 +443,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="voltage",
|
subkey="voltage",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -452,7 +452,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="electriccurrent",
|
subkey="electriccurrent",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -461,7 +461,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -470,7 +470,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="voltage",
|
subkey="voltage",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1396,7 +1396,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
translation_key="total_power",
|
translation_key="total_power",
|
||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1412,7 +1412,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="electriccurrent",
|
subkey="electriccurrent",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1421,7 +1421,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1430,7 +1430,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="voltage",
|
subkey="voltage",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1439,7 +1439,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="electriccurrent",
|
subkey="electriccurrent",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1448,7 +1448,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1457,7 +1457,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="voltage",
|
subkey="voltage",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1466,7 +1466,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="electriccurrent",
|
subkey="electriccurrent",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1475,7 +1475,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
native_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="power",
|
subkey="power",
|
||||||
),
|
),
|
||||||
TuyaSensorEntityDescription(
|
TuyaSensorEntityDescription(
|
||||||
@@ -1484,7 +1484,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
|
|||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
complex_type=ElectricityTypeData,
|
complex_type=ElectricityValue,
|
||||||
subkey="voltage",
|
subkey="voltage",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1583,7 +1583,7 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
|
|||||||
|
|
||||||
_status_range: DeviceStatusRange | None = None
|
_status_range: DeviceStatusRange | None = None
|
||||||
_type: DPType | None = None
|
_type: DPType | None = None
|
||||||
_type_data: IntegerTypeData | EnumTypeData | ComplexTypeData | None = None
|
_type_data: IntegerTypeData | EnumTypeData | None = None
|
||||||
_uom: UnitOfMeasurement | None = None
|
_uom: UnitOfMeasurement | None = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
Reference in New Issue
Block a user