mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Add diagnostics to onedrive (#139516)
* Add diagnostics to onedrive * redact PII * add raw data
This commit is contained in:
parent
5fa5d08b18
commit
0681652aec
33
homeassistant/components/onedrive/diagnostics.py
Normal file
33
homeassistant/components/onedrive/diagnostics.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""Diagnostics support for OneDrive."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import OneDriveConfigEntry
|
||||
|
||||
TO_REDACT = {"display_name", "email", CONF_ACCESS_TOKEN, CONF_TOKEN}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
entry: OneDriveConfigEntry,
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
|
||||
coordinator = entry.runtime_data.coordinator
|
||||
|
||||
data = {
|
||||
"drive": asdict(coordinator.data),
|
||||
"config": {
|
||||
**entry.data,
|
||||
**entry.options,
|
||||
},
|
||||
}
|
||||
|
||||
return async_redact_data(data, TO_REDACT)
|
@ -41,10 +41,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics:
|
||||
status: exempt
|
||||
comment: |
|
||||
There is no data to diagnose.
|
||||
diagnostics: done
|
||||
discovery-update-info:
|
||||
status: exempt
|
||||
comment: |
|
||||
|
31
tests/components/onedrive/snapshots/test_diagnostics.ambr
Normal file
31
tests/components/onedrive/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,31 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'config': dict({
|
||||
'auth_implementation': 'onedrive',
|
||||
'folder_id': 'my_folder_id',
|
||||
'folder_name': 'name',
|
||||
'token': '**REDACTED**',
|
||||
}),
|
||||
'drive': dict({
|
||||
'drive_type': 'personal',
|
||||
'id': 'mock_drive_id',
|
||||
'name': 'My Drive',
|
||||
'owner': dict({
|
||||
'application': None,
|
||||
'user': dict({
|
||||
'display_name': '**REDACTED**',
|
||||
'email': '**REDACTED**',
|
||||
'id': 'id',
|
||||
}),
|
||||
}),
|
||||
'quota': dict({
|
||||
'deleted': 5,
|
||||
'remaining': 805306368,
|
||||
'state': 'nearing',
|
||||
'total': 5368709120,
|
||||
'used': 4250000000,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
26
tests/components/onedrive/test_diagnostics.py
Normal file
26
tests/components/onedrive/test_diagnostics.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""Tests for the diagnostics data provided by the OneDrive integration."""
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
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_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user