Updated the support of Tuya Circuit Breaker 'dlq' (#63519)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Dmitry Vasilyev 2022-01-06 15:01:16 +04:00 committed by GitHub
parent 10e2caf9e6
commit 77ccf46c9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 1 deletions

View file

@ -589,6 +589,88 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
subkey="voltage",
),
),
# Circuit Breaker
# https://developer.tuya.com/en/docs/iot/dlq?id=Kb0kidk9enyh8
"dlq": (
TuyaSensorEntityDescription(
key=DPCode.TOTAL_FORWARD_ENERGY,
name="Total Energy",
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_A,
name="Phase A Current",
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=SensorStateClass.MEASUREMENT,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_A,
name="Phase A Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT,
subkey="power",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_A,
name="Phase A Voltage",
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
subkey="voltage",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_B,
name="Phase B Current",
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=SensorStateClass.MEASUREMENT,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_B,
name="Phase B Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT,
subkey="power",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_B,
name="Phase B Voltage",
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
subkey="voltage",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_C,
name="Phase C Current",
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=SensorStateClass.MEASUREMENT,
subkey="electriccurrent",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_C,
name="Phase C Power",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT,
subkey="power",
),
TuyaSensorEntityDescription(
key=DPCode.PHASE_C,
name="Phase C Voltage",
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
subkey="voltage",
),
),
# Robot Vacuum
# https://developer.tuya.com/en/docs/iot/fsd?id=K9gf487ck1tlo
"sd": (
@ -765,6 +847,7 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
"String",
"Enum",
"Json",
"Raw",
):
return None
@ -794,5 +877,11 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
values = ElectricityTypeData.from_json(value)
return getattr(values, self.entity_description.subkey)
if self._status_range.type == "Raw":
if self.entity_description.subkey is None:
return None
values = ElectricityTypeData.from_raw(value)
return getattr(values, self.entity_description.subkey)
# Valid string or enum value
return value