Fix SmartThings diagnostics (#139447)
parent
9502dbee56
commit
ffac522554
|
@ -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] = {}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue