mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 04:36:31 +00:00
Fix write options handling (#84)
* Fix write options handling * Fix bug
This commit is contained in:
parent
d5eb66bc0d
commit
56a9f64730
@ -235,7 +235,7 @@ class Addon(object):
|
||||
"""Return path to this addon."""
|
||||
return Path(self._mesh[ATTR_LOCATON])
|
||||
|
||||
def write_addon_options(self):
|
||||
def write_options(self):
|
||||
"""Return True if addon options is written to data."""
|
||||
schema = self.schema
|
||||
options = self.options
|
||||
@ -313,9 +313,6 @@ class Addon(object):
|
||||
_LOGGER.error("Addon %s is not installed", self._id)
|
||||
return False
|
||||
|
||||
if not self.write_addon_options():
|
||||
return False
|
||||
|
||||
return await self.addon_docker.run()
|
||||
|
||||
async def stop(self):
|
||||
@ -350,9 +347,6 @@ class Addon(object):
|
||||
_LOGGER.error("Addon %s is not installed", self._id)
|
||||
return False
|
||||
|
||||
if not self.write_addon_options():
|
||||
return False
|
||||
|
||||
return await self.addon_docker.restart()
|
||||
|
||||
async def logs(self):
|
||||
|
@ -3,6 +3,7 @@ import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
from voluptuous.humanize import humanize_error
|
||||
|
||||
from .util import api_process, api_process_raw, api_validate
|
||||
from ..const import (
|
||||
@ -92,13 +93,20 @@ class APIAddons(object):
|
||||
async def uninstall(self, request):
|
||||
"""Uninstall addon."""
|
||||
addon = self._extract_addon(request)
|
||||
|
||||
return await asyncio.shield(addon.uninstall(), loop=self.loop)
|
||||
|
||||
@api_process
|
||||
async def start(self, request):
|
||||
"""Start addon."""
|
||||
addon = self._extract_addon(request)
|
||||
|
||||
# check options
|
||||
options = addon.options
|
||||
try:
|
||||
addon.schema(options)
|
||||
except vol.Invalid as ex:
|
||||
raise RuntimeError(humanize_error(options, ex)) from None
|
||||
|
||||
return await asyncio.shield(addon.start(), loop=self.loop)
|
||||
|
||||
@api_process
|
||||
|
@ -94,11 +94,15 @@ class DockerAddon(DockerBase):
|
||||
Need run inside executor.
|
||||
"""
|
||||
if self._is_running():
|
||||
return
|
||||
return True
|
||||
|
||||
# cleanup
|
||||
self._stop()
|
||||
|
||||
# write config
|
||||
if not self.addon.write_options():
|
||||
return False
|
||||
|
||||
try:
|
||||
self.dock.containers.run(
|
||||
self.image,
|
||||
|
Loading…
x
Reference in New Issue
Block a user