From db8d4053d668e8c63b63e8d5c3260a1dd6fe013e Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Tue, 2 Jun 2020 20:11:23 +0200 Subject: [PATCH] Add supervisor get addon info helper (#36260) --- homeassistant/components/hassio/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index bb4663a9654..0bd766589a1 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -17,6 +17,7 @@ from homeassistant.const import ( from homeassistant.core import DOMAIN as HASS_DOMAIN, callback from homeassistant.exceptions import HomeAssistantError import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.typing import HomeAssistantType from homeassistant.loader import bind_hass from homeassistant.util.dt import utcnow @@ -124,6 +125,21 @@ MAP_SERVICE_API = { } +@bind_hass +async def async_get_addon_info(hass: HomeAssistantType, addon_id: str) -> dict: + """Return add-on info. + + The addon_id is a snakecased concatenation of the 'repository' value + found in the add-on info and the 'slug' value found in the add-on config.json. + In the add-on info the addon_id is called 'slug'. + + The caller of the function should handle HassioAPIError. + """ + hassio = hass.data[DOMAIN] + result = await hassio.get_addon_info(addon_id) + return result["data"] + + @callback @bind_hass def get_homeassistant_version(hass):