Fix flaky traccar_server tests (#116191)

pull/115239/head^2
Erik Montnemery 2024-04-25 21:20:24 +02:00 committed by GitHub
parent 8523df952e
commit 9d33965bc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 110 additions and 98 deletions

View File

@ -57,7 +57,7 @@ async def async_get_config_entry_diagnostics(
"coordinator_data": coordinator.data,
"entities": [
{
"enity_id": entity.entity_id,
"entity_id": entity.entity_id,
"disabled": entity.disabled,
"unit_of_measurement": entity.unit_of_measurement,
"state": _entity_state(hass, entity, coordinator),
@ -92,7 +92,7 @@ async def async_get_device_diagnostics(
"coordinator_data": coordinator.data,
"entities": [
{
"enity_id": entity.entity_id,
"entity_id": entity.entity_id,
"disabled": entity.disabled,
"unit_of_measurement": entity.unit_of_measurement,
"state": _entity_state(hass, entity, coordinator),

View File

@ -73,7 +73,30 @@
'entities': list([
dict({
'disabled': False,
'enity_id': 'device_tracker.x_wing',
'entity_id': 'binary_sensor.x_wing_motion',
'state': dict({
'attributes': dict({
'device_class': 'motion',
'friendly_name': 'X-Wing Motion',
}),
'state': 'off',
}),
'unit_of_measurement': None,
}),
dict({
'disabled': False,
'entity_id': 'binary_sensor.x_wing_status',
'state': dict({
'attributes': dict({
'friendly_name': 'X-Wing Status',
}),
'state': 'on',
}),
'unit_of_measurement': None,
}),
dict({
'disabled': False,
'entity_id': 'device_tracker.x_wing',
'state': dict({
'attributes': dict({
'category': 'starfighter',
@ -92,30 +115,31 @@
}),
dict({
'disabled': False,
'enity_id': 'binary_sensor.x_wing_motion',
'entity_id': 'sensor.x_wing_address',
'state': dict({
'attributes': dict({
'device_class': 'motion',
'friendly_name': 'X-Wing Motion',
'friendly_name': 'X-Wing Address',
}),
'state': 'off',
'state': '**REDACTED**',
}),
'unit_of_measurement': None,
}),
dict({
'disabled': False,
'enity_id': 'binary_sensor.x_wing_status',
'entity_id': 'sensor.x_wing_altitude',
'state': dict({
'attributes': dict({
'friendly_name': 'X-Wing Status',
'friendly_name': 'X-Wing Altitude',
'state_class': 'measurement',
'unit_of_measurement': 'm',
}),
'state': 'on',
'state': '546841384638',
}),
'unit_of_measurement': None,
'unit_of_measurement': 'm',
}),
dict({
'disabled': False,
'enity_id': 'sensor.x_wing_battery',
'entity_id': 'sensor.x_wing_battery',
'state': dict({
'attributes': dict({
'device_class': 'battery',
@ -129,7 +153,18 @@
}),
dict({
'disabled': False,
'enity_id': 'sensor.x_wing_speed',
'entity_id': 'sensor.x_wing_geofence',
'state': dict({
'attributes': dict({
'friendly_name': 'X-Wing Geofence',
}),
'state': 'Tatooine',
}),
'unit_of_measurement': None,
}),
dict({
'disabled': False,
'entity_id': 'sensor.x_wing_speed',
'state': dict({
'attributes': dict({
'device_class': 'speed',
@ -141,41 +176,6 @@
}),
'unit_of_measurement': 'kn',
}),
dict({
'disabled': False,
'enity_id': 'sensor.x_wing_altitude',
'state': dict({
'attributes': dict({
'friendly_name': 'X-Wing Altitude',
'state_class': 'measurement',
'unit_of_measurement': 'm',
}),
'state': '546841384638',
}),
'unit_of_measurement': 'm',
}),
dict({
'disabled': False,
'enity_id': 'sensor.x_wing_address',
'state': dict({
'attributes': dict({
'friendly_name': 'X-Wing Address',
}),
'state': '**REDACTED**',
}),
'unit_of_measurement': None,
}),
dict({
'disabled': False,
'enity_id': 'sensor.x_wing_geofence',
'state': dict({
'attributes': dict({
'friendly_name': 'X-Wing Geofence',
}),
'state': 'Tatooine',
}),
'unit_of_measurement': None,
}),
]),
'subscription_status': 'disconnected',
})
@ -254,51 +254,51 @@
'entities': list([
dict({
'disabled': True,
'enity_id': 'binary_sensor.x_wing_motion',
'entity_id': 'binary_sensor.x_wing_motion',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'binary_sensor.x_wing_status',
'entity_id': 'binary_sensor.x_wing_status',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_battery',
'entity_id': 'device_tracker.x_wing',
'state': None,
'unit_of_measurement': '%',
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_speed',
'entity_id': 'sensor.x_wing_address',
'state': None,
'unit_of_measurement': 'kn',
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_altitude',
'entity_id': 'sensor.x_wing_altitude',
'state': None,
'unit_of_measurement': 'm',
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_address',
'entity_id': 'sensor.x_wing_battery',
'state': None,
'unit_of_measurement': '%',
}),
dict({
'disabled': True,
'entity_id': 'sensor.x_wing_geofence',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_geofence',
'entity_id': 'sensor.x_wing_speed',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'device_tracker.x_wing',
'state': None,
'unit_of_measurement': None,
'unit_of_measurement': 'kn',
}),
]),
'subscription_status': 'disconnected',
@ -378,49 +378,19 @@
'entities': list([
dict({
'disabled': True,
'enity_id': 'binary_sensor.x_wing_motion',
'entity_id': 'binary_sensor.x_wing_motion',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'binary_sensor.x_wing_status',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_battery',
'state': None,
'unit_of_measurement': '%',
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_speed',
'state': None,
'unit_of_measurement': 'kn',
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_altitude',
'state': None,
'unit_of_measurement': 'm',
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_address',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'enity_id': 'sensor.x_wing_geofence',
'entity_id': 'binary_sensor.x_wing_status',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': False,
'enity_id': 'device_tracker.x_wing',
'entity_id': 'device_tracker.x_wing',
'state': dict({
'attributes': dict({
'category': 'starfighter',
@ -437,6 +407,36 @@
}),
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'entity_id': 'sensor.x_wing_address',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'entity_id': 'sensor.x_wing_altitude',
'state': None,
'unit_of_measurement': 'm',
}),
dict({
'disabled': True,
'entity_id': 'sensor.x_wing_battery',
'state': None,
'unit_of_measurement': '%',
}),
dict({
'disabled': True,
'entity_id': 'sensor.x_wing_geofence',
'state': None,
'unit_of_measurement': None,
}),
dict({
'disabled': True,
'entity_id': 'sensor.x_wing_speed',
'state': None,
'unit_of_measurement': 'kn',
}),
]),
'subscription_status': 'disconnected',
})

View File

@ -33,6 +33,10 @@ async def test_entry_diagnostics(
hass_client,
mock_config_entry,
)
# Sort the list of entities
result["entities"] = sorted(
result["entities"], key=lambda entity: entity["entity_id"]
)
assert result == snapshot(name="entry")
@ -64,13 +68,17 @@ async def test_device_diagnostics(
device_id=device.id,
include_disabled_entities=True,
)
# Enable all entitits to show everything in snapshots
# Enable all entities to show everything in snapshots
for entity in entities:
entity_registry.async_update_entity(entity.entity_id, disabled_by=None)
result = await get_diagnostics_for_device(
hass, hass_client, mock_config_entry, device=device
)
# Sort the list of entities
result["entities"] = sorted(
result["entities"], key=lambda entity: entity["entity_id"]
)
assert result == snapshot(name=device.name)
@ -110,5 +118,9 @@ async def test_device_diagnostics_with_disabled_entity(
result = await get_diagnostics_for_device(
hass, hass_client, mock_config_entry, device=device
)
# Sort the list of entities
result["entities"] = sorted(
result["entities"], key=lambda entity: entity["entity_id"]
)
assert result == snapshot(name=device.name)