mirror of
https://github.com/home-assistant/core.git
synced 2025-09-04 20:31:36 +02:00
Extend UnitOfApparentPower with 'mVA' (#150422)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
@@ -88,7 +88,7 @@ class NumberDeviceClass(StrEnum):
|
|||||||
APPARENT_POWER = "apparent_power"
|
APPARENT_POWER = "apparent_power"
|
||||||
"""Apparent power.
|
"""Apparent power.
|
||||||
|
|
||||||
Unit of measurement: `VA`
|
Unit of measurement: `mVA`, `VA`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
AQI = "aqi"
|
AQI = "aqi"
|
||||||
|
@@ -42,6 +42,7 @@ from homeassistant.util import dt as dt_util
|
|||||||
from homeassistant.util.collection import chunked_or_all
|
from homeassistant.util.collection import chunked_or_all
|
||||||
from homeassistant.util.enum import try_parse_enum
|
from homeassistant.util.enum import try_parse_enum
|
||||||
from homeassistant.util.unit_conversion import (
|
from homeassistant.util.unit_conversion import (
|
||||||
|
ApparentPowerConverter,
|
||||||
AreaConverter,
|
AreaConverter,
|
||||||
BaseUnitConverter,
|
BaseUnitConverter,
|
||||||
BloodGlucoseConcentrationConverter,
|
BloodGlucoseConcentrationConverter,
|
||||||
@@ -193,6 +194,7 @@ QUERY_STATISTICS_SUMMARY_SUM = (
|
|||||||
|
|
||||||
|
|
||||||
STATISTIC_UNIT_TO_UNIT_CONVERTER: dict[str | None, type[BaseUnitConverter]] = {
|
STATISTIC_UNIT_TO_UNIT_CONVERTER: dict[str | None, type[BaseUnitConverter]] = {
|
||||||
|
**dict.fromkeys(ApparentPowerConverter.VALID_UNITS, ApparentPowerConverter),
|
||||||
**dict.fromkeys(AreaConverter.VALID_UNITS, AreaConverter),
|
**dict.fromkeys(AreaConverter.VALID_UNITS, AreaConverter),
|
||||||
**dict.fromkeys(
|
**dict.fromkeys(
|
||||||
BloodGlucoseConcentrationConverter.VALID_UNITS,
|
BloodGlucoseConcentrationConverter.VALID_UNITS,
|
||||||
|
@@ -16,6 +16,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from homeassistant.helpers.json import json_bytes
|
from homeassistant.helpers.json import json_bytes
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
from homeassistant.util.unit_conversion import (
|
from homeassistant.util.unit_conversion import (
|
||||||
|
ApparentPowerConverter,
|
||||||
AreaConverter,
|
AreaConverter,
|
||||||
BloodGlucoseConcentrationConverter,
|
BloodGlucoseConcentrationConverter,
|
||||||
ConductivityConverter,
|
ConductivityConverter,
|
||||||
@@ -59,6 +60,7 @@ UPDATE_STATISTICS_METADATA_TIME_OUT = 10
|
|||||||
|
|
||||||
UNIT_SCHEMA = vol.Schema(
|
UNIT_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
|
vol.Optional("apparent_power"): vol.In(ApparentPowerConverter.VALID_UNITS),
|
||||||
vol.Optional("area"): vol.In(AreaConverter.VALID_UNITS),
|
vol.Optional("area"): vol.In(AreaConverter.VALID_UNITS),
|
||||||
vol.Optional("blood_glucose_concentration"): vol.In(
|
vol.Optional("blood_glucose_concentration"): vol.In(
|
||||||
BloodGlucoseConcentrationConverter.VALID_UNITS
|
BloodGlucoseConcentrationConverter.VALID_UNITS
|
||||||
|
@@ -46,6 +46,7 @@ from homeassistant.const import (
|
|||||||
UnitOfVolumetricFlux,
|
UnitOfVolumetricFlux,
|
||||||
)
|
)
|
||||||
from homeassistant.util.unit_conversion import (
|
from homeassistant.util.unit_conversion import (
|
||||||
|
ApparentPowerConverter,
|
||||||
AreaConverter,
|
AreaConverter,
|
||||||
BaseUnitConverter,
|
BaseUnitConverter,
|
||||||
BloodGlucoseConcentrationConverter,
|
BloodGlucoseConcentrationConverter,
|
||||||
@@ -117,7 +118,7 @@ class SensorDeviceClass(StrEnum):
|
|||||||
APPARENT_POWER = "apparent_power"
|
APPARENT_POWER = "apparent_power"
|
||||||
"""Apparent power.
|
"""Apparent power.
|
||||||
|
|
||||||
Unit of measurement: `VA`
|
Unit of measurement: `mVA`, `VA`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
AQI = "aqi"
|
AQI = "aqi"
|
||||||
@@ -528,6 +529,7 @@ STATE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(SensorStateClass))
|
|||||||
STATE_CLASSES: Final[list[str]] = [cls.value for cls in SensorStateClass]
|
STATE_CLASSES: Final[list[str]] = [cls.value for cls in SensorStateClass]
|
||||||
|
|
||||||
UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] = {
|
UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] = {
|
||||||
|
SensorDeviceClass.APPARENT_POWER: ApparentPowerConverter,
|
||||||
SensorDeviceClass.ABSOLUTE_HUMIDITY: MassVolumeConcentrationConverter,
|
SensorDeviceClass.ABSOLUTE_HUMIDITY: MassVolumeConcentrationConverter,
|
||||||
SensorDeviceClass.AREA: AreaConverter,
|
SensorDeviceClass.AREA: AreaConverter,
|
||||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE: PressureConverter,
|
SensorDeviceClass.ATMOSPHERIC_PRESSURE: PressureConverter,
|
||||||
|
@@ -588,6 +588,7 @@ ATTR_PERSONS: Final = "persons"
|
|||||||
class UnitOfApparentPower(StrEnum):
|
class UnitOfApparentPower(StrEnum):
|
||||||
"""Apparent power units."""
|
"""Apparent power units."""
|
||||||
|
|
||||||
|
MILLIVOLT_AMPERE = "mVA"
|
||||||
VOLT_AMPERE = "VA"
|
VOLT_AMPERE = "VA"
|
||||||
|
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ from homeassistant.const import (
|
|||||||
CONCENTRATION_PARTS_PER_MILLION,
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
||||||
|
UnitOfApparentPower,
|
||||||
UnitOfArea,
|
UnitOfArea,
|
||||||
UnitOfBloodGlucoseConcentration,
|
UnitOfBloodGlucoseConcentration,
|
||||||
UnitOfConductivity,
|
UnitOfConductivity,
|
||||||
@@ -382,6 +383,20 @@ class MassConverter(BaseUnitConverter):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ApparentPowerConverter(BaseUnitConverter):
|
||||||
|
"""Utility to convert apparent power values."""
|
||||||
|
|
||||||
|
UNIT_CLASS = "apparent_power"
|
||||||
|
_UNIT_CONVERSION: dict[str | None, float] = {
|
||||||
|
UnitOfApparentPower.MILLIVOLT_AMPERE: 1 * 1000,
|
||||||
|
UnitOfApparentPower.VOLT_AMPERE: 1,
|
||||||
|
}
|
||||||
|
VALID_UNITS = {
|
||||||
|
UnitOfApparentPower.MILLIVOLT_AMPERE,
|
||||||
|
UnitOfApparentPower.VOLT_AMPERE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PowerConverter(BaseUnitConverter):
|
class PowerConverter(BaseUnitConverter):
|
||||||
"""Utility to convert power values."""
|
"""Utility to convert power values."""
|
||||||
|
|
||||||
|
@@ -2958,7 +2958,6 @@ def test_device_class_units_are_complete() -> None:
|
|||||||
def test_device_class_converters_are_complete() -> None:
|
def test_device_class_converters_are_complete() -> None:
|
||||||
"""Test that the device class converters enum is complete."""
|
"""Test that the device class converters enum is complete."""
|
||||||
no_converter_device_classes = {
|
no_converter_device_classes = {
|
||||||
SensorDeviceClass.APPARENT_POWER,
|
|
||||||
SensorDeviceClass.AQI,
|
SensorDeviceClass.AQI,
|
||||||
SensorDeviceClass.BATTERY,
|
SensorDeviceClass.BATTERY,
|
||||||
SensorDeviceClass.CO,
|
SensorDeviceClass.CO,
|
||||||
|
@@ -14,6 +14,7 @@ from homeassistant.const import (
|
|||||||
CONCENTRATION_PARTS_PER_BILLION,
|
CONCENTRATION_PARTS_PER_BILLION,
|
||||||
CONCENTRATION_PARTS_PER_MILLION,
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
|
UnitOfApparentPower,
|
||||||
UnitOfArea,
|
UnitOfArea,
|
||||||
UnitOfBloodGlucoseConcentration,
|
UnitOfBloodGlucoseConcentration,
|
||||||
UnitOfConductivity,
|
UnitOfConductivity,
|
||||||
@@ -38,6 +39,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.util import unit_conversion
|
from homeassistant.util import unit_conversion
|
||||||
from homeassistant.util.unit_conversion import (
|
from homeassistant.util.unit_conversion import (
|
||||||
|
ApparentPowerConverter,
|
||||||
AreaConverter,
|
AreaConverter,
|
||||||
BaseUnitConverter,
|
BaseUnitConverter,
|
||||||
BloodGlucoseConcentrationConverter,
|
BloodGlucoseConcentrationConverter,
|
||||||
@@ -83,6 +85,7 @@ _ALL_CONVERTERS: dict[type[BaseUnitConverter], list[str | None]] = {
|
|||||||
EnergyConverter,
|
EnergyConverter,
|
||||||
InformationConverter,
|
InformationConverter,
|
||||||
MassConverter,
|
MassConverter,
|
||||||
|
ApparentPowerConverter,
|
||||||
PowerConverter,
|
PowerConverter,
|
||||||
PressureConverter,
|
PressureConverter,
|
||||||
ReactiveEnergyConverter,
|
ReactiveEnergyConverter,
|
||||||
@@ -138,6 +141,11 @@ _GET_UNIT_RATIO: dict[type[BaseUnitConverter], tuple[str | None, str | None, flo
|
|||||||
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
|
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
|
||||||
1000,
|
1000,
|
||||||
),
|
),
|
||||||
|
ApparentPowerConverter: (
|
||||||
|
UnitOfApparentPower.MILLIVOLT_AMPERE,
|
||||||
|
UnitOfApparentPower.VOLT_AMPERE,
|
||||||
|
1000,
|
||||||
|
),
|
||||||
PowerConverter: (UnitOfPower.WATT, UnitOfPower.KILO_WATT, 1000),
|
PowerConverter: (UnitOfPower.WATT, UnitOfPower.KILO_WATT, 1000),
|
||||||
PressureConverter: (UnitOfPressure.HPA, UnitOfPressure.INHG, 33.86389),
|
PressureConverter: (UnitOfPressure.HPA, UnitOfPressure.INHG, 33.86389),
|
||||||
ReactiveEnergyConverter: (
|
ReactiveEnergyConverter: (
|
||||||
@@ -615,6 +623,14 @@ _CONVERTED_VALUE: dict[
|
|||||||
(1, UnitOfMass.STONES, 14, UnitOfMass.POUNDS),
|
(1, UnitOfMass.STONES, 14, UnitOfMass.POUNDS),
|
||||||
(1, UnitOfMass.STONES, 224, UnitOfMass.OUNCES),
|
(1, UnitOfMass.STONES, 224, UnitOfMass.OUNCES),
|
||||||
],
|
],
|
||||||
|
ApparentPowerConverter: [
|
||||||
|
(
|
||||||
|
10,
|
||||||
|
UnitOfApparentPower.MILLIVOLT_AMPERE,
|
||||||
|
0.01,
|
||||||
|
UnitOfApparentPower.VOLT_AMPERE,
|
||||||
|
),
|
||||||
|
],
|
||||||
PowerConverter: [
|
PowerConverter: [
|
||||||
(10, UnitOfPower.KILO_WATT, 10000, UnitOfPower.WATT),
|
(10, UnitOfPower.KILO_WATT, 10000, UnitOfPower.WATT),
|
||||||
(10, UnitOfPower.MEGA_WATT, 10e6, UnitOfPower.WATT),
|
(10, UnitOfPower.MEGA_WATT, 10e6, UnitOfPower.WATT),
|
||||||
|
Reference in New Issue
Block a user