mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Fix SmartThings diagnostics (#139447)
This commit is contained in:
parent
d8a259044f
commit
df4e5a54e3
@ -21,25 +21,24 @@ async def async_get_device_diagnostics(
|
|||||||
hass: HomeAssistant, entry: SmartThingsConfigEntry, device: DeviceEntry
|
hass: HomeAssistant, entry: SmartThingsConfigEntry, device: DeviceEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a device entry."""
|
"""Return diagnostics for a device entry."""
|
||||||
|
client = entry.runtime_data.client
|
||||||
device_id = next(
|
device_id = next(
|
||||||
identifier for identifier in device.identifiers if identifier[0] == DOMAIN
|
identifier for identifier in device.identifiers if identifier[0] == DOMAIN
|
||||||
)[0]
|
)[1]
|
||||||
|
|
||||||
|
device_status = await client.get_device_status(device_id)
|
||||||
|
|
||||||
events: list[DeviceEvent] = []
|
events: list[DeviceEvent] = []
|
||||||
|
|
||||||
def register_event(event: DeviceEvent) -> None:
|
def register_event(event: DeviceEvent) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
client = entry.runtime_data.client
|
|
||||||
|
|
||||||
listener = client.add_device_event_listener(device_id, register_event)
|
listener = client.add_device_event_listener(device_id, register_event)
|
||||||
|
|
||||||
await asyncio.sleep(EVENT_WAIT_TIME)
|
await asyncio.sleep(EVENT_WAIT_TIME)
|
||||||
|
|
||||||
listener()
|
listener()
|
||||||
|
|
||||||
device_status = await client.get_device_status(device_id)
|
|
||||||
|
|
||||||
status: dict[str, Any] = {}
|
status: dict[str, Any] = {}
|
||||||
for component, capabilities in device_status.items():
|
for component, capabilities in device_status.items():
|
||||||
status[component] = {}
|
status[component] = {}
|
||||||
|
@ -34,6 +34,8 @@ async def test_device(
|
|||||||
identifiers={(DOMAIN, "96a5ef74-5832-a84b-f1f7-ca799957065d")}
|
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):
|
with patch("homeassistant.components.smartthings.diagnostics.EVENT_WAIT_TIME", 0.1):
|
||||||
diag = await get_diagnostics_for_device(
|
diag = await get_diagnostics_for_device(
|
||||||
hass, hass_client, mock_config_entry, device
|
hass, hass_client, mock_config_entry, device
|
||||||
@ -42,3 +44,6 @@ async def test_device(
|
|||||||
assert diag == snapshot(
|
assert diag == snapshot(
|
||||||
exclude=props("last_changed", "last_reported", "last_updated")
|
exclude=props("last_changed", "last_reported", "last_updated")
|
||||||
)
|
)
|
||||||
|
mock_smartthings.get_device_status.assert_called_once_with(
|
||||||
|
"96a5ef74-5832-a84b-f1f7-ca799957065d"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user