mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Move Tuya suggested units to the sensor descriptions (#192901)
This commit is contained in:
@@ -50,12 +50,14 @@ from homeassistant.components.sensor import (
|
||||
)
|
||||
from homeassistant.const import (
|
||||
EntityCategory,
|
||||
UnitOfApparentPower,
|
||||
UnitOfDensity,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfRatio,
|
||||
UnitOfReactivePower,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
@@ -98,6 +100,7 @@ def _electricity_data(dpcode: DPCode) -> tuple[TuyaSensorEntityDescription, ...]
|
||||
translation_key=f"{dpcode}_current",
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||
wrapper_class=(ElectricityCurrentRawWrapper, ElectricityCurrentJsonWrapper),
|
||||
),
|
||||
TuyaSensorEntityDescription(
|
||||
@@ -106,6 +109,7 @@ def _electricity_data(dpcode: DPCode) -> tuple[TuyaSensorEntityDescription, ...]
|
||||
translation_key=f"{dpcode}_power",
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||
wrapper_class=(ElectricityPowerRawWrapper, ElectricityPowerJsonWrapper),
|
||||
),
|
||||
TuyaSensorEntityDescription(
|
||||
@@ -122,6 +126,7 @@ def _electricity_data(dpcode: DPCode) -> tuple[TuyaSensorEntityDescription, ...]
|
||||
translation_key=f"{dpcode}_reactive_power",
|
||||
device_class=SensorDeviceClass.REACTIVE_POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfReactivePower.KILO_VOLT_AMPERE_REACTIVE,
|
||||
wrapper_class=(
|
||||
ElectricityReactivePowerRawWrapper,
|
||||
ElectricityReactivePowerJsonWrapper,
|
||||
@@ -133,6 +138,7 @@ def _electricity_data(dpcode: DPCode) -> tuple[TuyaSensorEntityDescription, ...]
|
||||
translation_key=f"{dpcode}_apparent_power",
|
||||
device_class=SensorDeviceClass.APPARENT_POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfApparentPower.KILO_VOLT_AMPERE,
|
||||
wrapper_class=(
|
||||
ElectricityApparentPowerRawWrapper,
|
||||
ElectricityApparentPowerJsonWrapper,
|
||||
@@ -167,6 +173,7 @@ def _indexed_electricity_data(
|
||||
dpcode=dpcode,
|
||||
device_class=SensorDeviceClass.CURRENT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||
wrapper_class=(ElectricityCurrentHexStringWrapper,),
|
||||
channel_index=index,
|
||||
channel_condition=_has_multiple_phase_channels,
|
||||
@@ -176,6 +183,7 @@ def _indexed_electricity_data(
|
||||
dpcode=dpcode,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||
wrapper_class=(ElectricityPowerHexStringWrapper,),
|
||||
channel_index=index,
|
||||
channel_condition=_has_multiple_phase_channels,
|
||||
@@ -194,6 +202,7 @@ def _indexed_electricity_data(
|
||||
dpcode=dpcode,
|
||||
device_class=SensorDeviceClass.REACTIVE_POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfReactivePower.KILO_VOLT_AMPERE_REACTIVE,
|
||||
wrapper_class=(ElectricityReactivePowerHexStringWrapper,),
|
||||
channel_index=index,
|
||||
channel_condition=_has_multiple_phase_channels,
|
||||
@@ -203,6 +212,7 @@ def _indexed_electricity_data(
|
||||
dpcode=dpcode,
|
||||
device_class=SensorDeviceClass.APPARENT_POWER,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_unit_of_measurement=UnitOfApparentPower.KILO_VOLT_AMPERE,
|
||||
wrapper_class=(ElectricityApparentPowerHexStringWrapper,),
|
||||
channel_index=index,
|
||||
channel_condition=_has_multiple_phase_channels,
|
||||
@@ -2105,10 +2115,6 @@ class TuyaSensorEntity(TuyaEntity, SensorEntity):
|
||||
super().__init__(device, device_manager, description, device_info=device_info)
|
||||
self._dpcode_wrapper = definition.sensor_wrapper
|
||||
|
||||
if description.suggested_unit_of_measurement is None:
|
||||
self._attr_suggested_unit_of_measurement = (
|
||||
definition.sensor_wrapper.suggested_unit
|
||||
)
|
||||
if (
|
||||
description.device_class is None
|
||||
# For enum type DPs, we can assume it's an ENUM sensor
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user