From 676b6ab7062bfb8e0ecf8efb6bfeff8e8fef2e78 Mon Sep 17 00:00:00 2001 From: Yuxin Wang Date: Wed, 31 May 2023 08:25:46 -0400 Subject: [PATCH] Add support for "days" unit for STESTI sensor in APCUPSD integration (#93844) Add a test case for self test interval --- homeassistant/components/apcupsd/sensor.py | 4 +++- tests/components/apcupsd/__init__.py | 1 + tests/components/apcupsd/test_sensor.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 77d8933827d..17168700f66 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -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, } diff --git a/tests/components/apcupsd/__init__.py b/tests/components/apcupsd/__init__.py index 7b58013ddbe..f99b29c7bb7 100644 --- a/tests/components/apcupsd/__init__.py +++ b/tests/components/apcupsd/__init__.py @@ -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"), diff --git a/tests/components/apcupsd/test_sensor.py b/tests/components/apcupsd/test_sensor.py index 3cc2f0a5620..a9f6820faa0 100644 --- a/tests/components/apcupsd/test_sensor.py +++ b/tests/components/apcupsd/test_sensor.py @@ -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