mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 23:26:29 +00:00
Fix wrong last boot (#1521)
* Protect overwrite last boot uptime * Fix naming * Fix lint
This commit is contained in:
parent
1fbb6d46ea
commit
e9f5b13aa5
@ -342,3 +342,12 @@ class UpdateChannels(str, Enum):
|
|||||||
STABLE = "stable"
|
STABLE = "stable"
|
||||||
BETA = "beta"
|
BETA = "beta"
|
||||||
DEV = "dev"
|
DEV = "dev"
|
||||||
|
|
||||||
|
|
||||||
|
class CoreStates(str, Enum):
|
||||||
|
"""Represent current loading state."""
|
||||||
|
|
||||||
|
INITIALIZE = "initialize"
|
||||||
|
STARTUP = "startup"
|
||||||
|
RUNNING = "running"
|
||||||
|
FREEZE = "freeze"
|
||||||
|
@ -1,35 +1,39 @@
|
|||||||
"""Main file for Hass.io."""
|
"""Main file for Supervisor."""
|
||||||
from contextlib import suppress
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from contextlib import suppress
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
|
||||||
from .coresys import CoreSysAttributes
|
|
||||||
from .const import (
|
from .const import (
|
||||||
STARTUP_SYSTEM,
|
|
||||||
STARTUP_SERVICES,
|
|
||||||
STARTUP_APPLICATION,
|
STARTUP_APPLICATION,
|
||||||
STARTUP_INITIALIZE,
|
STARTUP_INITIALIZE,
|
||||||
|
STARTUP_SERVICES,
|
||||||
|
STARTUP_SYSTEM,
|
||||||
|
CoreStates,
|
||||||
)
|
)
|
||||||
|
from .coresys import CoreSysAttributes
|
||||||
from .exceptions import HassioError, HomeAssistantError, SupervisorUpdateError
|
from .exceptions import HassioError, HomeAssistantError, SupervisorUpdateError
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class HassIO(CoreSysAttributes):
|
class HassIO(CoreSysAttributes):
|
||||||
"""Main object of Hass.io."""
|
"""Main object of Supervisor."""
|
||||||
|
|
||||||
def __init__(self, coresys):
|
def __init__(self, coresys):
|
||||||
"""Initialize Hass.io object."""
|
"""Initialize Supervisor object."""
|
||||||
self.coresys = coresys
|
self.coresys = coresys
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
"""Connect Supervisor container."""
|
"""Connect Supervisor container."""
|
||||||
|
self.coresys.state = CoreStates.INITIALIZE
|
||||||
await self.sys_supervisor.load()
|
await self.sys_supervisor.load()
|
||||||
|
|
||||||
async def setup(self):
|
async def setup(self):
|
||||||
"""Setup HassIO orchestration."""
|
"""Setup HassIO orchestration."""
|
||||||
|
self.coresys.state = CoreStates.STARTUP
|
||||||
|
|
||||||
# Load DBus
|
# Load DBus
|
||||||
await self.sys_dbus.load()
|
await self.sys_dbus.load()
|
||||||
|
|
||||||
@ -76,7 +80,7 @@ class HassIO(CoreSysAttributes):
|
|||||||
await self.sys_secrets.load()
|
await self.sys_secrets.load()
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
"""Start Hass.io orchestration."""
|
"""Start Supervisor orchestration."""
|
||||||
await self.sys_api.start()
|
await self.sys_api.start()
|
||||||
|
|
||||||
# Mark booted partition as healthy
|
# Mark booted partition as healthy
|
||||||
@ -87,7 +91,7 @@ class HassIO(CoreSysAttributes):
|
|||||||
if self.sys_supervisor.need_update:
|
if self.sys_supervisor.need_update:
|
||||||
try:
|
try:
|
||||||
if self.sys_dev:
|
if self.sys_dev:
|
||||||
_LOGGER.warning("Ignore Hass.io updates on dev!")
|
_LOGGER.warning("Ignore Supervisor updates on dev!")
|
||||||
else:
|
else:
|
||||||
await self.sys_supervisor.update()
|
await self.sys_supervisor.update()
|
||||||
except SupervisorUpdateError:
|
except SupervisorUpdateError:
|
||||||
@ -102,7 +106,7 @@ class HassIO(CoreSysAttributes):
|
|||||||
try:
|
try:
|
||||||
# HomeAssistant is already running / supervisor have only reboot
|
# HomeAssistant is already running / supervisor have only reboot
|
||||||
if self.sys_hardware.last_boot == self.sys_config.last_boot:
|
if self.sys_hardware.last_boot == self.sys_config.last_boot:
|
||||||
_LOGGER.info("Hass.io reboot detected")
|
_LOGGER.info("Supervisor reboot detected")
|
||||||
return
|
return
|
||||||
|
|
||||||
# reset register services / discovery
|
# reset register services / discovery
|
||||||
@ -138,7 +142,8 @@ class HassIO(CoreSysAttributes):
|
|||||||
if self.sys_homeassistant.version == "landingpage":
|
if self.sys_homeassistant.version == "landingpage":
|
||||||
self.sys_create_task(self.sys_homeassistant.install())
|
self.sys_create_task(self.sys_homeassistant.install())
|
||||||
|
|
||||||
_LOGGER.info("Hass.io is up and running")
|
_LOGGER.info("Supervisor is up and running")
|
||||||
|
self.coresys.state = CoreStates.RUNNING
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
"""Stop a running orchestration."""
|
"""Stop a running orchestration."""
|
||||||
@ -146,7 +151,8 @@ class HassIO(CoreSysAttributes):
|
|||||||
self.sys_scheduler.suspend = True
|
self.sys_scheduler.suspend = True
|
||||||
|
|
||||||
# store new last boot / prevent time adjustments
|
# store new last boot / prevent time adjustments
|
||||||
self._update_last_boot()
|
if self.coresys.state == CoreStates.RUNNING:
|
||||||
|
self._update_last_boot()
|
||||||
|
|
||||||
# process async stop tasks
|
# process async stop tasks
|
||||||
try:
|
try:
|
||||||
@ -163,7 +169,7 @@ class HassIO(CoreSysAttributes):
|
|||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.warning("Force Shutdown!")
|
_LOGGER.warning("Force Shutdown!")
|
||||||
|
|
||||||
_LOGGER.info("Hass.io is down")
|
_LOGGER.info("Supervisor is down")
|
||||||
|
|
||||||
async def shutdown(self):
|
async def shutdown(self):
|
||||||
"""Shutdown all running containers in correct order."""
|
"""Shutdown all running containers in correct order."""
|
||||||
@ -184,7 +190,7 @@ class HassIO(CoreSysAttributes):
|
|||||||
|
|
||||||
async def repair(self):
|
async def repair(self):
|
||||||
"""Repair system integrity."""
|
"""Repair system integrity."""
|
||||||
_LOGGER.info("Start repairing of Hass.io Environment")
|
_LOGGER.info("Start repairing of Supervisor Environment")
|
||||||
await self.sys_run_in_executor(self.sys_docker.repair)
|
await self.sys_run_in_executor(self.sys_docker.repair)
|
||||||
|
|
||||||
# Restore core functionality
|
# Restore core functionality
|
||||||
@ -198,4 +204,4 @@ class HassIO(CoreSysAttributes):
|
|||||||
|
|
||||||
# Tag version for latest
|
# Tag version for latest
|
||||||
await self.sys_supervisor.repair()
|
await self.sys_supervisor.repair()
|
||||||
_LOGGER.info("Finished repairing of Hass.io Environment")
|
_LOGGER.info("Finished repairing of Supervisor Environment")
|
||||||
|
@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Optional
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from .config import CoreConfig
|
from .config import CoreConfig
|
||||||
from .const import UpdateChannels
|
from .const import UpdateChannels, CoreStates
|
||||||
from .docker import DockerAPI
|
from .docker import DockerAPI
|
||||||
from .misc.hardware import Hardware
|
from .misc.hardware import Hardware
|
||||||
from .misc.scheduler import Scheduler
|
from .misc.scheduler import Scheduler
|
||||||
@ -39,7 +39,8 @@ class CoreSys:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize coresys."""
|
"""Initialize coresys."""
|
||||||
# Static attributes
|
# Static attributes
|
||||||
self.machine_id: str = None
|
self.machine_id: Optional[str] = None
|
||||||
|
self.state: Optional[CoreStates] = None
|
||||||
|
|
||||||
# External objects
|
# External objects
|
||||||
self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop()
|
self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user