Compare commits

...

7 Commits

Author SHA1 Message Date
Ludeeus
9ee83c8b95 fix dark api 2022-06-24 09:21:08 +00:00
Ludeeus
a5f8f68add fix icon 2022-06-24 09:19:34 +00:00
Ludeeus
381b73b4b8 update store API 2022-06-24 09:16:53 +00:00
Ludeeus
08af296c86 Merge branch 'main' of https://github.com/home-assistant/supervisor into dark_icon-suport 2022-06-24 09:13:44 +00:00
Ludeeus
11995e73ca Use dedicated endpoints 2022-06-10 07:41:56 +00:00
Ludeeus
20a6c53c2d logo as well 2022-06-10 07:21:53 +00:00
Ludeeus
0073660bdf Add support for dark_icon 2022-06-10 07:13:06 +00:00
4 changed files with 107 additions and 3 deletions

View File

@@ -478,11 +478,21 @@ class AddonModel(CoreSysAttributes, ABC):
"""Return True if an icon exists."""
return self.path_icon.exists()
@property
def with_dark_icon(self) -> bool:
"""Return True if an dark icon exists."""
return self.path_dark_icon.exists()
@property
def with_logo(self) -> bool:
"""Return True if a logo exists."""
return self.path_logo.exists()
@property
def with_dark_logo(self) -> bool:
"""Return True if a dark logo exists."""
return self.path_dark_logo.exists()
@property
def with_changelog(self) -> bool:
"""Return True if a changelog exists."""
@@ -543,11 +553,21 @@ class AddonModel(CoreSysAttributes, ABC):
"""Return path to add-on icon."""
return Path(self.path_location, "icon.png")
@property
def path_dark_icon(self) -> Path:
"""Return path to the dark variant of the add-on icon."""
return Path(self.path_location, "dark_icon.png")
@property
def path_logo(self) -> Path:
"""Return path to add-on logo."""
return Path(self.path_location, "logo.png")
@property
def path_dark_logo(self) -> Path:
"""Return path to the dark variant of the add-on logo."""
return Path(self.path_location, "dark_logo.png")
@property
def path_changelog(self) -> Path:
"""Return path to add-on changelog."""

View File

@@ -379,6 +379,10 @@ class RestAPI(CoreSysAttributes):
[
web.get("/addons", api_addons.list),
web.get("/addons/{addon}/info", api_addons.info),
web.get("/addons/{addon}/icon", api_addons.icon),
web.get("/addons/{addon}/dark_icon", api_addons.dark_icon),
web.get("/addons/{addon}/logo", api_addons.logo),
web.get("/addons/{addon}/dark_logo", api_addons.dark_logo),
web.post("/addons/{addon}/uninstall", api_addons.uninstall),
web.post("/addons/{addon}/start", api_addons.start),
web.post("/addons/{addon}/stop", api_addons.stop),
@@ -513,6 +517,12 @@ class RestAPI(CoreSysAttributes):
web.get("/store/addons/{addon}/{version}", api_store.addons_addon_info),
web.get("/store/addons/{addon}/icon", api_store.addons_addon_icon),
web.get("/store/addons/{addon}/logo", api_store.addons_addon_logo),
web.get(
"/store/addons/{addon}/dark_icon", api_store.addons_addon_dark_icon
),
web.get(
"/store/addons/{addon}/dark_logo", api_store.addons_addon_dark_logo
),
web.get(
"/store/addons/{addon}/changelog", api_store.addons_addon_changelog
),
@@ -551,8 +561,6 @@ class RestAPI(CoreSysAttributes):
web.post("/addons/reload", api_store.reload),
web.post("/addons/{addon}/install", api_store.addons_addon_install),
web.post("/addons/{addon}/update", api_store.addons_addon_update),
web.get("/addons/{addon}/icon", api_store.addons_addon_icon),
web.get("/addons/{addon}/logo", api_store.addons_addon_logo),
web.get("/addons/{addon}/changelog", api_store.addons_addon_changelog),
web.get(
"/addons/{addon}/documentation",

View File

@@ -98,7 +98,7 @@ from ..coresys import CoreSysAttributes
from ..docker.stats import DockerStats
from ..exceptions import APIError, APIForbidden, PwnedError, PwnedSecret
from ..validate import docker_ports
from .const import ATTR_SIGNED, CONTENT_TYPE_BINARY
from .const import ATTR_SIGNED, CONTENT_TYPE_BINARY, CONTENT_TYPE_PNG
from .utils import api_process, api_process_raw, api_validate, json_loads
_LOGGER: logging.Logger = logging.getLogger(__name__)
@@ -412,6 +412,54 @@ class APIAddons(CoreSysAttributes):
addon = self._extract_addon(request)
return addon.logs()
@api_process_raw(CONTENT_TYPE_PNG)
async def icon(self, request: web.Request) -> bytes:
"""Return icon from add-on."""
addon = self._extract_addon(request)
if not addon.with_icon:
raise APIError(f"No icon found for add-on {addon.slug}!")
with addon.path_icon.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_PNG)
async def dark_icon(self, request: web.Request) -> bytes:
"""Return dark icon from add-on."""
addon = self._extract_addon(request)
if not addon.with_icon:
raise APIError(f"No icon found for add-on {addon.slug}!")
if addon.with_dark_icon:
with addon.path_dark_icon.open("rb") as png:
return png.read()
with addon.path_icon.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_PNG)
async def logo(self, request: web.Request) -> bytes:
"""Return logo from add-on."""
addon = self._extract_addon(request)
if not addon.with_logo:
raise APIError(f"No logo found for add-on {addon.slug}!")
with addon.path_logo.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_PNG)
async def dark_logo(self, request: web.Request) -> bytes:
"""Return dark logo from add-on."""
addon = self._extract_addon(request)
if not addon.with_logo:
raise APIError(f"No logo found for add-on {addon.slug}!")
if addon.with_dark_logo:
with addon.path_dark_logo.open("rb") as png:
return png.read()
with addon.path_logo.open("rb") as png:
return png.read()
@api_process
async def stdin(self, request: web.Request) -> None:
"""Write to stdin of add-on."""

View File

@@ -217,6 +217,20 @@ class APIStore(CoreSysAttributes):
with addon.path_icon.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_PNG)
async def addons_addon_dark_icon(self, request: web.Request) -> bytes:
"""Return dark icon from add-on."""
addon = self._extract_addon(request)
if not addon.with_icon:
raise APIError(f"No icon found for add-on {addon.slug}!")
if addon.with_dark_icon:
with addon.path_dark_icon.open("rb") as png:
return png.read()
with addon.path_icon.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_PNG)
async def addons_addon_logo(self, request: web.Request) -> bytes:
"""Return logo from add-on."""
@@ -227,6 +241,20 @@ class APIStore(CoreSysAttributes):
with addon.path_logo.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_PNG)
async def addons_addon_dark_logo(self, request: web.Request) -> bytes:
"""Return dark logo from add-on."""
addon = self._extract_addon(request)
if not addon.with_logo:
raise APIError(f"No logo found for add-on {addon.slug}!")
if addon.with_dark_logo:
with addon.path_dark_logo.open("rb") as png:
return png.read()
with addon.path_logo.open("rb") as png:
return png.read()
@api_process_raw(CONTENT_TYPE_TEXT)
async def addons_addon_changelog(self, request: web.Request) -> str:
"""Return changelog from add-on."""