Fix SmartThings diagnostics (#139447)

pull/139454/head
Joost Lekkerkerker 2025-02-27 18:39:18 +01:00 committed by GitHub
parent 9502dbee56
commit ffac522554
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -21,25 +21,24 @@ async def async_get_device_diagnostics(
hass: HomeAssistant, entry: SmartThingsConfigEntry, device: DeviceEntry
) -> dict[str, Any]:
"""Return diagnostics for a device entry."""
client = entry.runtime_data.client
device_id = next(
identifier for identifier in device.identifiers if identifier[0] == DOMAIN
)[0]
)[1]
device_status = await client.get_device_status(device_id)
events: list[DeviceEvent] = []
def register_event(event: DeviceEvent) -> None:
events.append(event)
client = entry.runtime_data.client
listener = client.add_device_event_listener(device_id, register_event)
await asyncio.sleep(EVENT_WAIT_TIME)
listener()
device_status = await client.get_device_status(device_id)
status: dict[str, Any] = {}
for component, capabilities in device_status.items():
status[component] = {}

View File

@ -34,6 +34,8 @@ async def test_device(
identifiers={(DOMAIN, "96a5ef74-5832-a84b-f1f7-ca799957065d")}
)
mock_smartthings.get_device_status.reset_mock()
with patch("homeassistant.components.smartthings.diagnostics.EVENT_WAIT_TIME", 0.1):
diag = await get_diagnostics_for_device(
hass, hass_client, mock_config_entry, device
@ -42,3 +44,6 @@ async def test_device(
assert diag == snapshot(
exclude=props("last_changed", "last_reported", "last_updated")
)
mock_smartthings.get_device_status.assert_called_once_with(
"96a5ef74-5832-a84b-f1f7-ca799957065d"
)