mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +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
|
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(
|
async def async_get_device_diagnostics(
|
||||||
hass: HomeAssistant, entry: SmartThingsConfigEntry, device: DeviceEntry
|
hass: HomeAssistant, entry: SmartThingsConfigEntry, device: DeviceEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
@ -26,7 +35,8 @@ async def async_get_device_diagnostics(
|
|||||||
identifier for identifier in device.identifiers if identifier[0] == DOMAIN
|
identifier for identifier in device.identifiers if identifier[0] == DOMAIN
|
||||||
)[1]
|
)[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] = []
|
events: list[DeviceEvent] = []
|
||||||
|
|
||||||
@ -39,11 +49,8 @@ async def async_get_device_diagnostics(
|
|||||||
|
|
||||||
listener()
|
listener()
|
||||||
|
|
||||||
status: dict[str, Any] = {}
|
return {
|
||||||
for component, capabilities in device_status.items():
|
"events": [asdict(event) for event in events],
|
||||||
status[component] = {}
|
"status": device_status,
|
||||||
for capability, attributes in capabilities.items():
|
"info": device_info,
|
||||||
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}
|
|
||||||
|
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 . import setup_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||||
from tests.components.diagnostics import get_diagnostics_for_device
|
from tests.components.diagnostics import (
|
||||||
|
get_diagnostics_for_config_entry,
|
||||||
|
get_diagnostics_for_device,
|
||||||
|
)
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])
|
@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: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
@ -28,13 +51,19 @@ async def test_device(
|
|||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test generating diagnostics for a device entry."""
|
"""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)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
device = device_registry.async_get_device(
|
device = device_registry.async_get_device(
|
||||||
identifiers={(DOMAIN, "96a5ef74-5832-a84b-f1f7-ca799957065d")}
|
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):
|
with patch("homeassistant.components.smartthings.diagnostics.EVENT_WAIT_TIME", 0.1):
|
||||||
diag = await get_diagnostics_for_device(
|
diag = await get_diagnostics_for_device(
|
||||||
@ -44,6 +73,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(
|
mock_smartthings.get_raw_device_status.assert_called_once_with(
|
||||||
"96a5ef74-5832-a84b-f1f7-ca799957065d"
|
"96a5ef74-5832-a84b-f1f7-ca799957065d"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user