mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 10:05:26 +01:00
Firefly III add diagnostics (#154743)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
26
homeassistant/components/firefly_iii/diagnostics.py
Normal file
26
homeassistant/components/firefly_iii/diagnostics.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Diagnostics for the Firefly III integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import FireflyConfigEntry
|
||||
from .coordinator import FireflyDataUpdateCoordinator
|
||||
|
||||
TO_REDACT = [CONF_API_KEY, CONF_URL]
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: FireflyConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: FireflyDataUpdateCoordinator = entry.runtime_data
|
||||
|
||||
return {
|
||||
"config_entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||
"data": {"primary_currency": coordinator.data.primary_currency.to_dict()},
|
||||
}
|
||||
44
tests/components/firefly_iii/snapshots/test_diagnostics.ambr
Normal file
44
tests/components/firefly_iii/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,44 @@
|
||||
# serializer version: 1
|
||||
# name: test_get_config_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'api_key': '**REDACTED**',
|
||||
'url': '**REDACTED**',
|
||||
'verify_ssl': True,
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'firefly_iii',
|
||||
'entry_id': 'firefly_iii_test_entry_123',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Firefly III test',
|
||||
'unique_id': 'firefly_iii_test_unique_id_123',
|
||||
'version': 1,
|
||||
}),
|
||||
'data': dict({
|
||||
'primary_currency': dict({
|
||||
'attributes': dict({
|
||||
'code': 'AMS',
|
||||
'decimal_places': 2,
|
||||
'default': False,
|
||||
'enabled': True,
|
||||
'name': 'Ankh-Morpork dollar',
|
||||
'native': False,
|
||||
'symbol': 'AM$',
|
||||
'updated_at': '2018-09-17T12:46:47+01:00',
|
||||
}),
|
||||
'id': '2',
|
||||
'type': 'currencies',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
35
tests/components/firefly_iii/test_diagnostics.py
Normal file
35
tests/components/firefly_iii/test_diagnostics.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Test the Firefly III component diagnostics."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
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_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
mock_firefly_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
) -> None:
|
||||
"""Test if get_config_entry_diagnostics returns the correct data."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
diagnostics_entry = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
assert diagnostics_entry == snapshot(
|
||||
exclude=props(
|
||||
"created_at",
|
||||
"modified_at",
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user