From 22db1efbdef90fac2e3718cc9deaa1b693f05c05 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 28 Oct 2026 15:21:15 +0100 Subject: [PATCH] Add diagnostics to Gree Climate (#189137) Co-authored-by: Claude --- homeassistant/components/gree/diagnostics.py | 27 ++++++++++++ .../gree/snapshots/test_diagnostics.ambr | 26 ++++++++++++ tests/components/gree/test_diagnostics.py | 41 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 homeassistant/components/gree/diagnostics.py create mode 100644 tests/components/gree/snapshots/test_diagnostics.ambr create mode 100644 tests/components/gree/test_diagnostics.py diff --git a/homeassistant/components/gree/diagnostics.py b/homeassistant/components/gree/diagnostics.py new file mode 100644 index 000000000000..1468d8bc38a4 --- /dev/null +++ b/homeassistant/components/gree/diagnostics.py @@ -0,0 +1,27 @@ +"""Diagnostics support for Gree Climate.""" + +from typing import Any + +from homeassistant.core import HomeAssistant + +from .coordinator import GreeConfigEntry + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: GreeConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + return { + "devices": [ + { + "brand": coordinator.device.device_info.brand, + "model": coordinator.device.device_info.model, + "info_version": coordinator.device.device_info.version, + "hid": coordinator.device.hid, + "version": coordinator.device.version, + "last_update_success": coordinator.last_update_success, + "raw_properties": coordinator.data, + } + for coordinator in entry.runtime_data.coordinators + ] + } diff --git a/tests/components/gree/snapshots/test_diagnostics.ambr b/tests/components/gree/snapshots/test_diagnostics.ambr new file mode 100644 index 000000000000..9ee6e98b96f3 --- /dev/null +++ b/tests/components/gree/snapshots/test_diagnostics.ambr @@ -0,0 +1,26 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'devices': list([ + dict({ + 'brand': 'gree', + 'hid': '362001000762+U-CS532AE(LT)V3.31.bin', + 'info_version': 'V1.2.1', + 'last_update_success': True, + 'model': 'gree', + 'raw_properties': dict({ + 'Lig': 1, + 'Mod': 1, + 'Pow': 1, + 'Quiet': 0, + 'SetTem': 22, + 'TemSen': 64, + 'TemUn': 0, + 'Tur': 0, + 'WdSpd': 0, + }), + 'version': '3.31', + }), + ]), + }) +# --- diff --git a/tests/components/gree/test_diagnostics.py b/tests/components/gree/test_diagnostics.py new file mode 100644 index 000000000000..d3baf61c928d --- /dev/null +++ b/tests/components/gree/test_diagnostics.py @@ -0,0 +1,41 @@ +"""Tests for the Gree Climate diagnostics.""" + +from unittest.mock import MagicMock + +from pytest_homeassistant.components.diagnostics import get_diagnostics_for_config_entry +from pytest_homeassistant.typing import ClientSessionGenerator +from syrupy.assertion import SnapshotAssertion + +from homeassistant.core import HomeAssistant + +from .common import async_setup_gree + + +async def test_entry_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + device: MagicMock, + snapshot: SnapshotAssertion, +) -> None: + """Test config entry diagnostics.""" + mock_device = device.return_value + mock_device.device_info.brand = "gree" + mock_device.device_info.model = "gree" + mock_device.device_info.version = "V1.2.1" + mock_device.hid = "362001000762+U-CS532AE(LT)V3.31.bin" + mock_device.version = "3.31" + mock_device.raw_properties = { + "Pow": 1, + "Mod": 1, + "SetTem": 22, + "TemSen": 64, + "TemUn": 0, + "WdSpd": 0, + "Lig": 1, + "Quiet": 0, + "Tur": 0, + } + + entry = await async_setup_gree(hass) + + assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot