mirror of
https://github.com/home-assistant/core.git
synced 2026-03-05 00:58:47 +00:00
Add diagnostic to systemnexa2 integration (#164090)
This commit is contained in:
40
homeassistant/components/systemnexa2/diagnostics.py
Normal file
40
homeassistant/components/systemnexa2/diagnostics.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Diagnostics support for System Nexa 2."""
|
||||
|
||||
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_DEVICE_ID, CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import SystemNexa2ConfigEntry
|
||||
|
||||
TO_REDACT = {
|
||||
CONF_HOST,
|
||||
CONF_DEVICE_ID,
|
||||
"unique_id",
|
||||
"wifi_ssid",
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: SystemNexa2ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
return {
|
||||
"config_entry": async_redact_data(dict(entry.data), TO_REDACT),
|
||||
"device_info": async_redact_data(asdict(coordinator.data.info_data), TO_REDACT),
|
||||
"coordinator_available": coordinator.last_update_success,
|
||||
"state": coordinator.data.state,
|
||||
"settings": {
|
||||
name: {
|
||||
"name": setting.name,
|
||||
"enabled": setting.is_enabled(),
|
||||
}
|
||||
for name, setting in coordinator.data.on_off_settings.items()
|
||||
},
|
||||
}
|
||||
@@ -45,7 +45,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: done
|
||||
discovery: done
|
||||
docs-data-update: done
|
||||
|
||||
33
tests/components/systemnexa2/snapshots/test_diagnostics.ambr
Normal file
33
tests/components/systemnexa2/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,33 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics[False]
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'device_id': '**REDACTED**',
|
||||
'host': '**REDACTED**',
|
||||
'model': 'WPO-01',
|
||||
'name': 'Outdoor Smart Plug',
|
||||
}),
|
||||
'coordinator_available': True,
|
||||
'device_info': dict({
|
||||
'dimmable': False,
|
||||
'hw_version': 'Test HW Version',
|
||||
'model': 'WPO-01',
|
||||
'name': 'Outdoor Smart Plug',
|
||||
'sw_version': 'Test Model Version',
|
||||
'unique_id': '**REDACTED**',
|
||||
'wifi_dbm': -50,
|
||||
'wifi_ssid': '**REDACTED**',
|
||||
}),
|
||||
'settings': dict({
|
||||
'433Mhz': dict({
|
||||
'enabled': True,
|
||||
'name': '433Mhz',
|
||||
}),
|
||||
'Cloud Access': dict({
|
||||
'enabled': False,
|
||||
'name': 'Cloud Access',
|
||||
}),
|
||||
}),
|
||||
'state': 1.0,
|
||||
})
|
||||
# ---
|
||||
29
tests/components/systemnexa2/test_diagnostics.py
Normal file
29
tests/components/systemnexa2/test_diagnostics.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Test System Nexa 2 diagnostics."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
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,
|
||||
mock_system_nexa_2_device,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics for config entry."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
||||
assert result == snapshot
|
||||
Reference in New Issue
Block a user