diff --git a/API.md b/API.md index 61fc65566..0c119b5f6 100644 --- a/API.md +++ b/API.md @@ -518,6 +518,7 @@ Get all available addons. "icon": "bool", "logo": "bool", "changelog": "bool", + "documentation": "bool", "hassio_api": "bool", "hassio_role": "default|homeassistant|manager|admin", "homeassistant_api": "bool", @@ -551,6 +552,8 @@ Get all available addons. - GET `/addons/{addon}/changelog` +- GET `/addons/{addon}/documentation` + - POST `/addons/{addon}/options` ```json diff --git a/hassio/addons/model.py b/hassio/addons/model.py index 6cc799b44..faf8a8c17 100644 --- a/hassio/addons/model.py +++ b/hassio/addons/model.py @@ -405,6 +405,11 @@ class AddonModel(CoreSysAttributes): """Return True if a changelog exists.""" return self.path_changelog.exists() + @property + def with_documentation(self) -> bool: + """Return True if a documentation exists.""" + return self.path_documentation.exists() + @property def supported_arch(self) -> List[str]: """Return list of supported arch.""" @@ -455,6 +460,11 @@ class AddonModel(CoreSysAttributes): """Return path to add-on changelog.""" return Path(self.path_location, "CHANGELOG.md") + @property + def path_documentation(self) -> Path: + """Return path to add-on changelog.""" + return Path(self.path_location, "DOCS.md") + @property def path_apparmor(self) -> Path: """Return path to custom AppArmor profile.""" diff --git a/hassio/api/__init__.py b/hassio/api/__init__.py index 864fd5419..34af475f2 100644 --- a/hassio/api/__init__.py +++ b/hassio/api/__init__.py @@ -201,6 +201,7 @@ class RestAPI(CoreSysAttributes): web.get("/addons/{addon}/icon", api_addons.icon), web.get("/addons/{addon}/logo", api_addons.logo), web.get("/addons/{addon}/changelog", api_addons.changelog), + web.get("/addons/{addon}/documentation", api_addons.documentation), web.post("/addons/{addon}/stdin", api_addons.stdin), web.post("/addons/{addon}/security", api_addons.security), web.get("/addons/{addon}/stats", api_addons.stats), diff --git a/hassio/api/addons.py b/hassio/api/addons.py index 18c7a5be3..01d0ead33 100644 --- a/hassio/api/addons.py +++ b/hassio/api/addons.py @@ -7,7 +7,6 @@ from aiohttp import web import voluptuous as vol from ..addons import AnyAddon -from ..docker.stats import DockerStats from ..addons.utils import rating_security from ..const import ( ATTR_ADDONS, @@ -32,6 +31,7 @@ from ..const import ( ATTR_DISCOVERY, ATTR_DNS, ATTR_DOCKER_API, + ATTR_DOCUMENTATION, ATTR_FULL_ACCESS, ATTR_GPIO, ATTR_HASSIO_API, @@ -89,8 +89,9 @@ from ..const import ( STATE_NONE, ) from ..coresys import CoreSysAttributes +from ..docker.stats import DockerStats from ..exceptions import APIError -from ..validate import alsa_device, DOCKER_PORTS +from ..validate import DOCKER_PORTS, alsa_device from .utils import api_process, api_process_raw, api_validate _LOGGER: logging.Logger = logging.getLogger(__name__) @@ -217,6 +218,7 @@ class APIAddons(CoreSysAttributes): ATTR_ICON: addon.with_icon, ATTR_LOGO: addon.with_logo, ATTR_CHANGELOG: addon.with_changelog, + ATTR_DOCUMENTATION: addon.with_documentation, ATTR_STDIN: addon.with_stdin, ATTR_WEBUI: None, ATTR_HASSIO_API: addon.access_hassio_api, @@ -407,6 +409,16 @@ class APIAddons(CoreSysAttributes): with addon.path_changelog.open("r") as changelog: return changelog.read() + @api_process_raw(CONTENT_TYPE_TEXT) + async def documentation(self, request: web.Request) -> str: + """Return documentation from add-on.""" + addon: AnyAddon = self._extract_addon(request, check_installed=False) + if not addon.with_documentation: + raise APIError("No documentation found!") + + with addon.path_documentation.open("r") as documentation: + return documentation.read() + @api_process async def stdin(self, request: web.Request) -> None: """Write to stdin of add-on.""" diff --git a/hassio/const.py b/hassio/const.py index 43d9d0cba..ab0ac20c5 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -222,6 +222,7 @@ ATTR_LOCALS = "locals" ATTR_UDEV = "udev" ATTR_VALUE = "value" ATTR_SNAPSHOT_EXCLUDE = "snapshot_exclude" +ATTR_DOCUMENTATION = "documentation" PROVIDE_SERVICE = "provide" NEED_SERVICE = "need"