Use ApparentPower unit and device class in integrations (#83577)

This commit is contained in:
epenet 2022-12-08 20:55:18 +01:00 committed by GitHub
parent f5334c5aed
commit 248d5ff541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 23 deletions

View File

@ -21,11 +21,11 @@ from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_WATT, POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_MINUTES, TIME_MINUTES,
TIME_SECONDS, TIME_SECONDS,
UnitOfApparentPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -290,8 +290,8 @@ SENSORS: dict[str, SensorEntityDescription] = {
"nomapnt": SensorEntityDescription( "nomapnt": SensorEntityDescription(
key="nomapnt", key="nomapnt",
name="UPS Nominal Apparent Power", name="UPS Nominal Apparent Power",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
icon="mdi:flash", device_class=SensorDeviceClass.APPARENT_POWER,
), ),
"numxfers": SensorEntityDescription( "numxfers": SensorEntityDescription(
key="numxfers", key="numxfers",
@ -423,7 +423,7 @@ INFERRED_UNITS = {
" Percent": PERCENTAGE, " Percent": PERCENTAGE,
" Volts": ELECTRIC_POTENTIAL_VOLT, " Volts": ELECTRIC_POTENTIAL_VOLT,
" Ampere": ELECTRIC_CURRENT_AMPERE, " Ampere": ELECTRIC_CURRENT_AMPERE,
" Volt-Ampere": POWER_VOLT_AMPERE, " Volt-Ampere": UnitOfApparentPower.VOLT_AMPERE,
" Watts": POWER_WATT, " Watts": POWER_WATT,
" Hz": FREQUENCY_HERTZ, " Hz": FREQUENCY_HERTZ,
" C": TEMP_CELSIUS, " C": TEMP_CELSIUS,

View File

@ -16,10 +16,10 @@ from homeassistant.const import (
ENERGY_WATT_HOUR, ENERGY_WATT_HOUR,
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_VOLT_AMPERE_REACTIVE, POWER_VOLT_AMPERE_REACTIVE,
POWER_WATT, POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
UnitOfApparentPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.entity import DeviceInfo, EntityCategory
@ -297,7 +297,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
SensorEntityDescription( SensorEntityDescription(
key="power_apparent_phase_1", key="power_apparent_phase_1",
name="Power apparent phase 1", name="Power apparent phase 1",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
device_class=SensorDeviceClass.APPARENT_POWER, device_class=SensorDeviceClass.APPARENT_POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
icon="mdi:flash-outline", icon="mdi:flash-outline",
@ -306,7 +306,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
SensorEntityDescription( SensorEntityDescription(
key="power_apparent_phase_2", key="power_apparent_phase_2",
name="Power apparent phase 2", name="Power apparent phase 2",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
device_class=SensorDeviceClass.APPARENT_POWER, device_class=SensorDeviceClass.APPARENT_POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
icon="mdi:flash-outline", icon="mdi:flash-outline",
@ -315,7 +315,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
SensorEntityDescription( SensorEntityDescription(
key="power_apparent_phase_3", key="power_apparent_phase_3",
name="Power apparent phase 3", name="Power apparent phase 3",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
device_class=SensorDeviceClass.APPARENT_POWER, device_class=SensorDeviceClass.APPARENT_POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
icon="mdi:flash-outline", icon="mdi:flash-outline",
@ -324,7 +324,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
SensorEntityDescription( SensorEntityDescription(
key="power_apparent", key="power_apparent",
name="Power apparent", name="Power apparent",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
device_class=SensorDeviceClass.APPARENT_POWER, device_class=SensorDeviceClass.APPARENT_POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
icon="mdi:flash-outline", icon="mdi:flash-outline",

View File

@ -20,8 +20,8 @@ from homeassistant.const import (
ENERGY_WATT_HOUR, ENERGY_WATT_HOUR,
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_WATT, POWER_WATT,
UnitOfApparentPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity, entity_registry from homeassistant.helpers import entity, entity_registry
@ -87,9 +87,9 @@ ENTITY_DESCRIPTION_KEY_MAP: dict[str, IotaWattSensorEntityDescription] = {
), ),
"VA": IotaWattSensorEntityDescription( "VA": IotaWattSensorEntityDescription(
"VA", "VA",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
icon="mdi:flash", device_class=SensorDeviceClass.APPARENT_POWER,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
"VAR": IotaWattSensorEntityDescription( "VAR": IotaWattSensorEntityDescription(

View File

@ -24,13 +24,13 @@ from homeassistant.const import (
LIGHT_LUX, LIGHT_LUX,
MASS_KILOGRAMS, MASS_KILOGRAMS,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_WATT, POWER_WATT,
SOUND_PRESSURE_DB, SOUND_PRESSURE_DB,
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
VOLUME_CUBIC_METERS, VOLUME_CUBIC_METERS,
Platform, Platform,
UnitOfApparentPower,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -182,7 +182,8 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_VA": SensorEntityDescription( "V_VA": SensorEntityDescription(
key="V_VA", key="V_VA",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
device_class=SensorDeviceClass.APPARENT_POWER,
), ),
} }

View File

@ -14,11 +14,11 @@ from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_WATT, POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_SECONDS, TIME_SECONDS,
Platform, Platform,
UnitOfApparentPower,
) )
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -182,8 +182,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.power": SensorEntityDescription( "ups.power": SensorEntityDescription(
key="ups.power", key="ups.power",
name="Current Apparent Power", name="Current Apparent Power",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
icon="mdi:flash", device_class=SensorDeviceClass.APPARENT_POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
@ -191,8 +191,8 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.power.nominal": SensorEntityDescription( "ups.power.nominal": SensorEntityDescription(
key="ups.power.nominal", key="ups.power.nominal",
name="Nominal Power", name="Nominal Power",
native_unit_of_measurement=POWER_VOLT_AMPERE, native_unit_of_measurement=UnitOfApparentPower.VOLT_AMPERE,
icon="mdi:flash", device_class=SensorDeviceClass.APPARENT_POWER,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),

View File

@ -27,7 +27,6 @@ from homeassistant.const import (
LIGHT_LUX, LIGHT_LUX,
MASS_KILOGRAMS, MASS_KILOGRAMS,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_WATT, POWER_WATT,
PRESSURE_HPA, PRESSURE_HPA,
SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS,
@ -38,6 +37,7 @@ from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
TEMP_KELVIN, TEMP_KELVIN,
UnitOfApparentPower,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -214,7 +214,7 @@ SENSOR_UNIT_MAP = {
hc.CONCENTRATION_PARTS_PER_BILLION: CONCENTRATION_PARTS_PER_BILLION, hc.CONCENTRATION_PARTS_PER_BILLION: CONCENTRATION_PARTS_PER_BILLION,
hc.CONCENTRATION_PARTS_PER_MILLION: CONCENTRATION_PARTS_PER_MILLION, hc.CONCENTRATION_PARTS_PER_MILLION: CONCENTRATION_PARTS_PER_MILLION,
hc.ELECTRICAL_CURRENT_AMPERE: ELECTRIC_CURRENT_AMPERE, hc.ELECTRICAL_CURRENT_AMPERE: ELECTRIC_CURRENT_AMPERE,
hc.ELECTRICAL_VOLT_AMPERE: POWER_VOLT_AMPERE, hc.ELECTRICAL_VOLT_AMPERE: UnitOfApparentPower.VOLT_AMPERE,
hc.ENERGY_KILO_WATT_HOUR: ENERGY_KILO_WATT_HOUR, hc.ENERGY_KILO_WATT_HOUR: ENERGY_KILO_WATT_HOUR,
hc.FREQUENCY_HERTZ: FREQUENCY_HERTZ, hc.FREQUENCY_HERTZ: FREQUENCY_HERTZ,
hc.LENGTH_CENTIMETERS: LENGTH_CENTIMETERS, hc.LENGTH_CENTIMETERS: LENGTH_CENTIMETERS,

View File

@ -24,7 +24,6 @@ from homeassistant.const import (
FREQUENCY_HERTZ, FREQUENCY_HERTZ,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_VOLT_AMPERE,
POWER_WATT, POWER_WATT,
PRESSURE_HPA, PRESSURE_HPA,
TEMP_CELSIUS, TEMP_CELSIUS,
@ -38,6 +37,7 @@ from homeassistant.const import (
VOLUME_GALLONS, VOLUME_GALLONS,
VOLUME_LITERS, VOLUME_LITERS,
Platform, Platform,
UnitOfApparentPower,
UnitOfMass, UnitOfMass,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -315,7 +315,7 @@ class ElectricalMeasurementApparentPower(
_attr_device_class: SensorDeviceClass = SensorDeviceClass.APPARENT_POWER _attr_device_class: SensorDeviceClass = SensorDeviceClass.APPARENT_POWER
_attr_should_poll = False # Poll indirectly by ElectricalMeasurementSensor _attr_should_poll = False # Poll indirectly by ElectricalMeasurementSensor
_attr_name: str = "Apparent power" _attr_name: str = "Apparent power"
_unit = POWER_VOLT_AMPERE _unit = UnitOfApparentPower.VOLT_AMPERE
_div_mul_prefix = "ac_power" _div_mul_prefix = "ac_power"