From d554a828756dabe468c4fd8ebf5483b473bc5346 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 21 Feb 2022 20:53:41 -1000 Subject: [PATCH] Add diagnostics support to flux_led (#67012) --- .../components/flux_led/diagnostics.py | 24 +++++++++++ .../components/flux_led/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/flux_led/__init__.py | 1 + tests/components/flux_led/test_diagnostics.py | 40 +++++++++++++++++++ 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/flux_led/diagnostics.py create mode 100644 tests/components/flux_led/test_diagnostics.py diff --git a/homeassistant/components/flux_led/diagnostics.py b/homeassistant/components/flux_led/diagnostics.py new file mode 100644 index 00000000000..f0c95ffbe56 --- /dev/null +++ b/homeassistant/components/flux_led/diagnostics.py @@ -0,0 +1,24 @@ +"""Diagnostics support for flux_led.""" +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 FluxLedUpdateCoordinator + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + coordinator: FluxLedUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] + return { + "entry": { + "title": entry.title, + "data": dict(entry.data), + }, + "data": coordinator.device.diagnostics, + } diff --git a/homeassistant/components/flux_led/manifest.json b/homeassistant/components/flux_led/manifest.json index 9f1d307c14a..a1b541c177d 100644 --- a/homeassistant/components/flux_led/manifest.json +++ b/homeassistant/components/flux_led/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "dependencies": ["network"], "documentation": "https://www.home-assistant.io/integrations/flux_led", - "requirements": ["flux_led==0.28.26"], + "requirements": ["flux_led==0.28.27"], "quality_scale": "platinum", "codeowners": ["@icemanch", "@bdraco"], "iot_class": "local_push", diff --git a/requirements_all.txt b/requirements_all.txt index ef0210e3067..57798e31ad9 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -679,7 +679,7 @@ fjaraskupan==1.0.2 flipr-api==1.4.1 # homeassistant.components.flux_led -flux_led==0.28.26 +flux_led==0.28.27 # homeassistant.components.homekit fnvhash==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index fe0f3a638bf..93d1a4d060e 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -434,7 +434,7 @@ fjaraskupan==1.0.2 flipr-api==1.4.1 # homeassistant.components.flux_led -flux_led==0.28.26 +flux_led==0.28.27 # homeassistant.components.homekit fnvhash==0.1.0 diff --git a/tests/components/flux_led/__init__.py b/tests/components/flux_led/__init__.py index e1abebd40f1..65fb704e4c7 100644 --- a/tests/components/flux_led/__init__.py +++ b/tests/components/flux_led/__init__.py @@ -110,6 +110,7 @@ def _mocked_bulb() -> AIOWifiLedBulb: bulb.paired_remotes = 2 bulb.pixels_per_segment = 300 bulb.segments = 2 + bulb.diagnostics = {"mock_diag": "mock_diag"} bulb.music_pixels_per_segment = 150 bulb.music_segments = 4 bulb.operating_mode = "RGB&W" diff --git a/tests/components/flux_led/test_diagnostics.py b/tests/components/flux_led/test_diagnostics.py new file mode 100644 index 00000000000..c641d88c8e2 --- /dev/null +++ b/tests/components/flux_led/test_diagnostics.py @@ -0,0 +1,40 @@ +"""Test flux_led diagnostics.""" +from homeassistant.components.flux_led.const import DOMAIN +from homeassistant.setup import async_setup_component + +from . import ( + _mock_config_entry_for_bulb, + _mocked_bulb, + _patch_discovery, + _patch_wifibulb, +) + +from tests.components.diagnostics import get_diagnostics_for_config_entry + + +async def test_diagnostics(hass, hass_client): + """Test generating diagnostics for a config entry.""" + entry = _mock_config_entry_for_bulb(hass) + bulb = _mocked_bulb() + with _patch_discovery(), _patch_wifibulb(device=bulb): + await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) + await hass.async_block_till_done() + diag = await get_diagnostics_for_config_entry(hass, hass_client, entry) + assert diag == { + "data": {"mock_diag": "mock_diag"}, + "entry": { + "data": { + "host": "127.0.0.1", + "minor_version": 4, + "model": "AK001-ZJ2149", + "model_description": "Bulb RGBCW", + "model_info": "AK001-ZJ2149", + "model_num": 53, + "name": "Bulb RGBCW DDEEFF", + "remote_access_enabled": True, + "remote_access_host": "the.cloud", + "remote_access_port": 8816, + }, + "title": "Mock Title", + }, + }