diff --git a/homeassistant/components/ista_ecotrend/diagnostics.py b/homeassistant/components/ista_ecotrend/diagnostics.py new file mode 100644 index 00000000000..4c61c197b5e --- /dev/null +++ b/homeassistant/components/ista_ecotrend/diagnostics.py @@ -0,0 +1,33 @@ +"""Diagnostics platform for ista EcoTrend integration.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.components.diagnostics import async_redact_data +from homeassistant.core import HomeAssistant + +from .coordinator import IstaConfigEntry + +TO_REDACT = { + "firstName", + "lastName", + "street", + "houseNumber", + "documentNumber", + "postalCode", + "city", + "propertyNumber", + "idAtCustomerUser", +} + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, config_entry: IstaConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + + return { + "details": async_redact_data(config_entry.runtime_data.details, TO_REDACT), + "data": async_redact_data(config_entry.runtime_data.data, TO_REDACT), + } diff --git a/homeassistant/components/ista_ecotrend/quality_scale.yaml b/homeassistant/components/ista_ecotrend/quality_scale.yaml index 7e1e6fb92d9..33cf24592b3 100644 --- a/homeassistant/components/ista_ecotrend/quality_scale.yaml +++ b/homeassistant/components/ista_ecotrend/quality_scale.yaml @@ -43,7 +43,7 @@ rules: # Gold devices: done - diagnostics: todo + diagnostics: done discovery-update-info: status: exempt comment: The integration is a web service, there are no discoverable devices. diff --git a/tests/components/ista_ecotrend/snapshots/test_diagnostics.ambr b/tests/components/ista_ecotrend/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..c9f5e72ae1f --- /dev/null +++ b/tests/components/ista_ecotrend/snapshots/test_diagnostics.ambr @@ -0,0 +1,205 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'data': dict({ + '26e93f1a-c828-11ea-87d0-0242ac130003': dict({ + 'consumptionUnitId': '26e93f1a-c828-11ea-87d0-0242ac130003', + 'consumptions': list([ + dict({ + 'date': dict({ + 'month': 5, + 'year': 2024, + }), + 'readings': list([ + dict({ + 'additionalValue': '38,0', + 'type': 'heating', + 'value': '35', + }), + dict({ + 'additionalValue': '57,0', + 'type': 'warmwater', + 'value': '1,0', + }), + dict({ + 'type': 'water', + 'value': '5,0', + }), + ]), + }), + dict({ + 'date': dict({ + 'month': 4, + 'year': 2024, + }), + 'readings': list([ + dict({ + 'additionalValue': '113,0', + 'type': 'heating', + 'value': '104', + }), + dict({ + 'additionalValue': '61,1', + 'type': 'warmwater', + 'value': '1,1', + }), + dict({ + 'type': 'water', + 'value': '6,8', + }), + ]), + }), + ]), + 'costs': list([ + dict({ + 'costsByEnergyType': list([ + dict({ + 'type': 'heating', + 'value': 21, + }), + dict({ + 'type': 'warmwater', + 'value': 7, + }), + dict({ + 'type': 'water', + 'value': 3, + }), + ]), + 'date': dict({ + 'month': 5, + 'year': 2024, + }), + }), + dict({ + 'costsByEnergyType': list([ + dict({ + 'type': 'heating', + 'value': 62, + }), + dict({ + 'type': 'warmwater', + 'value': 7, + }), + dict({ + 'type': 'water', + 'value': 2, + }), + ]), + 'date': dict({ + 'month': 4, + 'year': 2024, + }), + }), + ]), + }), + 'eaf5c5c8-889f-4a3c-b68c-e9a676505762': dict({ + 'consumptionUnitId': 'eaf5c5c8-889f-4a3c-b68c-e9a676505762', + 'consumptions': list([ + dict({ + 'date': dict({ + 'month': 5, + 'year': 2024, + }), + 'readings': list([ + dict({ + 'additionalValue': '38,0', + 'type': 'heating', + 'value': '35', + }), + dict({ + 'additionalValue': '57,0', + 'type': 'warmwater', + 'value': '1,0', + }), + dict({ + 'type': 'water', + 'value': '5,0', + }), + ]), + }), + dict({ + 'date': dict({ + 'month': 4, + 'year': 2024, + }), + 'readings': list([ + dict({ + 'additionalValue': '113,0', + 'type': 'heating', + 'value': '104', + }), + dict({ + 'additionalValue': '61,1', + 'type': 'warmwater', + 'value': '1,1', + }), + dict({ + 'type': 'water', + 'value': '6,8', + }), + ]), + }), + ]), + 'costs': list([ + dict({ + 'costsByEnergyType': list([ + dict({ + 'type': 'heating', + 'value': 21, + }), + dict({ + 'type': 'warmwater', + 'value': 7, + }), + dict({ + 'type': 'water', + 'value': 3, + }), + ]), + 'date': dict({ + 'month': 5, + 'year': 2024, + }), + }), + dict({ + 'costsByEnergyType': list([ + dict({ + 'type': 'heating', + 'value': 62, + }), + dict({ + 'type': 'warmwater', + 'value': 7, + }), + dict({ + 'type': 'water', + 'value': 2, + }), + ]), + 'date': dict({ + 'month': 4, + 'year': 2024, + }), + }), + ]), + }), + }), + 'details': dict({ + '26e93f1a-c828-11ea-87d0-0242ac130003': dict({ + 'address': dict({ + 'houseNumber': '**REDACTED**', + 'street': '**REDACTED**', + }), + 'id': '26e93f1a-c828-11ea-87d0-0242ac130003', + }), + 'eaf5c5c8-889f-4a3c-b68c-e9a676505762': dict({ + 'address': dict({ + 'houseNumber': '**REDACTED**', + 'street': '**REDACTED**', + }), + 'id': 'eaf5c5c8-889f-4a3c-b68c-e9a676505762', + }), + }), + }) +# --- diff --git a/tests/components/ista_ecotrend/test_diagnostics.py b/tests/components/ista_ecotrend/test_diagnostics.py new file mode 100644 index 00000000000..83e28b0b7f8 --- /dev/null +++ b/tests/components/ista_ecotrend/test_diagnostics.py @@ -0,0 +1,27 @@ +"""Tests for ista EcoTrend diagnostics platform .""" + +import pytest +from syrupy.assertion import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator + + +@pytest.mark.usefixtures("mock_ista") +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + ista_config_entry: MockConfigEntry, + snapshot: SnapshotAssertion, +) -> None: + """Test diagnostics.""" + ista_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(ista_config_entry.entry_id) + await hass.async_block_till_done() + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, ista_config_entry) + == snapshot + )