Update nest diagnostics (#65141)

pull/65442/head
Allen Porter 2022-01-28 12:50:38 -08:00 committed by Paulus Schoutsen
parent 3829a81d15
commit 25e6d8858c
3 changed files with 28 additions and 18 deletions

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from typing import Any
from google_nest_sdm import diagnostics
from google_nest_sdm.device import Device
from google_nest_sdm.device_traits import InfoTrait
from google_nest_sdm.exceptions import ApiException
@ -30,22 +31,14 @@ async def async_get_config_entry_diagnostics(
return {"error": str(err)}
return {
**diagnostics.get_diagnostics(),
"devices": [
get_device_data(device) for device in device_manager.devices.values()
]
],
}
def get_device_data(device: Device) -> dict[str, Any]:
"""Return diagnostic information about a device."""
# Return a simplified view of the API object, but skipping any id fields or
# traits that include unique identifiers or personally identifiable information.
# See https://developers.google.com/nest/device-access/traits for API details
return {
"type": device.type,
"traits": {
trait: data
for trait, data in device.raw_data.get("traits", {}).items()
if trait not in REDACT_DEVICE_TRAITS
},
}
# Library performs its own redaction for device data
return device.get_diagnostics()

View File

@ -1,6 +1,7 @@
"""Common libraries for test setup."""
from __future__ import annotations
from collections.abc import Generator
import copy
import shutil
from typing import Any
@ -8,6 +9,7 @@ from unittest.mock import patch
import uuid
import aiohttp
from google_nest_sdm import diagnostics
from google_nest_sdm.auth import AbstractAuth
from google_nest_sdm.device_manager import DeviceManager
import pytest
@ -234,3 +236,10 @@ async def setup_platform(
) -> PlatformSetup:
"""Fixture to setup the integration platform and subscriber."""
return setup_base_platform
@pytest.fixture(autouse=True)
def reset_diagnostics() -> Generator[None, None, None]:
"""Fixture to reset client library diagnostic counters."""
yield
diagnostics.reset()

View File

@ -56,13 +56,21 @@ async def test_entry_diagnostics(hass, hass_client):
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"devices": [
{
"traits": {
"sdm.devices.traits.Humidity": {"ambientHumidityPercent": 35.0},
"sdm.devices.traits.Temperature": {
"ambientTemperatureCelsius": 25.1
"data": {
"assignee": "**REDACTED**",
"name": "**REDACTED**",
"parentRelations": [
{"displayName": "**REDACTED**", "parent": "**REDACTED**"}
],
"traits": {
"sdm.devices.traits.Info": {"customName": "**REDACTED**"},
"sdm.devices.traits.Humidity": {"ambientHumidityPercent": 35.0},
"sdm.devices.traits.Temperature": {
"ambientTemperatureCelsius": 25.1
},
},
},
"type": "sdm.devices.types.THERMOSTAT",
"type": "sdm.devices.types.THERMOSTAT",
}
}
],
}