Provide better debug capabilities for the Traccar Server integration (#113868)

This commit is contained in:
Joakim Sørensen 2024-03-20 15:40:46 +01:00 committed by GitHub
parent c5f6925948
commit 83cf59e6a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 167 additions and 11 deletions

View file

@ -99,6 +99,86 @@
'subscription_status': 'disconnected',
})
# ---
# name: test_device_diagnostics_with_disabled_entity[X-Wing]
dict({
'config_entry_options': dict({
'custom_attributes': list([
'custom_attr_1',
]),
'events': list([
'device_moving',
]),
'max_accuracy': 5.0,
'skip_accuracy_filter_for': list([
]),
}),
'coordinator_data': dict({
'0': dict({
'attributes': dict({
'custom_attr_1': 'custom_attr_1_value',
}),
'device': dict({
'attributes': dict({
}),
'category': 'starfighter',
'contact': None,
'disabled': False,
'groupId': 0,
'id': 0,
'lastUpdate': '1970-01-01T00:00:00Z',
'model': '1337',
'name': 'X-Wing',
'phone': None,
'positionId': 0,
'status': 'unknown',
'uniqueId': 'abc123',
}),
'geofence': dict({
'area': '**REDACTED**',
'attributes': dict({
}),
'calendarId': 0,
'description': "A harsh desert world orbiting twin suns in the galaxy's Outer Rim",
'id': 0,
'name': 'Tatooine',
}),
'position': dict({
'accuracy': 3.5,
'address': '**REDACTED**',
'altitude': 546841384638,
'attributes': dict({
'custom_attr_1': 'custom_attr_1_value',
}),
'course': 360,
'deviceId': 0,
'deviceTime': '1970-01-01T00:00:00Z',
'fixTime': '1970-01-01T00:00:00Z',
'geofenceIds': list([
0,
]),
'id': 0,
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'network': dict({
}),
'outdated': True,
'protocol': 'C-3PO',
'serverTime': '1970-01-01T00:00:00Z',
'speed': 4568795,
'valid': True,
}),
}),
}),
'entities': list([
dict({
'disabled': True,
'enity_id': 'device_tracker.x_wing',
'state': None,
}),
]),
'subscription_status': 'disconnected',
})
# ---
# name: test_entry_diagnostics[entry]
dict({
'config_entry_options': dict({

View file

@ -6,7 +6,7 @@ from unittest.mock import AsyncMock
from syrupy import SnapshotAssertion
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .common import setup_integration
@ -63,3 +63,42 @@ async def test_device_diagnostics(
)
assert result == snapshot(name=device.name)
async def test_device_diagnostics_with_disabled_entity(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_traccar_api_client: Generator[AsyncMock, None, None],
mock_config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test device diagnostics with disabled entity."""
await setup_integration(hass, mock_config_entry)
devices = dr.async_entries_for_config_entry(
hass.helpers.device_registry.async_get(hass),
mock_config_entry.entry_id,
)
assert len(devices) == 1
for device in dr.async_entries_for_config_entry(
hass.helpers.device_registry.async_get(hass), mock_config_entry.entry_id
):
for entry in er.async_entries_for_device(
entity_registry,
device.id,
include_disabled_entities=True,
):
entity_registry.async_update_entity(
entry.entity_id,
disabled_by=er.RegistryEntryDisabler.USER,
)
result = await get_diagnostics_for_device(
hass, hass_client, mock_config_entry, device=device
)
assert result == snapshot(name=device.name)