From c7cb5088961bb5caaad97ad79749d4b5cb4bc89f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 24 Dec 2023 02:34:36 +0100 Subject: [PATCH] Add diagnostics to ccm15 (#106329) * Add diagnostics to ccm15 * Update homeassistant/components/ccm15/diagnostics.py Co-authored-by: J. Nick Koston --------- Co-authored-by: J. Nick Koston --- homeassistant/components/ccm15/diagnostics.py | 35 ++++++++++++++++++ .../ccm15/snapshots/test_diagnostics.ambr | 33 +++++++++++++++++ tests/components/ccm15/test_diagnostics.py | 37 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 homeassistant/components/ccm15/diagnostics.py create mode 100644 tests/components/ccm15/snapshots/test_diagnostics.ambr create mode 100644 tests/components/ccm15/test_diagnostics.py diff --git a/homeassistant/components/ccm15/diagnostics.py b/homeassistant/components/ccm15/diagnostics.py new file mode 100644 index 000000000000..b4a3c80f319c --- /dev/null +++ b/homeassistant/components/ccm15/diagnostics.py @@ -0,0 +1,35 @@ +"""Diagnostics support for CCM15.""" +from __future__ import annotations + +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from .const import DOMAIN +from .coordinator import CCM15Coordinator + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, config_entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: CCM15Coordinator = hass.data[DOMAIN][config_entry.entry_id] + + return { + str(device_id): { + "is_celsius": device.is_celsius, + "locked_cool_temperature": device.locked_cool_temperature, + "locked_heat_temperature": device.locked_heat_temperature, + "locked_ac_mode": device.locked_ac_mode, + "error_code": device.error_code, + "ac_mode": device.ac_mode, + "fan_mode": device.fan_mode, + "is_ac_mode_locked": device.is_ac_mode_locked, + "temperature_setpoint": device.temperature_setpoint, + "fan_locked": device.fan_locked, + "is_remote_locked": device.is_remote_locked, + "temperature": device.temperature, + } + for device_id, device in coordinator.data.devices.items() + } diff --git a/tests/components/ccm15/snapshots/test_diagnostics.ambr b/tests/components/ccm15/snapshots/test_diagnostics.ambr new file mode 100644 index 000000000000..c6b2f9c371e0 --- /dev/null +++ b/tests/components/ccm15/snapshots/test_diagnostics.ambr @@ -0,0 +1,33 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + '0': dict({ + 'ac_mode': 4, + 'error_code': 0, + 'fan_locked': False, + 'fan_mode': 5, + 'is_ac_mode_locked': False, + 'is_celsius': True, + 'is_remote_locked': False, + 'locked_ac_mode': 0, + 'locked_cool_temperature': 0, + 'locked_heat_temperature': 0, + 'temperature': 27, + 'temperature_setpoint': 23, + }), + '1': dict({ + 'ac_mode': 0, + 'error_code': 0, + 'fan_locked': False, + 'fan_mode': 2, + 'is_ac_mode_locked': False, + 'is_celsius': True, + 'is_remote_locked': False, + 'locked_ac_mode': 0, + 'locked_cool_temperature': 0, + 'locked_heat_temperature': 0, + 'temperature': 26, + 'temperature_setpoint': 24, + }), + }) +# --- diff --git a/tests/components/ccm15/test_diagnostics.py b/tests/components/ccm15/test_diagnostics.py new file mode 100644 index 000000000000..3700faa51ce7 --- /dev/null +++ b/tests/components/ccm15/test_diagnostics.py @@ -0,0 +1,37 @@ +"""Test CCM15 diagnostics.""" +from unittest.mock import AsyncMock + +from syrupy import SnapshotAssertion + +from homeassistant.components.ccm15.const import DOMAIN +from homeassistant.const import CONF_HOST, CONF_PORT +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 + + +async def test_entry_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + ccm15_device: AsyncMock, + snapshot: SnapshotAssertion, +) -> None: + """Test config entry diagnostics.""" + entry = MockConfigEntry( + domain=DOMAIN, + unique_id="1.1.1.1", + data={ + CONF_HOST: "1.1.1.1", + CONF_PORT: 80, + }, + ) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + result = await get_diagnostics_for_config_entry(hass, hass_client, entry) + + assert result == snapshot