From 6c54267f578c999fefed335bdf18873df6d04fb7 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 23 Jan 2022 09:02:14 +0100 Subject: [PATCH] Add diagnostics support to Elgato (#64652) --- .../components/elgato/diagnostics.py | 21 +++++++++++ tests/components/elgato/test_diagnostics.py | 35 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 homeassistant/components/elgato/diagnostics.py create mode 100644 tests/components/elgato/test_diagnostics.py diff --git a/homeassistant/components/elgato/diagnostics.py b/homeassistant/components/elgato/diagnostics.py new file mode 100644 index 00000000000..4871d79a1b9 --- /dev/null +++ b/homeassistant/components/elgato/diagnostics.py @@ -0,0 +1,21 @@ +"""Diagnostics support for Elgato.""" +from __future__ import annotations + +from typing import Any + +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from . import HomeAssistantElgatoData +from .const import DOMAIN + + +async def async_get_config_entry_diagnostics( + hass: HomeAssistant, entry: ConfigEntry +) -> dict[str, Any]: + """Return diagnostics for a config entry.""" + data: HomeAssistantElgatoData = hass.data[DOMAIN][entry.entry_id] + return { + "info": data.info.dict(), + "state": data.coordinator.data.dict(), + } diff --git a/tests/components/elgato/test_diagnostics.py b/tests/components/elgato/test_diagnostics.py new file mode 100644 index 00000000000..4ea543a487b --- /dev/null +++ b/tests/components/elgato/test_diagnostics.py @@ -0,0 +1,35 @@ +"""Tests for the diagnostics data provided by the Elgato integration.""" +from aiohttp import ClientSession + +from homeassistant.core import HomeAssistant + +from tests.common import MockConfigEntry +from tests.components.diagnostics import get_diagnostics_for_config_entry + + +async def test_diagnostics( + hass: HomeAssistant, + hass_client: ClientSession, + init_integration: MockConfigEntry, +): + """Test diagnostics.""" + assert await get_diagnostics_for_config_entry( + hass, hass_client, init_integration + ) == { + "info": { + "display_name": "Frenck", + "firmware_build_number": 192, + "firmware_version": "1.0.3", + "hardware_board_type": 53, + "product_name": "Elgato Key Light", + "serial_number": "CN11A1A00001", + "features": ["lights"], + }, + "state": { + "on": True, + "brightness": 21, + "hue": None, + "saturation": None, + "temperature": 297, + }, + }