Add supervisor set add-on options helper (#41651)
This commit is contained in:
parent
e28e453c08
commit
da6bdd4464
2 changed files with 35 additions and 17 deletions
|
@ -24,7 +24,7 @@ from homeassistant.util.dt import utcnow
|
|||
from .addon_panel import async_setup_addon_panel
|
||||
from .auth import async_setup_auth_view
|
||||
from .discovery import async_setup_discovery_view
|
||||
from .handler import HassIO, HassioAPIError
|
||||
from .handler import HassIO, HassioAPIError, api_data
|
||||
from .http import HassIOView
|
||||
from .ingress import async_setup_ingress_view
|
||||
|
||||
|
@ -137,47 +137,65 @@ async def async_get_addon_info(hass: HomeAssistantType, slug: str) -> dict:
|
|||
|
||||
|
||||
@bind_hass
|
||||
async def async_install_addon(hass: HomeAssistantType, slug: str) -> None:
|
||||
@api_data
|
||||
async def async_install_addon(hass: HomeAssistantType, slug: str) -> dict:
|
||||
"""Install add-on.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio = hass.data[DOMAIN]
|
||||
command = f"/addons/{slug}/install"
|
||||
await hassio.send_command(command)
|
||||
return await hassio.send_command(command)
|
||||
|
||||
|
||||
@bind_hass
|
||||
async def async_uninstall_addon(hass: HomeAssistantType, slug: str) -> None:
|
||||
@api_data
|
||||
async def async_uninstall_addon(hass: HomeAssistantType, slug: str) -> dict:
|
||||
"""Uninstall add-on.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio = hass.data[DOMAIN]
|
||||
command = f"/addons/{slug}/uninstall"
|
||||
await hassio.send_command(command)
|
||||
return await hassio.send_command(command)
|
||||
|
||||
|
||||
@bind_hass
|
||||
async def async_start_addon(hass: HomeAssistantType, slug: str) -> None:
|
||||
@api_data
|
||||
async def async_start_addon(hass: HomeAssistantType, slug: str) -> dict:
|
||||
"""Start add-on.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio = hass.data[DOMAIN]
|
||||
command = f"/addons/{slug}/start"
|
||||
await hassio.send_command(command)
|
||||
return await hassio.send_command(command)
|
||||
|
||||
|
||||
@bind_hass
|
||||
async def async_stop_addon(hass: HomeAssistantType, slug: str) -> None:
|
||||
@api_data
|
||||
async def async_stop_addon(hass: HomeAssistantType, slug: str) -> dict:
|
||||
"""Stop add-on.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio = hass.data[DOMAIN]
|
||||
command = f"/addons/{slug}/stop"
|
||||
await hassio.send_command(command)
|
||||
return await hassio.send_command(command)
|
||||
|
||||
|
||||
@bind_hass
|
||||
@api_data
|
||||
async def async_set_addon_options(
|
||||
hass: HomeAssistantType, slug: str, options: dict
|
||||
) -> dict:
|
||||
"""Set add-on options.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
"""
|
||||
hassio = hass.data[DOMAIN]
|
||||
command = f"/addons/{slug}/options"
|
||||
return await hassio.send_command(command, payload=options)
|
||||
|
||||
|
||||
@callback
|
||||
|
|
|
@ -36,7 +36,7 @@ def _api_bool(funct):
|
|||
return _wrapper
|
||||
|
||||
|
||||
def _api_data(funct):
|
||||
def api_data(funct):
|
||||
"""Return data of an api."""
|
||||
|
||||
async def _wrapper(*argv, **kwargs):
|
||||
|
@ -66,7 +66,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command("/supervisor/ping", method="get", timeout=15)
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def get_info(self):
|
||||
"""Return generic Supervisor information.
|
||||
|
||||
|
@ -74,7 +74,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command("/info", method="get")
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def get_host_info(self):
|
||||
"""Return data for Host.
|
||||
|
||||
|
@ -82,7 +82,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command("/host/info", method="get")
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def get_core_info(self):
|
||||
"""Return data for Home Asssistant Core.
|
||||
|
||||
|
@ -90,7 +90,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command("/core/info", method="get")
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def get_addon_info(self, addon):
|
||||
"""Return data for a Add-on.
|
||||
|
||||
|
@ -98,7 +98,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command(f"/addons/{addon}/info", method="get")
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def get_ingress_panels(self):
|
||||
"""Return data for Add-on ingress panels.
|
||||
|
||||
|
@ -122,7 +122,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command("/homeassistant/stop")
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def retrieve_discovery_messages(self):
|
||||
"""Return all discovery data from Hass.io API.
|
||||
|
||||
|
@ -130,7 +130,7 @@ class HassIO:
|
|||
"""
|
||||
return self.send_command("/discovery", method="get")
|
||||
|
||||
@_api_data
|
||||
@api_data
|
||||
def get_discovery_message(self, uuid):
|
||||
"""Return a single discovery data message.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue