diff --git a/homeassistant/components/smartthings/diagnostics.py b/homeassistant/components/smartthings/diagnostics.py index bcf40645d22..fc34415e419 100644 --- a/homeassistant/components/smartthings/diagnostics.py +++ b/homeassistant/components/smartthings/diagnostics.py @@ -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] = {} diff --git a/tests/components/smartthings/test_diagnostics.py b/tests/components/smartthings/test_diagnostics.py index 22f1c77cdd1..768be155c86 100644 --- a/tests/components/smartthings/test_diagnostics.py +++ b/tests/components/smartthings/test_diagnostics.py @@ -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" + )