mirror of
https://github.com/home-assistant/core.git
synced 2026-04-02 00:20:30 +01:00
Add diagnostics platform to air-Q integration (#166065)
Co-authored-by: Claw <claw@theeggeadventure.com>
This commit is contained in:
36
homeassistant/components/airq/diagnostics.py
Normal file
36
homeassistant/components/airq/diagnostics.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Diagnostics support for air-Q."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_UNIQUE_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import AirQConfigEntry
|
||||
|
||||
REDACT_CONFIG = {CONF_PASSWORD, CONF_UNIQUE_ID, CONF_IP_ADDRESS, "title"}
|
||||
REDACT_DEVICE_INFO = {"identifiers", "name"}
|
||||
REDACT_COORDINATOR_DATA = {"DeviceID"}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: AirQConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
return {
|
||||
"config_entry": async_redact_data(entry.as_dict(), REDACT_CONFIG),
|
||||
"device_info": async_redact_data(
|
||||
dict(coordinator.device_info), REDACT_DEVICE_INFO
|
||||
),
|
||||
"coordinator_data": async_redact_data(
|
||||
coordinator.data, REDACT_COORDINATOR_DATA
|
||||
),
|
||||
"options": {
|
||||
"clip_negative": coordinator.clip_negative,
|
||||
"return_average": coordinator.return_average,
|
||||
},
|
||||
}
|
||||
46
tests/components/airq/snapshots/test_diagnostics.ambr
Normal file
46
tests/components/airq/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,46 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'created_at': '2025-01-01T00:00:00+00:00',
|
||||
'data': dict({
|
||||
'ip_address': '**REDACTED**',
|
||||
'password': '**REDACTED**',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'airq',
|
||||
'entry_id': '01JGFJJZ008DNE3BKJ7ZE14YFE',
|
||||
'minor_version': 1,
|
||||
'modified_at': '2025-01-01T00:00:00+00:00',
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': '**REDACTED**',
|
||||
'unique_id': '**REDACTED**',
|
||||
'version': 1,
|
||||
}),
|
||||
'coordinator_data': dict({
|
||||
'Status': 'OK',
|
||||
'brightness': 42,
|
||||
'co2': 500.0,
|
||||
}),
|
||||
'device_info': dict({
|
||||
'hw_version': 'hw',
|
||||
'identifiers': '**REDACTED**',
|
||||
'manufacturer': 'CorantGmbH',
|
||||
'model': 'model',
|
||||
'name': '**REDACTED**',
|
||||
'sw_version': 'sw',
|
||||
}),
|
||||
'options': dict({
|
||||
'clip_negative': True,
|
||||
'return_average': True,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
38
tests/components/airq/test_diagnostics.py
Normal file
38
tests/components/airq/test_diagnostics.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Test air-Q diagnostics."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.airq.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import TEST_DEVICE_INFO, TEST_USER_DATA
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
FIXED_MOCK_ENTRY_ID = "01JGFJJZ008DNE3BKJ7ZE14YFE"
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2025-01-01T00:00:00+00:00")
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_airq,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=TEST_USER_DATA,
|
||||
unique_id=TEST_DEVICE_INFO["id"],
|
||||
entry_id=FIXED_MOCK_ENTRY_ID,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
|
||||
assert result == snapshot
|
||||
Reference in New Issue
Block a user