Home Assistant Core start flow / partial restore (#1507)

* Fix start flow logic

* Add a note

* Fix flow on partial restore
This commit is contained in:
Pascal Vizeli 2020-02-14 15:25:43 +01:00 committed by GitHub
parent c33d31996d
commit 9e5c276e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 15 deletions

View File

@ -121,6 +121,8 @@ class HassIO(CoreSysAttributes):
):
with suppress(HomeAssistantError):
await self.sys_homeassistant.start()
else:
_LOGGER.info("Skip start of Home Assistant")
# start addon mark as application
await self.sys_addons.boot(STARTUP_APPLICATION)

View File

@ -330,10 +330,6 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
async def _start(self) -> None:
"""Start Home Assistant Docker & wait."""
if await self.instance.is_running():
_LOGGER.warning("Home Assistant is already running!")
return
# Create new API token
self._data[ATTR_ACCESS_TOKEN] = secrets.token_hex(56)
self.save_data()
@ -347,18 +343,21 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
@process_lock
async def start(self) -> None:
"""Run Home Assistant docker."""
try:
if await self.instance.is_running():
await self.instance.restart()
elif await self.instance.is_initialize():
if await self.instance.is_running():
_LOGGER.warning("Home Assistant is already running!")
return
# Instance/Container exists, simple start
if await self.instance.is_initialize():
try:
await self.instance.start()
else:
await self._start()
return
except DockerAPIError:
raise HomeAssistantError() from None
await self._block_till_run()
except DockerAPIError:
raise HomeAssistantError() from None
# No Instance/Container found, extended start
else:
await self._start()
@process_lock
async def stop(self) -> None:

View File

@ -291,8 +291,8 @@ class SnapshotManager(CoreSysAttributes):
await self.lock.acquire()
async with snapshot:
# Stop Home-Assistant if they will be restored later
if homeassistant and FOLDER_HOMEASSISTANT in folders:
# Stop Home-Assistant for config restore
if FOLDER_HOMEASSISTANT in folders:
await self.sys_homeassistant.stop()
snapshot.restore_homeassistant()