mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Always create the APC UPS Daemon battery transfer sensors (#184559)
This commit is contained in:
@@ -47,6 +47,11 @@ IGNORED_SENSORS: Final = {
|
||||
"serialno",
|
||||
}
|
||||
|
||||
# Sensors that only appear after an event since the last daemon restart: a self
|
||||
# test for "laststest", a transfer to or from the battery for "xonbatt" and
|
||||
# "xoffbatt". They are always added, and stay unknown until the event happens.
|
||||
EVENT_SENSORS: Final = {LAST_S_TEST, "xoffbatt", "xonbatt"}
|
||||
|
||||
SENSORS: dict[str, SensorEntityDescription] = {
|
||||
"alarmdel": SensorEntityDescription(
|
||||
key="alarmdel",
|
||||
@@ -430,16 +435,9 @@ async def async_setup_entry(
|
||||
|
||||
entities = []
|
||||
|
||||
# "laststest" is a special sensor that only appears when
|
||||
# the APC UPS daemon has done a periodical (or manual) self
|
||||
# test since last daemon restart. It might not be available
|
||||
# when we set up the integration, and we do not know if it
|
||||
# would ever be available. Here we add it anyway and mark it
|
||||
# as unknown initially.
|
||||
#
|
||||
# We also sort the resources to ensure the order of entities
|
||||
# created is deterministic
|
||||
for resource in sorted(available_resources | {LAST_S_TEST}):
|
||||
# We sort the resources to ensure the order of entities created is
|
||||
# deterministic
|
||||
for resource in sorted(available_resources | EVENT_SENSORS):
|
||||
if resource in IGNORED_SENSORS:
|
||||
continue
|
||||
if resource not in SENSORS:
|
||||
|
||||
@@ -147,6 +147,20 @@ async def test_manual_update_entity(
|
||||
MOCK_MINIMAL_STATUS | {"LASTSTEST": "1970-01-01 00:00:00 +0000"},
|
||||
id="last_self_test_missing",
|
||||
),
|
||||
pytest.param(
|
||||
# The transfer fields only appear after a transfer to or from the
|
||||
# battery since the daemon started.
|
||||
MOCK_MINIMAL_STATUS,
|
||||
"sensor.apc_ups_transfer_to_battery",
|
||||
MOCK_MINIMAL_STATUS | {"XONBATT": "1970-01-01 00:00:00 +0000"},
|
||||
id="xonbatt_missing",
|
||||
),
|
||||
pytest.param(
|
||||
MOCK_MINIMAL_STATUS,
|
||||
"sensor.apc_ups_transfer_from_battery",
|
||||
MOCK_MINIMAL_STATUS | {"XOFFBATT": "1970-01-01 00:00:00 +0000"},
|
||||
id="xoffbatt_missing",
|
||||
),
|
||||
pytest.param(
|
||||
MOCK_MINIMAL_STATUS | {"XOFFBATT": "N/A"},
|
||||
"sensor.apc_ups_transfer_from_battery",
|
||||
|
||||
Reference in New Issue
Block a user