Add diagnostics platform to modern forms (#125032)

This commit is contained in:
Michael 2024-09-01 22:04:29 +02:00 committed by GitHub
parent 659d135fca
commit 07e251d488
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,36 @@
"""Diagnostics support for Modern Forms."""
from __future__ import annotations
from dataclasses import asdict
from typing import TYPE_CHECKING, Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_MAC
from homeassistant.core import HomeAssistant
from .const import DOMAIN
from .coordinator import ModernFormsDataUpdateCoordinator
REDACT_CONFIG = {CONF_MAC}
REDACT_DEVICE_INFO = {"mac_address", "owner"}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator: ModernFormsDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
if TYPE_CHECKING:
assert coordinator is not None
return {
"config_entry": async_redact_data(entry.as_dict(), REDACT_CONFIG),
"device": {
"info": async_redact_data(
asdict(coordinator.modern_forms.info), REDACT_DEVICE_INFO
),
"status": asdict(coordinator.modern_forms.status),
},
}

View File

@ -0,0 +1,50 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'config_entry': dict({
'data': dict({
'host': '192.168.1.123',
'mac': '**REDACTED**',
}),
'disabled_by': None,
'domain': 'modern_forms',
'minor_version': 1,
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': 'Mock Title',
'unique_id': None,
'version': 1,
}),
'device': dict({
'info': dict({
'client_id': 'MF_000000000000',
'device_name': 'ModernFormsFan',
'fan_motor_type': 'DC125X25',
'fan_type': '1818-56',
'federated_identity': 'us-east-1:f3da237b-c19c-4f61-b387-0e6dde2e470b',
'firmware_url': '',
'firmware_version': '01.03.0025',
'light_type': 'F6IN-120V-R1-30',
'mac_address': '**REDACTED**',
'main_mcu_firmware_version': '01.03.3008',
'owner': '**REDACTED**',
'product_sku': '',
'production_lot_number': '',
}),
'status': dict({
'adaptive_learning_enabled': False,
'away_mode_enabled': False,
'fan_direction': 'forward',
'fan_on': True,
'fan_sleep_timer': 0,
'fan_speed': 3,
'light_brightness': 50,
'light_on': True,
'light_sleep_timer': 0,
}),
}),
})
# ---

View File

@ -0,0 +1,26 @@
"""Tests for the Modern Forms diagnostics platform."""
from syrupy import SnapshotAssertion
from syrupy.filters import props
from homeassistant.core import HomeAssistant
from . import init_integration
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
async def test_entry_diagnostics(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test the creation and values of the Modern Forms fans."""
entry = await init_integration(hass, aioclient_mock)
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert result == snapshot(exclude=props("created_at", "modified_at", "entry_id"))