Add mA to SensorDeviceClass.CURRENT units (#84492)

fixes undefined
This commit is contained in:
SukramJ 2022-12-30 13:55:14 +01:00 committed by GitHub
parent df2d0cd3e3
commit 005bc8994d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import pytest
from homeassistant.const import (
UnitOfDataRate,
UnitOfElectricCurrent,
UnitOfEnergy,
UnitOfInformation,
UnitOfLength,
@ -19,6 +20,7 @@ from homeassistant.util.unit_conversion import (
BaseUnitConverter,
DataRateConverter,
DistanceConverter,
ElectricCurrentConverter,
EnergyConverter,
InformationConverter,
MassConverter,
@ -44,6 +46,8 @@ INVALID_SYMBOL = "bob"
(DistanceConverter, UnitOfLength.YARDS),
(DistanceConverter, UnitOfLength.FEET),
(DistanceConverter, UnitOfLength.INCHES),
(ElectricCurrentConverter, UnitOfElectricCurrent.AMPERE),
(ElectricCurrentConverter, UnitOfElectricCurrent.MILLIAMPERE),
(EnergyConverter, UnitOfEnergy.WATT_HOUR),
(EnergyConverter, UnitOfEnergy.KILO_WATT_HOUR),
(EnergyConverter, UnitOfEnergy.MEGA_WATT_HOUR),
@ -93,6 +97,7 @@ def test_convert_same_unit(converter: type[BaseUnitConverter], valid_unit: str)
[
(DataRateConverter, UnitOfDataRate.GIBIBYTES_PER_SECOND),
(DistanceConverter, UnitOfLength.KILOMETERS),
(ElectricCurrentConverter, UnitOfElectricCurrent.AMPERE),
(EnergyConverter, UnitOfEnergy.KILO_WATT_HOUR),
(InformationConverter, UnitOfInformation.GIBIBYTES),
(MassConverter, UnitOfMass.GRAMS),
@ -157,6 +162,12 @@ def test_convert_nonnumeric_value(
8,
),
(DistanceConverter, UnitOfLength.KILOMETERS, UnitOfLength.METERS, 1 / 1000),
(
ElectricCurrentConverter,
UnitOfElectricCurrent.AMPERE,
UnitOfElectricCurrent.MILLIAMPERE,
1 / 1000,
),
(EnergyConverter, UnitOfEnergy.WATT_HOUR, UnitOfEnergy.KILO_WATT_HOUR, 1000),
(InformationConverter, UnitOfInformation.BITS, UnitOfInformation.BYTES, 8),
(PowerConverter, UnitOfPower.WATT, UnitOfPower.KILO_WATT, 1000),
@ -235,6 +246,23 @@ def test_data_rate_convert(
)
@pytest.mark.parametrize(
"value,from_unit,expected,to_unit",
[
(5, UnitOfElectricCurrent.AMPERE, 5000, UnitOfElectricCurrent.MILLIAMPERE),
(5, UnitOfElectricCurrent.MILLIAMPERE, 0.005, UnitOfElectricCurrent.AMPERE),
],
)
def test_electric_current_convert(
value: float,
from_unit: str,
expected: float,
to_unit: str,
) -> None:
"""Test conversion to other units."""
assert ElectricCurrentConverter.convert(value, from_unit, to_unit) == expected
@pytest.mark.parametrize(
"value,from_unit,expected,to_unit",
[