From 874ece195e6064bd8f4585e7b936cd5ee1c3f673 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 10 Nov 2022 13:19:21 +0100 Subject: [PATCH] Include config entry id in response to WS API hardware/info (#81906) --- homeassistant/components/hardkernel/hardware.py | 5 +++++ homeassistant/components/hardware/models.py | 1 + .../components/homeassistant_sky_connect/hardware.py | 1 + homeassistant/components/homeassistant_yellow/hardware.py | 7 +++++++ homeassistant/components/raspberry_pi/hardware.py | 5 +++++ tests/components/hardkernel/test_hardware.py | 1 + .../components/homeassistant_sky_connect/test_hardware.py | 2 ++ tests/components/homeassistant_yellow/test_hardware.py | 1 + tests/components/raspberry_pi/test_hardware.py | 1 + 9 files changed, 24 insertions(+) diff --git a/homeassistant/components/hardkernel/hardware.py b/homeassistant/components/hardkernel/hardware.py index 47ff5830a84..eca599960f8 100644 --- a/homeassistant/components/hardkernel/hardware.py +++ b/homeassistant/components/hardkernel/hardware.py @@ -27,6 +27,10 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: if not board.startswith("odroid"): raise HomeAssistantError + config_entries = [ + entry.entry_id for entry in hass.config_entries.async_entries(DOMAIN) + ] + return [ HardwareInfo( board=BoardInfo( @@ -35,6 +39,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: model=board, revision=None, ), + config_entries=config_entries, dongle=None, name=BOARD_NAMES.get(board, f"Unknown hardkernel Odroid model '{board}'"), url=None, diff --git a/homeassistant/components/hardware/models.py b/homeassistant/components/hardware/models.py index 8ce5e7be7f3..801bc9b923a 100644 --- a/homeassistant/components/hardware/models.py +++ b/homeassistant/components/hardware/models.py @@ -34,6 +34,7 @@ class HardwareInfo: name: str | None board: BoardInfo | None + config_entries: list[str] | None dongle: USBInfo | None url: str | None diff --git a/homeassistant/components/homeassistant_sky_connect/hardware.py b/homeassistant/components/homeassistant_sky_connect/hardware.py index 6eceb746756..f48e1763dd5 100644 --- a/homeassistant/components/homeassistant_sky_connect/hardware.py +++ b/homeassistant/components/homeassistant_sky_connect/hardware.py @@ -17,6 +17,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: return [ HardwareInfo( board=None, + config_entries=[entry.entry_id], dongle=USBInfo( vid=entry.data["vid"], pid=entry.data["pid"], diff --git a/homeassistant/components/homeassistant_yellow/hardware.py b/homeassistant/components/homeassistant_yellow/hardware.py index ad17eccfe7f..b67eb50ff2c 100644 --- a/homeassistant/components/homeassistant_yellow/hardware.py +++ b/homeassistant/components/homeassistant_yellow/hardware.py @@ -6,6 +6,8 @@ from homeassistant.components.hassio import get_os_info from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError +from .const import DOMAIN + BOARD_NAME = "Home Assistant Yellow" MANUFACTURER = "homeassistant" MODEL = "yellow" @@ -22,6 +24,10 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: if not board == "yellow": raise HomeAssistantError + config_entries = [ + entry.entry_id for entry in hass.config_entries.async_entries(DOMAIN) + ] + return [ HardwareInfo( board=BoardInfo( @@ -30,6 +36,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: model=MODEL, revision=None, ), + config_entries=config_entries, dongle=None, name=BOARD_NAME, url=None, diff --git a/homeassistant/components/raspberry_pi/hardware.py b/homeassistant/components/raspberry_pi/hardware.py index 6433b15adb5..61417f751ac 100644 --- a/homeassistant/components/raspberry_pi/hardware.py +++ b/homeassistant/components/raspberry_pi/hardware.py @@ -42,6 +42,10 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: if not board.startswith("rpi"): raise HomeAssistantError + config_entries = [ + entry.entry_id for entry in hass.config_entries.async_entries(DOMAIN) + ] + return [ HardwareInfo( board=BoardInfo( @@ -50,6 +54,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: model=MODELS.get(board), revision=None, ), + config_entries=config_entries, dongle=None, name=BOARD_NAMES.get(board, f"Unknown Raspberry Pi model '{board}'"), url=None, diff --git a/tests/components/hardkernel/test_hardware.py b/tests/components/hardkernel/test_hardware.py index 33602f92e3f..e35c94e4926 100644 --- a/tests/components/hardkernel/test_hardware.py +++ b/tests/components/hardkernel/test_hardware.py @@ -48,6 +48,7 @@ async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None: "model": "odroid-n2", "revision": None, }, + "config_entries": [config_entry.entry_id], "dongle": None, "name": "Home Assistant Blue / Hardkernel Odroid-N2", "url": None, diff --git a/tests/components/homeassistant_sky_connect/test_hardware.py b/tests/components/homeassistant_sky_connect/test_hardware.py index 6226651133a..2ba305afb4a 100644 --- a/tests/components/homeassistant_sky_connect/test_hardware.py +++ b/tests/components/homeassistant_sky_connect/test_hardware.py @@ -62,6 +62,7 @@ async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None: "hardware": [ { "board": None, + "config_entries": [config_entry.entry_id], "dongle": { "vid": "bla_vid", "pid": "bla_pid", @@ -74,6 +75,7 @@ async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None: }, { "board": None, + "config_entries": [config_entry_2.entry_id], "dongle": { "vid": "bla_vid_2", "pid": "bla_pid_2", diff --git a/tests/components/homeassistant_yellow/test_hardware.py b/tests/components/homeassistant_yellow/test_hardware.py index 45d6fcabdfe..681c031b2e1 100644 --- a/tests/components/homeassistant_yellow/test_hardware.py +++ b/tests/components/homeassistant_yellow/test_hardware.py @@ -48,6 +48,7 @@ async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None: "model": "yellow", "revision": None, }, + "config_entries": [config_entry.entry_id], "dongle": None, "name": "Home Assistant Yellow", "url": None, diff --git a/tests/components/raspberry_pi/test_hardware.py b/tests/components/raspberry_pi/test_hardware.py index c36fcbd1642..0f672ef98db 100644 --- a/tests/components/raspberry_pi/test_hardware.py +++ b/tests/components/raspberry_pi/test_hardware.py @@ -48,6 +48,7 @@ async def test_hardware_info(hass: HomeAssistant, hass_ws_client) -> None: "model": "1", "revision": None, }, + "config_entries": [config_entry.entry_id], "dongle": None, "name": "Raspberry Pi", "url": None,