Add diagnostics to slide_local (#133488)

pull/132287/head^2
dontinelli 2024-12-18 15:21:17 +01:00 committed by GitHub
parent fce6d6246f
commit 1e075cdac7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 101 additions and 1 deletions

View File

@ -0,0 +1,27 @@
"""Provides diagnostics for slide_local."""
from __future__ import annotations
from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.const import CONF_PASSWORD
from homeassistant.core import HomeAssistant
from . import SlideConfigEntry
TO_REDACT = [
CONF_PASSWORD,
]
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, config_entry: SlideConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
data = config_entry.runtime_data.data
return {
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
"slide_data": data,
}

View File

@ -43,7 +43,7 @@ rules:
entity-disabled-by-default: done
discovery: done
stale-devices: todo
diagnostics: todo
diagnostics: done
exception-translations: done
icon-translations: todo
reconfiguration-flow: todo

View File

@ -0,0 +1,39 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'config_entry': dict({
'data': dict({
'api_version': 2,
'host': '127.0.0.2',
'mac': '12:34:56:78:90:ab',
}),
'disabled_by': None,
'discovery_keys': dict({
}),
'domain': 'slide_local',
'entry_id': 'ce5f5431554d101905d31797e1232da8',
'minor_version': 1,
'options': dict({
'invert_position': False,
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': 'slide',
'unique_id': '12:34:56:78:90:ab',
'version': 1,
}),
'slide_data': dict({
'board_rev': 1,
'calib_time': 10239,
'curtain_type': 0,
'device_name': 'slide bedroom',
'mac': '1234567890ab',
'pos': 0,
'slide_id': 'slide_1234567890ab',
'state': 'open',
'touch_go': True,
'zone_name': 'bedroom',
}),
})
# ---

View File

@ -0,0 +1,34 @@
"""Test slide_local diagnostics."""
from unittest.mock import AsyncMock
from syrupy import SnapshotAssertion
from syrupy.filters import props
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from . import setup_platform
from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_config_entry: MockConfigEntry,
mock_slide_api: AsyncMock,
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
await setup_platform(
hass, mock_config_entry, [Platform.BUTTON, Platform.COVER, Platform.SWITCH]
)
result = await get_diagnostics_for_config_entry(
hass, hass_client, mock_config_entry
)
assert result == snapshot(exclude=props("created_at", "modified_at"))