diff --git a/homeassistant/components/hue/diagnostics.py b/homeassistant/components/hue/diagnostics.py new file mode 100644 index 00000000000..17f00a50bbe --- /dev/null +++ b/homeassistant/components/hue/diagnostics.py @@ -0,0 +1,22 @@ +"""Diagnostics support for Hue.""" +from __future__ import annotations + +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from .bridge import HueBridge +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + bridge: HueBridge = hass.data[DOMAIN][entry.entry_id] + if bridge.api_version == 1: + # diagnostics is only implemented for V2 bridges. + return {} + # Hue diagnostics are already redacted + return await bridge.api.get_diagnostics() diff --git a/tests/components/hue/test_diagnostics.py b/tests/components/hue/test_diagnostics.py new file mode 100644 index 00000000000..8ccc91a5d19 --- /dev/null +++ b/tests/components/hue/test_diagnostics.py @@ -0,0 +1,22 @@ +"""Test Hue diagnostics.""" + +from .conftest import setup_platform + +from tests.components.diagnostics import get_diagnostics_for_config_entry + + +async def test_diagnostics_v1(hass, hass_client, mock_bridge_v1): + """Test diagnostics v1.""" + await setup_platform(hass, mock_bridge_v1, []) + config_entry = hass.config_entries.async_entries("hue")[0] + result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + assert result == {} + + +async def test_diagnostics_v2(hass, hass_client, mock_bridge_v2): + """Test diagnostics v2.""" + mock_bridge_v2.api.get_diagnostics.return_value = {"hello": "world"} + await setup_platform(hass, mock_bridge_v2, []) + config_entry = hass.config_entries.async_entries("hue")[0] + result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + assert result == {"hello": "world"}