From bf92db6fd577407c3fcd78ecd30f1c5ef862f0af Mon Sep 17 00:00:00 2001 From: Sid <27780930+autinerd@users.noreply.github.com> Date: Mon, 26 May 2025 19:25:15 +0200 Subject: [PATCH] Add diagnostics to eheimdigital (#145382) * Add diagnotics to eheimdigital * Diagnostics are now with data in tests --- .../components/eheimdigital/diagnostics.py | 19 ++ .../eheimdigital/quality_scale.yaml | 2 +- .../snapshots/test_diagnostics.ambr | 261 ++++++++++++++++++ .../eheimdigital/test_diagnostics.py | 39 +++ 4 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/eheimdigital/diagnostics.py create mode 100644 tests/components/eheimdigital/snapshots/test_diagnostics.ambr create mode 100644 tests/components/eheimdigital/test_diagnostics.py diff --git a/homeassistant/components/eheimdigital/diagnostics.py b/homeassistant/components/eheimdigital/diagnostics.py new file mode 100644 index 00000000000..208131beabe --- /dev/null +++ b/homeassistant/components/eheimdigital/diagnostics.py @@ -0,0 +1,19 @@ +"""Diagnostics for the EHEIM Digital integration.""" + +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.core import HomeAssistant + +from .coordinator import EheimDigitalConfigEntry + +TO_REDACT = {"emailAddr", "usrName"} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: EheimDigitalConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + return async_redact_data( + {"entry": entry.as_dict(), "data": entry.runtime_data.data}, TO_REDACT + ) diff --git a/homeassistant/components/eheimdigital/quality_scale.yaml b/homeassistant/components/eheimdigital/quality_scale.yaml index fa13c9bf4ca..c1490b352c2 100644 --- a/homeassistant/components/eheimdigital/quality_scale.yaml +++ b/homeassistant/components/eheimdigital/quality_scale.yaml @@ -43,7 +43,7 @@ rules: # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: done discovery: done docs-data-update: todo diff --git a/tests/components/eheimdigital/snapshots/test_diagnostics.ambr b/tests/components/eheimdigital/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..a60952b0ef5 --- /dev/null +++ b/tests/components/eheimdigital/snapshots/test_diagnostics.ambr @@ -0,0 +1,261 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'data': dict({ + '00:00:00:00:00:01': dict({ + 'acclimate': dict({ + 'acclActive': 0, + 'currentAcclDay': 0, + 'duration': 30, + 'from': '00:00:00:00:00:01', + 'intensityReduction': 99, + 'pause': 0, + 'title': 'ACCLIMATE', + }), + 'ccv': dict({ + 'currentValues': list([ + 10, + 39, + ]), + 'from': '00:00:00:00:00:01', + 'title': 'CCV', + }), + 'clock': dict({ + 'day': 22, + 'from': '00:00:00:00:00:01', + 'hour': 5, + 'min': 53, + 'mode': 'DAYCL_MODE', + 'month': 5, + 'sec': 22, + 'title': 'CLOCK', + 'to': 'USER', + 'valid': 1, + 'year': 2025, + }), + 'cloud': dict({ + 'cloudActive': 1, + 'from': '00:00:00:00:00:01', + 'maxAmount': 90, + 'maxDuration': 1500, + 'maxIntensity': 100, + 'minDuration': 600, + 'minIntensity': 60, + 'mode': 2, + 'probability': 50, + 'title': 'CLOUD', + }), + 'moon': dict({ + 'from': '00:00:00:00:00:01', + 'maxmoonlight': 18, + 'minmoonlight': 4, + 'moonlightActive': 1, + 'moonlightCycle': 1, + 'title': 'MOON', + }), + 'usrdta': dict({ + 'aqName': 'Mock Aquarium', + 'build': list([ + '1722600896000', + '1722596503307', + ]), + 'demoUse': 0, + 'dst': 1, + 'emailAddr': '', + 'firmwareAvailable': 0, + 'firstStart': 0, + 'from': '00:00:00:00:00:01', + 'fstTime': 0, + 'groupID': 0, + 'host': 'eheimdigital', + 'language': 'EN', + 'latestAvailableRevision': list([ + -1, + -1, + -1, + -1, + ]), + 'liveTime': 832140, + 'meshing': 1, + 'mode': 'DAYCL_MODE', + 'name': 'Mock classicLEDcontrol+e', + 'netmode': 'ST', + 'power': '[[],[14]]', + 'revision': list([ + 2034, + 2034, + ]), + 'softChange': 0, + 'sstTime': 0, + 'stMail': 0, + 'stMailMode': 0, + 'sysLED': 20, + 'tID': 30, + 'tankconfig': '[[],["CLASSIC_DAYLIGHT"]]', + 'timezone': 60, + 'title': 'USRDTA', + 'to': 'USER', + 'unit': 0, + 'usrName': '', + 'version': 17, + }), + }), + '00:00:00:00:00:02': dict({ + 'heater_data': dict({ + 'active': 1, + 'alertState': 0, + 'dayStartT': 480, + 'from': '00:00:00:00:00:02', + 'hystHigh': 5, + 'hystLow': 5, + 'isHeating': 1, + 'isTemp': 242, + 'mUnit': 0, + 'mode': 0, + 'nReduce': -2, + 'nightStartT': 1200, + 'offset': 1, + 'partnerName': '', + 'sollTemp': 255, + 'sync': '', + 'title': 'HEATER_DATA', + 'to': 'USER', + }), + 'usrdta': dict({ + 'aqName': 'Mock Aquarium', + 'build': list([ + '1718889198000', + '1718868200327', + ]), + 'demoUse': 0, + 'dst': 1, + 'emailAddr': '', + 'firmwareAvailable': 0, + 'firstStart': 0, + 'from': '00:00:00:00:00:02', + 'fstTime': 0, + 'groupID': 0, + 'host': 'eheimdigital', + 'language': 'EN', + 'latestAvailableRevision': list([ + -1, + -1, + -1, + -1, + ]), + 'liveTime': 302580, + 'meshing': 1, + 'name': 'Mock Heater', + 'netmode': 'ST', + 'power': '9', + 'remote': 0, + 'revision': list([ + 1021, + 1024, + ]), + 'sstTime': 0, + 'stMail': 0, + 'stMailMode': 0, + 'sysLED': 20, + 'tID': 30, + 'tankconfig': 'HEAT400', + 'timezone': 60, + 'title': 'USRDTA', + 'to': 'USER', + 'unit': 0, + 'usrName': '', + 'version': 5, + }), + }), + '00:00:00:00:00:03': dict({ + 'classic_vario_data': dict({ + 'errorCode': 0, + 'filterActive': 1, + 'from': '00:00:00:00:00:03', + 'pulse_Time_High': 100, + 'pulse_Time_Low': 50, + 'pulse_motorSpeed_High': 100, + 'pulse_motorSpeed_Low': 20, + 'pumpMode': 16, + 'rel_manual_motor_speed': 75, + 'rel_motor_speed_day': 80, + 'rel_motor_speed_night': 20, + 'rel_speed': 75, + 'serviceHour': 360, + 'startTime_day': 480, + 'startTime_night': 1200, + 'title': 'CLASSIC_VARIO_DATA', + 'to': 'USER', + 'turnOffTime': 0, + 'turnTimeFeeding': 0, + 'version': 0, + }), + 'usrdta': dict({ + 'aqName': 'Mock Aquarium', + 'build': list([ + '1722600896000', + '1722596503307', + ]), + 'demoUse': 0, + 'dst': 1, + 'emailAddr': '', + 'firmwareAvailable': 1, + 'firstStart': 0, + 'from': '00:00:00:00:00:03', + 'fstTime': 720, + 'groupID': 0, + 'host': 'eheimdigital', + 'language': 'EN', + 'latestAvailableRevision': list([ + 1024, + 1028, + 2036, + 2036, + ]), + 'liveTime': 444600, + 'meshing': 1, + 'name': 'Mock classicVARIO', + 'netmode': 'ST', + 'power': '9', + 'revision': list([ + 2034, + 2034, + ]), + 'softChange': 0, + 'sstTime': 0, + 'stMail': 0, + 'stMailMode': 0, + 'sysLED': 100, + 'tID': 30, + 'tankconfig': 'CLASSIC-VARIO', + 'timezone': 60, + 'title': 'USRDTA', + 'to': 'USER', + 'unit': 0, + 'usrName': '', + 'version': 18, + }), + }), + }), + 'entry': dict({ + 'data': dict({ + 'host': 'eheimdigital', + }), + 'disabled_by': None, + 'discovery_keys': dict({ + }), + 'domain': 'eheimdigital', + 'minor_version': 1, + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'subentries': list([ + ]), + 'title': 'Mock Title', + 'unique_id': '00:00:00:00:00:01', + 'version': 1, + }), + }) +# --- diff --git a/tests/components/eheimdigital/test_diagnostics.py b/tests/components/eheimdigital/test_diagnostics.py new file mode 100644 index 00000000000..878bc1eb1cc --- /dev/null +++ b/tests/components/eheimdigital/test_diagnostics.py @@ -0,0 +1,39 @@ +"""Tests for the diagnostics module.""" + +from unittest.mock import MagicMock + +from syrupy.assertion import SnapshotAssertion +from syrupy.filters import props + +from homeassistant.core import HomeAssistant + +from .conftest import init_integration + +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, + snapshot: SnapshotAssertion, + eheimdigital_hub_mock: MagicMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test config entry diagnostics.""" + + await init_integration(hass, mock_config_entry) + + for device in eheimdigital_hub_mock.return_value.devices.values(): + await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( + device.mac_address, device.device_type + ) + + mock_config_entry.runtime_data.data = eheimdigital_hub_mock.return_value.devices + + result = await get_diagnostics_for_config_entry( + hass, hass_client, mock_config_entry + ) + + assert result == snapshot(exclude=props("created_at", "modified_at", "entry_id"))