mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Add panel information to diagnostics for Satel Integra (#180987)
This commit is contained in:
@@ -69,8 +69,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: SatelConfigEntry) -> boo
|
||||
)
|
||||
await coordinator_temperatures.async_config_entry_first_refresh()
|
||||
|
||||
try:
|
||||
panel_info = await client.controller.read_panel_info()
|
||||
except SatelIntegraError:
|
||||
_LOGGER.warning("Unable to read Satel panel information", exc_info=True)
|
||||
panel_info = None
|
||||
|
||||
entry.runtime_data = SatelIntegraData(
|
||||
client=client,
|
||||
panel_info=panel_info,
|
||||
coordinator_zones=coordinator_zones,
|
||||
coordinator_outputs=coordinator_outputs,
|
||||
coordinator_partitions=coordinator_partitions,
|
||||
@@ -86,12 +93,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: SatelConfigEntry) -> boo
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_close_connection)
|
||||
)
|
||||
|
||||
try:
|
||||
panel_info = await client.controller.read_panel_info()
|
||||
except SatelIntegraError:
|
||||
_LOGGER.warning("Unable to read Satel panel information", exc_info=True)
|
||||
panel_info = None
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
|
||||
@@ -5,7 +5,7 @@ from datetime import timedelta
|
||||
import logging
|
||||
from typing import override
|
||||
|
||||
from satel_integra import AlarmState
|
||||
from satel_integra import AlarmState, SatelPanelInfo
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
@@ -26,6 +26,7 @@ class SatelIntegraData:
|
||||
"""Data for the satel_integra integration."""
|
||||
|
||||
client: SatelClient
|
||||
panel_info: SatelPanelInfo | None
|
||||
coordinator_zones: SatelIntegraZonesCoordinator
|
||||
coordinator_outputs: SatelIntegraOutputsCoordinator
|
||||
coordinator_partitions: SatelIntegraPartitionsCoordinator
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
"""Diagnostics support for Satel Integra."""
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_CODE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_ENCRYPTION_KEY
|
||||
from .coordinator import SatelConfigEntry
|
||||
|
||||
TO_REDACT = {CONF_CODE, CONF_ENCRYPTION_KEY}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: SatelConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for the config entry."""
|
||||
diag: dict[str, Any] = {}
|
||||
|
||||
diag["config_entry_data"] = async_redact_data(entry.data, TO_REDACT)
|
||||
diag["config_entry_options"] = async_redact_data(entry.options, TO_REDACT)
|
||||
|
||||
diag["subentries"] = dict(entry.subentries)
|
||||
|
||||
return diag
|
||||
return {
|
||||
"config_entry_data": async_redact_data(entry.data, TO_REDACT),
|
||||
"config_entry_options": async_redact_data(entry.options, TO_REDACT),
|
||||
"subentries": dict(entry.subentries),
|
||||
"panel_info": (
|
||||
asdict(entry.runtime_data.panel_info)
|
||||
if entry.runtime_data.panel_info
|
||||
else None
|
||||
),
|
||||
}
|
||||
|
||||
@@ -9,6 +9,18 @@
|
||||
'config_entry_options': dict({
|
||||
'code': '**REDACTED**',
|
||||
}),
|
||||
'panel_info': dict({
|
||||
'firmware': dict({
|
||||
'release_date': '2025-03-12',
|
||||
'version': '1.24',
|
||||
}),
|
||||
'language_code': 0,
|
||||
'model': dict({
|
||||
'name': 'INTEGRA 64',
|
||||
}),
|
||||
'settings_stored_in_flash': True,
|
||||
'type_code': 2,
|
||||
}),
|
||||
'subentries': dict({
|
||||
'ID_OUTPUT': dict({
|
||||
'data': dict({
|
||||
@@ -67,6 +79,18 @@
|
||||
'config_entry_options': dict({
|
||||
'code': '**REDACTED**',
|
||||
}),
|
||||
'panel_info': dict({
|
||||
'firmware': dict({
|
||||
'release_date': '2025-03-12',
|
||||
'version': '1.24',
|
||||
}),
|
||||
'language_code': 0,
|
||||
'model': dict({
|
||||
'name': 'INTEGRA 64',
|
||||
}),
|
||||
'settings_stored_in_flash': True,
|
||||
'type_code': 2,
|
||||
}),
|
||||
'subentries': dict({
|
||||
'ID_ZONE': dict({
|
||||
'data': dict({
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
from satel_integra import SatelUnexpectedResponseError
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
@@ -10,6 +11,7 @@ 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
|
||||
|
||||
@@ -35,3 +37,21 @@ async def test_diagnostics(
|
||||
|
||||
diagnostics = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||
assert diagnostics == snapshot(exclude=props("created_at", "modified_at", "id"))
|
||||
|
||||
|
||||
async def test_diagnostics_without_panel_info(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_satel: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test diagnostics when panel information could not be read during setup."""
|
||||
mock_satel.read_panel_info.side_effect = SatelUnexpectedResponseError
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
diagnostics = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, mock_config_entry
|
||||
)
|
||||
|
||||
assert diagnostics["panel_info"] is None
|
||||
mock_satel.read_panel_info.assert_awaited_once_with()
|
||||
|
||||
Reference in New Issue
Block a user