mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add config entry level diagnostics to SmartThings (#139939)
* Add config entry level diagnostics to SmartThings * Add config entry level diagnostics to SmartThings * Add config entry level diagnostics to SmartThings
This commit is contained in:
parent
f38a32477e
commit
4bafdf5e4b
@ -17,6 +17,15 @@ from .const import DOMAIN
|
||||
EVENT_WAIT_TIME = 5
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
entry: SmartThingsConfigEntry,
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
client = entry.runtime_data.client
|
||||
return await client.get_raw_devices()
|
||||
|
||||
|
||||
async def async_get_device_diagnostics(
|
||||
hass: HomeAssistant, entry: SmartThingsConfigEntry, device: DeviceEntry
|
||||
) -> dict[str, Any]:
|
||||
@ -26,7 +35,8 @@ async def async_get_device_diagnostics(
|
||||
identifier for identifier in device.identifiers if identifier[0] == DOMAIN
|
||||
)[1]
|
||||
|
||||
device_status = await client.get_device_status(device_id)
|
||||
device_status = await client.get_raw_device_status(device_id)
|
||||
device_info = await client.get_raw_device(device_id)
|
||||
|
||||
events: list[DeviceEvent] = []
|
||||
|
||||
@ -39,11 +49,8 @@ async def async_get_device_diagnostics(
|
||||
|
||||
listener()
|
||||
|
||||
status: dict[str, Any] = {}
|
||||
for component, capabilities in device_status.items():
|
||||
status[component] = {}
|
||||
for capability, attributes in capabilities.items():
|
||||
status[component][capability] = {}
|
||||
for attribute, value in attributes.items():
|
||||
status[component][capability][attribute] = asdict(value)
|
||||
return {"events": [asdict(event) for event in events], "status": status}
|
||||
return {
|
||||
"events": [asdict(event) for event in events],
|
||||
"status": device_status,
|
||||
"info": device_info,
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,13 +12,36 @@ from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_device
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
from tests.components.diagnostics import (
|
||||
get_diagnostics_for_config_entry,
|
||||
get_diagnostics_for_device,
|
||||
)
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])
|
||||
async def test_device(
|
||||
async def test_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
devices: AsyncMock,
|
||||
mock_smartthings: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test generating diagnostics for a device entry."""
|
||||
mock_smartthings.get_raw_devices.return_value = load_json_object_fixture(
|
||||
"devices/da_ac_rac_000001.json", DOMAIN
|
||||
)
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])
|
||||
async def test_device_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
@ -28,13 +51,19 @@ async def test_device(
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test generating diagnostics for a device entry."""
|
||||
mock_smartthings.get_raw_device_status.return_value = load_json_object_fixture(
|
||||
"device_status/da_ac_rac_000001.json", DOMAIN
|
||||
)
|
||||
mock_smartthings.get_raw_device.return_value = load_json_object_fixture(
|
||||
"devices/da_ac_rac_000001.json", DOMAIN
|
||||
)["items"][0]
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, "96a5ef74-5832-a84b-f1f7-ca799957065d")}
|
||||
)
|
||||
|
||||
mock_smartthings.get_device_status.reset_mock()
|
||||
mock_smartthings.get_raw_device_status.reset_mock()
|
||||
|
||||
with patch("homeassistant.components.smartthings.diagnostics.EVENT_WAIT_TIME", 0.1):
|
||||
diag = await get_diagnostics_for_device(
|
||||
@ -44,6 +73,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(
|
||||
mock_smartthings.get_raw_device_status.assert_called_once_with(
|
||||
"96a5ef74-5832-a84b-f1f7-ca799957065d"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user