From 2c9a96b62a0a1f6d70611947b137e462101b0497 Mon Sep 17 00:00:00 2001 From: MoonDevLT <107535193+MoonDevLT@users.noreply.github.com> Date: Tue, 10 Feb 2026 13:18:23 +0100 Subject: [PATCH] Add config entry diagnostics to lunatone (#162406) Co-authored-by: Joostlek --- .../components/lunatone/diagnostics.py | 20 ++ .../components/lunatone/quality_scale.yaml | 2 +- .../lunatone/snapshots/test_diagnostics.ambr | 214 ++++++++++++++++++ tests/components/lunatone/test_diagnostics.py | 31 +++ 4 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/lunatone/diagnostics.py create mode 100644 tests/components/lunatone/snapshots/test_diagnostics.ambr create mode 100644 tests/components/lunatone/test_diagnostics.py diff --git a/homeassistant/components/lunatone/diagnostics.py b/homeassistant/components/lunatone/diagnostics.py new file mode 100644 index 00000000000..64df87c8f63 --- /dev/null +++ b/homeassistant/components/lunatone/diagnostics.py @@ -0,0 +1,20 @@ +"""Diagnostics support for Lunatone integration.""" + +from typing import Any + +from homeassistant.core import HomeAssistant + +from .coordinator import LunatoneConfigEntry + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: LunatoneConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + return { + "info": entry.runtime_data.coordinator_info.data.model_dump(), + "devices": [ + v.data.model_dump() + for v in entry.runtime_data.coordinator_devices.data.values() + ], + } diff --git a/homeassistant/components/lunatone/quality_scale.yaml b/homeassistant/components/lunatone/quality_scale.yaml index c118c210d53..a5b9bc44962 100644 --- a/homeassistant/components/lunatone/quality_scale.yaml +++ b/homeassistant/components/lunatone/quality_scale.yaml @@ -51,7 +51,7 @@ rules: test-coverage: done # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: status: todo comment: Discovery not yet supported diff --git a/tests/components/lunatone/snapshots/test_diagnostics.ambr b/tests/components/lunatone/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..ce93e4f42a5 --- /dev/null +++ b/tests/components/lunatone/snapshots/test_diagnostics.ambr @@ -0,0 +1,214 @@ +# serializer version: 1 +# name: test_config_entry_diagnostics + dict({ + 'devices': list([ + dict({ + 'address': 0, + 'available': True, + 'dali_types': list([ + ]), + 'features': dict({ + 'color_kelvin': dict({ + 'status': 1000.0, + }), + 'color_kelvin_with_fade': None, + 'color_rgb': dict({ + 'status': dict({ + 'blue': 0.0, + 'green': 0.0, + 'red': 0.0, + }), + }), + 'color_rgb_with_fade': None, + 'color_waf': dict({ + 'status': dict({ + 'amber': 0.0, + 'free_color': 0.0, + 'white': 0.0, + }), + }), + 'color_waf_with_fade': None, + 'color_xy': None, + 'color_xy_with_fade': None, + 'dali_cmd16': None, + 'dim_down': None, + 'dim_up': None, + 'dimmable': dict({ + 'status': 0.0, + }), + 'dimmable_kelvin': None, + 'dimmable_rgb': None, + 'dimmable_waf': None, + 'dimmable_with_fade': None, + 'dimmable_xy': None, + 'fade_rate': None, + 'fade_time': None, + 'goto_last_active': None, + 'goto_last_active_with_fade': None, + 'save_to_scene': None, + 'scene': None, + 'scene_with_fade': None, + 'switchable': dict({ + 'status': False, + }), + }), + 'groups': list([ + ]), + 'id': 1, + 'line': 0, + 'name': 'Device 1', + 'scenes': list([ + ]), + 'status': dict({ + 'control_gear_failure': False, + 'fade_running': False, + 'is_unaddressed': False, + 'lamp_failure': False, + 'lamp_on': False, + 'limit_error': False, + 'power_cycle_see': False, + 'raw': 0, + 'reset_state': False, + }), + 'time_signature': None, + 'type': 'default', + }), + dict({ + 'address': 1, + 'available': True, + 'dali_types': list([ + ]), + 'features': dict({ + 'color_kelvin': dict({ + 'status': 1000.0, + }), + 'color_kelvin_with_fade': None, + 'color_rgb': dict({ + 'status': dict({ + 'blue': 0.0, + 'green': 0.0, + 'red': 0.0, + }), + }), + 'color_rgb_with_fade': None, + 'color_waf': dict({ + 'status': dict({ + 'amber': 0.0, + 'free_color': 0.0, + 'white': 0.0, + }), + }), + 'color_waf_with_fade': None, + 'color_xy': None, + 'color_xy_with_fade': None, + 'dali_cmd16': None, + 'dim_down': None, + 'dim_up': None, + 'dimmable': dict({ + 'status': 0.0, + }), + 'dimmable_kelvin': None, + 'dimmable_rgb': None, + 'dimmable_waf': None, + 'dimmable_with_fade': None, + 'dimmable_xy': None, + 'fade_rate': None, + 'fade_time': None, + 'goto_last_active': None, + 'goto_last_active_with_fade': None, + 'save_to_scene': None, + 'scene': None, + 'scene_with_fade': None, + 'switchable': dict({ + 'status': False, + }), + }), + 'groups': list([ + ]), + 'id': 2, + 'line': 0, + 'name': 'Device 2', + 'scenes': list([ + ]), + 'status': dict({ + 'control_gear_failure': False, + 'fade_running': False, + 'is_unaddressed': False, + 'lamp_failure': False, + 'lamp_on': False, + 'limit_error': False, + 'power_cycle_see': False, + 'raw': 0, + 'reset_state': False, + }), + 'time_signature': None, + 'type': 'default', + }), + ]), + 'info': dict({ + 'descriptor': dict({ + 'buffer_size': 0, + 'device_list_specifier': 0, + 'implemented_macros': list([ + ]), + 'lines': 0, + 'max_yn_frame_size': 0, + 'power_supply_implemented': False, + 'protocol_version_major': 1, + 'protocol_version_minor': 0, + 'tick_resolution': 0, + }), + 'device': dict({ + 'article_info': '', + 'article_number': 87654321, + 'gtin': 192837465, + 'pcb': '2a', + 'production_week': 1, + 'production_year': 20, + 'serial': 12345, + }), + 'emergency_light': False, + 'errors': dict({ + }), + 'lines': dict({ + '0': dict({ + 'device': dict({ + 'article_info': '', + 'article_number': 87654321, + 'gtin': 192837465, + 'pcb': '2a', + 'production_week': 1, + 'production_year': 20, + 'serial': 12345, + }), + 'line_status': 'ok', + 'send_blocked_initialize': False, + 'send_blocked_macro_running': False, + 'send_blocked_quiescent': False, + 'send_buffer_full': False, + }), + '1': dict({ + 'device': dict({ + 'article_info': '', + 'article_number': 12345678, + 'gtin': 101010101, + 'pcb': '1a', + 'production_week': 10, + 'production_year': 22, + 'serial': 54321, + }), + 'line_status': 'ok', + 'send_blocked_initialize': False, + 'send_blocked_macro_running': False, + 'send_blocked_quiescent': False, + 'send_buffer_full': False, + }), + }), + 'name': 'Test', + 'node_red': False, + 'startup_mode': 'normal', + 'tier': 'basic', + 'version': 'v1.14.1/1.4.3', + }), + }) +# --- diff --git a/tests/components/lunatone/test_diagnostics.py b/tests/components/lunatone/test_diagnostics.py new file mode 100644 index 00000000000..bdbf480b840 --- /dev/null +++ b/tests/components/lunatone/test_diagnostics.py @@ -0,0 +1,31 @@ +"""Define tests for Lunatone diagnostics.""" + +from unittest.mock import AsyncMock + +from syrupy.assertion import SnapshotAssertion + +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 + + +async def test_config_entry_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + mock_lunatone_devices: AsyncMock, + mock_lunatone_info: AsyncMock, + mock_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test the config entry level diagnostics.""" + await setup_integration(hass, mock_config_entry) + + diagnostics = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + + assert diagnostics == snapshot