Add unit inference for Amps and VA in APCUPSD integration (#94431)
* Add unit inference for Amps and VA * Rename `init_integration` to `async_init_integration` for better consistency with HA naming style
This commit is contained in:
parent
47995fc274
commit
b1bdd92383
5 changed files with 18 additions and 14 deletions
|
@ -430,7 +430,9 @@ INFERRED_UNITS = {
|
|||
" Percent": PERCENTAGE,
|
||||
" Volts": UnitOfElectricPotential.VOLT,
|
||||
" Ampere": UnitOfElectricCurrent.AMPERE,
|
||||
" Amps": UnitOfElectricCurrent.AMPERE,
|
||||
" Volt-Ampere": UnitOfApparentPower.VOLT_AMPERE,
|
||||
" VA": UnitOfApparentPower.VOLT_AMPERE,
|
||||
" Watts": UnitOfPower.WATT,
|
||||
" Hz": UnitOfFrequency.HERTZ,
|
||||
" C": UnitOfTemperature.CELSIUS,
|
||||
|
|
|
@ -26,6 +26,7 @@ MOCK_STATUS: Final = OrderedDict(
|
|||
("LOADPCT", "14.0 Percent"),
|
||||
("BCHARGE", "100.0 Percent"),
|
||||
("TIMELEFT", "51.0 Minutes"),
|
||||
("NOMAPNT", "60.0 VA"),
|
||||
("ITEMP", "34.6 C Internal"),
|
||||
("MBATTCHG", "5 Percent"),
|
||||
("MINTIMEL", "3 Minutes"),
|
||||
|
@ -35,6 +36,7 @@ MOCK_STATUS: Final = OrderedDict(
|
|||
("HITRANS", "139.0 Volts"),
|
||||
("ALARMDEL", "30 Seconds"),
|
||||
("BATTV", "13.7 Volts"),
|
||||
("OUTCURNT", "0.88 Amps"),
|
||||
("LASTXFER", "Automatic or explicit self test"),
|
||||
("NUMXFERS", "1"),
|
||||
("XONBATT", "1970-01-01 00:00:00 0000"),
|
||||
|
@ -74,7 +76,7 @@ MOCK_MINIMAL_STATUS: Final = OrderedDict(
|
|||
)
|
||||
|
||||
|
||||
async def init_integration(
|
||||
async def async_init_integration(
|
||||
hass: HomeAssistant, host: str = "test", status=None
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the APC UPS Daemon integration in HomeAssistant."""
|
||||
|
@ -95,7 +97,7 @@ async def init_integration(
|
|||
with patch("apcaccess.status.parse", return_value=status), patch(
|
||||
"apcaccess.status.get", return_value=b""
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return entry
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import MOCK_STATUS, init_integration
|
||||
from . import MOCK_STATUS, async_init_integration
|
||||
|
||||
|
||||
async def test_binary_sensor(hass: HomeAssistant) -> None:
|
||||
"""Test states of binary sensor."""
|
||||
await init_integration(hass, status=MOCK_STATUS)
|
||||
await async_init_integration(hass, status=MOCK_STATUS)
|
||||
registry = er.async_get(hass)
|
||||
|
||||
state = hass.states.get("binary_sensor.ups_online_status")
|
||||
|
@ -22,7 +22,7 @@ async def test_no_binary_sensor(hass: HomeAssistant) -> None:
|
|||
"""Test binary sensor when STATFLAG is not available."""
|
||||
status = MOCK_STATUS.copy()
|
||||
status.pop("STATFLAG")
|
||||
await init_integration(hass, status=status)
|
||||
await async_init_integration(hass, status=status)
|
||||
|
||||
state = hass.states.get("binary_sensor.ups_online_status")
|
||||
assert state is None
|
||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.config_entries import SOURCE_USER, ConfigEntryState
|
|||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import CONF_DATA, MOCK_MINIMAL_STATUS, MOCK_STATUS, init_integration
|
||||
from . import CONF_DATA, MOCK_MINIMAL_STATUS, MOCK_STATUS, async_init_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -19,7 +19,7 @@ async def test_async_setup_entry(hass: HomeAssistant, status: OrderedDict) -> No
|
|||
"""Test a successful setup entry."""
|
||||
# Minimal status does not contain "SERIALNO" field, which is used to determine the
|
||||
# unique ID of this integration. But, the integration should work fine without it.
|
||||
await init_integration(hass, status=status)
|
||||
await async_init_integration(hass, status=status)
|
||||
|
||||
# Verify successful setup by querying the status sensor.
|
||||
state = hass.states.get("binary_sensor.ups_online_status")
|
||||
|
@ -34,8 +34,8 @@ async def test_multiple_integrations(hass: HomeAssistant) -> None:
|
|||
status1 = MOCK_STATUS | {"LOADPCT": "15.0 Percent", "SERIALNO": "XXXXX1"}
|
||||
status2 = MOCK_STATUS | {"LOADPCT": "16.0 Percent", "SERIALNO": "XXXXX2"}
|
||||
entries = (
|
||||
await init_integration(hass, host="test1", status=status1),
|
||||
await init_integration(hass, host="test2", status=status2),
|
||||
await async_init_integration(hass, host="test1", status=status1),
|
||||
await async_init_integration(hass, host="test2", status=status2),
|
||||
)
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 2
|
||||
|
@ -70,8 +70,8 @@ async def test_unload_remove(hass: HomeAssistant) -> None:
|
|||
"""Test successful unload of entry."""
|
||||
# Load two integrations from two mock hosts.
|
||||
entries = (
|
||||
await init_integration(hass, host="test1", status=MOCK_STATUS),
|
||||
await init_integration(hass, host="test2", status=MOCK_MINIMAL_STATUS),
|
||||
await async_init_integration(hass, host="test1", status=MOCK_STATUS),
|
||||
await async_init_integration(hass, host="test2", status=MOCK_MINIMAL_STATUS),
|
||||
)
|
||||
|
||||
# Assert they are loaded.
|
||||
|
|
|
@ -16,12 +16,12 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import MOCK_STATUS, init_integration
|
||||
from . import MOCK_STATUS, async_init_integration
|
||||
|
||||
|
||||
async def test_sensor(hass: HomeAssistant) -> None:
|
||||
"""Test states of sensor."""
|
||||
await init_integration(hass, status=MOCK_STATUS)
|
||||
await async_init_integration(hass, status=MOCK_STATUS)
|
||||
registry = er.async_get(hass)
|
||||
|
||||
# Test a representative string sensor.
|
||||
|
@ -89,7 +89,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_sensor_disabled(hass: HomeAssistant) -> None:
|
||||
"""Test sensor disabled by default."""
|
||||
await init_integration(hass)
|
||||
await async_init_integration(hass)
|
||||
registry = er.async_get(hass)
|
||||
|
||||
# Test a representative integration-disabled sensor.
|
||||
|
|
Loading…
Add table
Reference in a new issue