1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Sort the resources for deterministic sensor addition order in APCUPSD (#152467)

This commit is contained in:
Yuxin Wang
2025-09-17 04:41:19 -04:00
committed by GitHub
parent b10a9721a7
commit a494d3ec69
4 changed files with 56 additions and 3 deletions

View File

@@ -467,7 +467,10 @@ async def async_setup_entry(
# 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.
for resource in available_resources | {LAST_S_TEST}:
#
# We also sort the resources to ensure the order of entities created is deterministic since
# "APCMODEL" and "MODEL" resources map to the same "Model" name.
for resource in sorted(available_resources | {LAST_S_TEST}):
if resource not in SENSORS:
_LOGGER.warning("Invalid resource from APCUPSd: %s", resource.upper())
continue

View File

@@ -16,6 +16,7 @@ MOCK_STATUS: Final = {
"DRIVER": "USB UPS Driver",
"UPSMODE": "Stand Alone",
"UPSNAME": "MyUPS",
"APCMODEL": "Back-UPS ES 600",
"MODEL": "Back-UPS ES 600",
"STATUS": "ONLINE",
"LINEV": "124.0 Volts",

View File

@@ -3,6 +3,7 @@
dict({
'ALARMDEL': '30 Seconds',
'APC': '001,038,0985',
'APCMODEL': 'Back-UPS ES 600',
'BATTDATE': '1970-01-01',
'BATTV': '13.7 Volts',
'BCHARGE': '100.0 Percent',

View File

@@ -934,8 +934,8 @@
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'model',
'unique_id': 'XXXXXXXXXXXX_model',
'translation_key': 'apc_model',
'unique_id': 'XXXXXXXXXXXX_apcmodel',
'unit_of_measurement': None,
})
# ---
@@ -952,6 +952,54 @@
'state': 'Back-UPS ES 600',
})
# ---
# name: test_sensor[sensor.myups_model_2-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.myups_model_2',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Model',
'platform': 'apcupsd',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'model',
'unique_id': 'XXXXXXXXXXXX_model',
'unit_of_measurement': None,
})
# ---
# name: test_sensor[sensor.myups_model_2-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'MyUPS Model',
}),
'context': <ANY>,
'entity_id': 'sensor.myups_model_2',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'Back-UPS ES 600',
})
# ---
# name: test_sensor[sensor.myups_name-entry]
EntityRegistryEntrySnapshot({
'aliases': set({