Add support for "days" unit for STESTI sensor in APCUPSD integration (#93844)

Add a test case for self test interval
This commit is contained in:
Yuxin Wang 2023-05-31 08:25:46 -04:00 committed by GitHub
parent 21771457d1
commit 676b6ab706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -377,7 +377,6 @@ SENSORS: dict[str, SensorEntityDescription] = {
key="stesti",
name="UPS Self Test Interval",
icon="mdi:information-outline",
state_class=SensorStateClass.TOTAL_INCREASING,
),
"timeleft": SensorEntityDescription(
key="timeleft",
@ -440,6 +439,9 @@ INFERRED_UNITS = {
# "34.6 C Internal". Here we create a fake unit " C Internal" to handle this case.
" C Internal": UnitOfTemperature.CELSIUS,
" Percent Load Capacity": PERCENTAGE,
# "stesti" field (Self Test Interval) field could report a "days" unit, e.g.,
# "7 days", so here we add support for it.
" days": UnitOfTime.DAYS,
}

View File

@ -43,6 +43,7 @@ MOCK_STATUS: Final = OrderedDict(
("XOFFBATT", "1970-01-01 00:00:00 0000"),
("LASTSTEST", "1970-01-01 00:00:00 0000"),
("SELFTEST", "NO"),
("STESTI", "7 days"),
("STATFLAG", "0x05000008"),
("SERIALNO", "XXXXXXXXXXXX"),
("BATTDATE", "1970-01-01"),

View File

@ -11,6 +11,7 @@ from homeassistant.const import (
PERCENTAGE,
UnitOfElectricPotential,
UnitOfPower,
UnitOfTime,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
@ -56,6 +57,15 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_battv"
# test a representative time sensor.
state = hass.states.get("sensor.ups_self_test_interval")
assert state
assert state.state == "7"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTime.DAYS
entry = registry.async_get("sensor.ups_self_test_interval")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_stesti"
# Test a representative percentage sensor.
state = hass.states.get("sensor.ups_load")
assert state