Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/apcupsd/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@
key="stesti",
name="UPS Self Test Interval",
icon="mdi:information-outline",
state_class=SensorStateClass.TOTAL_INCREASING,
),
"timeleft": SensorEntityDescription(
key="timeleft",
Expand Down Expand Up @@ -440,6 +439,9 @@
# "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,
}


Expand Down
1 change: 1 addition & 0 deletions tests/components/apcupsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
("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"),
Expand Down
10 changes: 10 additions & 0 deletions tests/components/apcupsd/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
PERCENTAGE,
UnitOfElectricPotential,
UnitOfPower,
UnitOfTime,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
Expand Down Expand Up @@ -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
Expand Down