Add diagnostics for fyta (#118234)
* Add diagnostics * add test for diagnostics * Redact access_token * remove unnecessary redaction
This commit is contained in:
parent
70820c1702
commit
e54fbcec77
3 changed files with 100 additions and 0 deletions
30
homeassistant/components/fyta/diagnostics.py
Normal file
30
homeassistant/components/fyta/diagnostics.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
"""Provides diagnostics for Fyta."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = [
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
CONF_ACCESS_TOKEN,
|
||||
]
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data = hass.data[DOMAIN][config_entry.entry_id].data
|
||||
|
||||
return {
|
||||
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
|
||||
"plant_data": data,
|
||||
}
|
39
tests/components/fyta/snapshots/test_diagnostics.ambr
Normal file
39
tests/components/fyta/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,39 @@
|
|||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'access_token': '**REDACTED**',
|
||||
'expiration': '2030-12-31T10:00:00+00:00',
|
||||
'password': '**REDACTED**',
|
||||
'username': '**REDACTED**',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'fyta',
|
||||
'entry_id': 'ce5f5431554d101905d31797e1232da8',
|
||||
'minor_version': 2,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'fyta_user',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
'plant_data': dict({
|
||||
'0': dict({
|
||||
'name': 'Gummibaum',
|
||||
'scientific_name': 'Ficus elastica',
|
||||
'status': 1,
|
||||
'sw_version': '1.0',
|
||||
}),
|
||||
'1': dict({
|
||||
'name': 'Kakaobaum',
|
||||
'scientific_name': 'Theobroma cacao',
|
||||
'status': 2,
|
||||
'sw_version': '1.0',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
31
tests/components/fyta/test_diagnostics.py
Normal file
31
tests/components/fyta/test_diagnostics.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""Test Fyta diagnostics."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_platform
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_fyta_connector: AsyncMock,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
await setup_platform(hass, mock_config_entry, [Platform.SENSOR])
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
||||
assert result == snapshot
|
Loading…
Add table
Reference in a new issue