mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Add diagnostics support to homematicip_cloud (#163829)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""Diagnostics support for HomematicIP Cloud."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from homematicip.base.helpers import handle_config
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .hap import HomematicIPConfigEntry
|
||||
|
||||
TO_REDACT_CONFIG = {"city", "latitude", "longitude", "refreshToken"}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: HomematicIPConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
hap = config_entry.runtime_data
|
||||
json_state = await hap.home.download_configuration_async()
|
||||
anonymized = handle_config(json_state, anonymize=True)
|
||||
config = json.loads(anonymized)
|
||||
|
||||
return async_redact_data(config, TO_REDACT_CONFIG)
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"accessPointId": "3014F7110000000000000001",
|
||||
"home": {
|
||||
"id": "a1b2c3d4-e5f6-1234-abcd-ef0123456789",
|
||||
"location": {
|
||||
"city": "Berlin, Germany",
|
||||
"latitude": "52.520008",
|
||||
"longitude": "13.404954"
|
||||
},
|
||||
"weather": {
|
||||
"temperature": 18.3
|
||||
}
|
||||
},
|
||||
"devices": {
|
||||
"3014F7110000000000000002": {
|
||||
"id": "3014F7110000000000000002",
|
||||
"label": "Living Room Thermostat",
|
||||
"type": "WALL_MOUNTED_THERMOSTAT_PRO",
|
||||
"serializedGlobalTradeItemNumber": "ABCDEFGHIJKLMNOPQRSTUVWX"
|
||||
}
|
||||
},
|
||||
"clients": {
|
||||
"a1b2c3d4-e5f6-1234-abcd-ef0123456789": {
|
||||
"id": "a1b2c3d4-e5f6-1234-abcd-ef0123456789",
|
||||
"label": "Home Assistant",
|
||||
"refreshToken": "secret-refresh-token"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'accessPointId': '3014F7110000000000000000',
|
||||
'clients': dict({
|
||||
'00000000-0000-0000-0000-000000000000': dict({
|
||||
'id': '00000000-0000-0000-0000-000000000000',
|
||||
'label': 'Home Assistant',
|
||||
'refreshToken': None,
|
||||
}),
|
||||
}),
|
||||
'devices': dict({
|
||||
'3014F7110000000000000001': dict({
|
||||
'id': '3014F7110000000000000001',
|
||||
'label': 'Living Room Thermostat',
|
||||
'serializedGlobalTradeItemNumber': '3014F7110000000000000002',
|
||||
'type': 'WALL_MOUNTED_THERMOSTAT_PRO',
|
||||
}),
|
||||
}),
|
||||
'home': dict({
|
||||
'id': '00000000-0000-0000-0000-000000000000',
|
||||
'location': dict({
|
||||
'city': '**REDACTED**',
|
||||
'latitude': '**REDACTED**',
|
||||
'longitude': '**REDACTED**',
|
||||
}),
|
||||
'weather': dict({
|
||||
'temperature': 18.3,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Tests for HomematicIP Cloud diagnostics."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.homematicip_cloud.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import async_load_json_object_fixture
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_hap_with_service,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics for config entry."""
|
||||
mock_hap_with_service.home.download_configuration_async.return_value = (
|
||||
await async_load_json_object_fixture(hass, "diagnostics.json", DOMAIN)
|
||||
)
|
||||
|
||||
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||
|
||||
assert result == snapshot
|
||||
Reference in New Issue
Block a user