Skip to content

Commit

Permalink
Change POWER_VOLT_AMPERE_REACTIVE to UnitOfReactivePower (home-assist…
Browse files Browse the repository at this point in the history
…ant#117153)

* Refactoring: exchange POWER_VOLT_AMPERE_REACTIVE with UnitOfReactivePower

* updated iotawatt and mysensors from VOLT_AMPERE_REACTIVE to UnitOfReactivePower.VOLT_AMPERE_REACTIVE

* deprecation period for POWER_VOLT_AMPERE_REACTIVE changed to one year.

* POWER_VOLT_AMPERE_REACTIVE changed to UnitOfReactivePower in blebox integration

* Update homeassistant/const.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
  • Loading branch information
NECH2004 and emontnemery authored Aug 21, 2024
1 parent b21b300 commit 3e53cc1
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 56 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/blebox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
LIGHT_LUX,
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
UnitOfApparentPower,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfReactivePower,
UnitOfSpeed,
UnitOfTemperature,
)
Expand Down Expand Up @@ -85,7 +85,7 @@
SensorEntityDescription(
key="reactivePower",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
),
SensorEntityDescription(
key="activePower",
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/fronius/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
)
from homeassistant.const import (
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
EntityCategory,
UnitOfApparentPower,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfReactivePower,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -381,28 +381,28 @@ class FroniusSensorEntityDescription(SensorEntityDescription):
),
FroniusSensorEntityDescription(
key="power_reactive_phase_1",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
FroniusSensorEntityDescription(
key="power_reactive_phase_2",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
FroniusSensorEntityDescription(
key="power_reactive_phase_3",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
FroniusSensorEntityDescription(
key="power_reactive",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
EntityCategory,
UnitOfApparentPower,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfReactivePower,
UnitOfTemperature,
UnitOfTime,
)
Expand Down Expand Up @@ -126,7 +126,7 @@ class GoodweSensorEntityDescription(SensorEntityDescription):
key="var",
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
entity_registry_enabled_default=False,
),
"C": GoodweSensorEntityDescription(
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/homewizard/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from homeassistant.const import (
ATTR_VIA_DEVICE,
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
EntityCategory,
Platform,
UnitOfApparentPower,
Expand All @@ -27,6 +26,7 @@
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfReactivePower,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -404,7 +404,7 @@ def to_percentage(value: float | None) -> float | None:
),
HomeWizardSensorEntityDescription(
key="active_reactive_power_var",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
Expand All @@ -415,7 +415,7 @@ def to_percentage(value: float | None) -> float | None:
key="active_reactive_power_l1_var",
translation_key="active_reactive_power_phase_var",
translation_placeholders={"phase": "1"},
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
Expand All @@ -426,7 +426,7 @@ def to_percentage(value: float | None) -> float | None:
key="active_reactive_power_l2_var",
translation_key="active_reactive_power_phase_var",
translation_placeholders={"phase": "2"},
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
Expand All @@ -437,7 +437,7 @@ def to_percentage(value: float | None) -> float | None:
key="active_reactive_power_l3_var",
translation_key="active_reactive_power_phase_var",
translation_placeholders={"phase": "3"},
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
device_class=SensorDeviceClass.REACTIVE_POWER,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/iotawatt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import httpx

DOMAIN = "iotawatt"
VOLT_AMPERE_REACTIVE = "VAR"
VOLT_AMPERE_REACTIVE_HOURS = "VARh"

CONNECTION_ERRORS = (KeyError, json.JSONDecodeError, httpx.HTTPError)
5 changes: 3 additions & 2 deletions homeassistant/components/iotawatt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfReactivePower,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er
Expand All @@ -31,7 +32,7 @@
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt as dt_util

from .const import DOMAIN, VOLT_AMPERE_REACTIVE, VOLT_AMPERE_REACTIVE_HOURS
from .const import DOMAIN, VOLT_AMPERE_REACTIVE_HOURS
from .coordinator import IotawattUpdater

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -89,7 +90,7 @@ class IotaWattSensorEntityDescription(SensorEntityDescription):
),
"VAR": IotaWattSensorEntityDescription(
key="VAR",
native_unit_of_measurement=VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:flash",
entity_registry_enabled_default=False,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/isy994/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
DEGREE,
LIGHT_LUX,
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
REVOLUTIONS_PER_MINUTE,
SERVICE_LOCK,
SERVICE_UNLOCK,
Expand All @@ -50,6 +49,7 @@
UnitOfMass,
UnitOfPower,
UnitOfPressure,
UnitOfReactivePower,
UnitOfSoundPressure,
UnitOfSpeed,
UnitOfTemperature,
Expand Down Expand Up @@ -438,7 +438,7 @@
"133": UnitOfFrequency.KILOHERTZ,
"134": f"{UnitOfLength.METERS}/{UnitOfTime.SECONDS}²",
"135": UnitOfApparentPower.VOLT_AMPERE, # Volt-Amp
"136": POWER_VOLT_AMPERE_REACTIVE, # VAR = Volt-Amp Reactive
"136": UnitOfReactivePower.VOLT_AMPERE_REACTIVE, # VAR = Volt-Amp Reactive
"137": "", # NTP DateTime - Number of seconds since 1900
"138": UnitOfPressure.PSI,
"139": DEGREE, # Degree 0-360
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/mysensors/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
UnitOfLength,
UnitOfMass,
UnitOfPower,
UnitOfReactivePower,
UnitOfSoundPressure,
UnitOfTemperature,
UnitOfVolume,
Expand Down Expand Up @@ -195,7 +196,7 @@
),
"V_VAR": SensorEntityDescription(
key="V_VAR",
native_unit_of_measurement="var",
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
),
"V_VA": SensorEntityDescription(
key="V_VA",
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/number/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
CONCENTRATION_PARTS_PER_MILLION,
LIGHT_LUX,
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfApparentPower,
Expand All @@ -31,6 +30,7 @@
UnitOfPower,
UnitOfPrecipitationDepth,
UnitOfPressure,
UnitOfReactivePower,
UnitOfSoundPressure,
UnitOfSpeed,
UnitOfTemperature,
Expand Down Expand Up @@ -468,7 +468,7 @@ class NumberDeviceClass(StrEnum):
NumberDeviceClass.PRECIPITATION: set(UnitOfPrecipitationDepth),
NumberDeviceClass.PRECIPITATION_INTENSITY: set(UnitOfVolumetricFlux),
NumberDeviceClass.PRESSURE: set(UnitOfPressure),
NumberDeviceClass.REACTIVE_POWER: {POWER_VOLT_AMPERE_REACTIVE},
NumberDeviceClass.REACTIVE_POWER: {UnitOfReactivePower.VOLT_AMPERE_REACTIVE},
NumberDeviceClass.SIGNAL_STRENGTH: {
SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/sensor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
CONCENTRATION_PARTS_PER_MILLION,
LIGHT_LUX,
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfApparentPower,
Expand All @@ -31,6 +30,7 @@
UnitOfPower,
UnitOfPrecipitationDepth,
UnitOfPressure,
UnitOfReactivePower,
UnitOfSoundPressure,
UnitOfSpeed,
UnitOfTemperature,
Expand Down Expand Up @@ -563,7 +563,7 @@ class SensorStateClass(StrEnum):
SensorDeviceClass.PRECIPITATION: set(UnitOfPrecipitationDepth),
SensorDeviceClass.PRECIPITATION_INTENSITY: set(UnitOfVolumetricFlux),
SensorDeviceClass.PRESSURE: set(UnitOfPressure),
SensorDeviceClass.REACTIVE_POWER: {POWER_VOLT_AMPERE_REACTIVE},
SensorDeviceClass.REACTIVE_POWER: {UnitOfReactivePower.VOLT_AMPERE_REACTIVE},
SensorDeviceClass.SIGNAL_STRENGTH: {
SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/sma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
EntityCategory,
UnitOfApparentPower,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfFrequency,
UnitOfPower,
UnitOfReactivePower,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -204,31 +204,31 @@
"grid_reactive_power": SensorEntityDescription(
key="grid_reactive_power",
name="Grid Reactive Power",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.REACTIVE_POWER,
entity_registry_enabled_default=False,
),
"grid_reactive_power_l1": SensorEntityDescription(
key="grid_reactive_power_l1",
name="Grid Reactive Power L1",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.REACTIVE_POWER,
entity_registry_enabled_default=False,
),
"grid_reactive_power_l2": SensorEntityDescription(
key="grid_reactive_power_l2",
name="Grid Reactive Power L2",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.REACTIVE_POWER,
entity_registry_enabled_default=False,
),
"grid_reactive_power_l3": SensorEntityDescription(
key="grid_reactive_power_l3",
name="Grid Reactive Power L3",
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
native_unit_of_measurement=UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.REACTIVE_POWER,
entity_registry_enabled_default=False,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/tasmota/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
CONCENTRATION_PARTS_PER_MILLION,
LIGHT_LUX,
PERCENTAGE,
POWER_VOLT_AMPERE_REACTIVE,
SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
EntityCategory,
Expand All @@ -35,6 +34,7 @@
UnitOfMass,
UnitOfPower,
UnitOfPressure,
UnitOfReactivePower,
UnitOfSpeed,
UnitOfTemperature,
)
Expand Down Expand Up @@ -227,7 +227,7 @@
hc.PERCENTAGE: PERCENTAGE,
hc.POWER_WATT: UnitOfPower.WATT,
hc.PRESSURE_HPA: UnitOfPressure.HPA,
hc.REACTIVE_POWER: POWER_VOLT_AMPERE_REACTIVE,
hc.REACTIVE_POWER: UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
hc.SIGNAL_STRENGTH_DECIBELS: SIGNAL_STRENGTH_DECIBELS,
hc.SIGNAL_STRENGTH_DECIBELS_MILLIWATT: SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
hc.SPEED_KILOMETERS_PER_HOUR: UnitOfSpeed.KILOMETERS_PER_HOUR,
Expand Down
13 changes: 12 additions & 1 deletion homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,19 @@ class UnitOfPower(StrEnum):
)
"""Deprecated: please use UnitOfPower.BTU_PER_HOUR."""


# Reactive power units
POWER_VOLT_AMPERE_REACTIVE: Final = "var"
class UnitOfReactivePower(StrEnum):
"""Reactive power units."""

VOLT_AMPERE_REACTIVE = "var"


_DEPRECATED_POWER_VOLT_AMPERE_REACTIVE: Final = DeprecatedConstantEnum(
UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
"2025.9",
)
"""Deprecated: please use UnitOfReactivePower.VOLT_AMPERE_REACTIVE."""


# Energy units
Expand Down
Loading

0 comments on commit 3e53cc1

Please sign in to comment.