Add healthy and supported to API (#1889)
* Add healthy and supported to API * fix protected attributes
This commit is contained in:
parent
495f9f2373
commit
71ccaa2bd0
3
API.md
3
API.md
|
@ -42,6 +42,8 @@ The addons from `addons` are only installed one.
|
|||
"arch": "armhf|aarch64|i386|amd64",
|
||||
"channel": "stable|beta|dev",
|
||||
"timezone": "TIMEZONE",
|
||||
"healthy": "bool",
|
||||
"supported": "bool",
|
||||
"logging": "debug|info|warning|error|critical",
|
||||
"ip_address": "ip address",
|
||||
"wait_boot": "int",
|
||||
|
@ -798,6 +800,7 @@ return:
|
|||
"machine": "type",
|
||||
"arch": "arch",
|
||||
"supported_arch": ["arch1", "arch2"],
|
||||
"supported": "bool",
|
||||
"channel": "stable|beta|dev",
|
||||
"logging": "debug|info|warning|error|critical",
|
||||
"timezone": "Europe/Zurich"
|
||||
|
|
|
@ -14,6 +14,7 @@ from ..const import (
|
|||
ATTR_LOGGING,
|
||||
ATTR_MACHINE,
|
||||
ATTR_SUPERVISOR,
|
||||
ATTR_SUPPORTED,
|
||||
ATTR_SUPPORTED_ARCH,
|
||||
ATTR_TIMEZONE,
|
||||
)
|
||||
|
@ -38,6 +39,7 @@ class APIInfo(CoreSysAttributes):
|
|||
ATTR_MACHINE: self.sys_machine,
|
||||
ATTR_ARCH: self.sys_arch.default,
|
||||
ATTR_SUPPORTED_ARCH: self.sys_arch.supported,
|
||||
ATTR_SUPPORTED: self.sys_supported,
|
||||
ATTR_CHANNEL: self.sys_updater.channel,
|
||||
ATTR_LOGGING: self.sys_config.logging,
|
||||
ATTR_TIMEZONE: self.sys_timezone,
|
||||
|
|
|
@ -18,6 +18,7 @@ from ..const import (
|
|||
ATTR_DEBUG_BLOCK,
|
||||
ATTR_DESCRIPTON,
|
||||
ATTR_DIAGNOSTICS,
|
||||
ATTR_HEALTHY,
|
||||
ATTR_ICON,
|
||||
ATTR_INSTALLED,
|
||||
ATTR_IP_ADDRESS,
|
||||
|
@ -32,6 +33,7 @@ from ..const import (
|
|||
ATTR_REPOSITORY,
|
||||
ATTR_SLUG,
|
||||
ATTR_STATE,
|
||||
ATTR_SUPPORTED,
|
||||
ATTR_TIMEZONE,
|
||||
ATTR_VERSION,
|
||||
ATTR_VERSION_LATEST,
|
||||
|
@ -98,6 +100,8 @@ class APISupervisor(CoreSysAttributes):
|
|||
ATTR_VERSION_LATEST: self.sys_updater.version_supervisor,
|
||||
ATTR_CHANNEL: self.sys_updater.channel,
|
||||
ATTR_ARCH: self.sys_supervisor.arch,
|
||||
ATTR_SUPPORTED: self.sys_supported,
|
||||
ATTR_HEALTHY: self.sys_core.healthy,
|
||||
ATTR_IP_ADDRESS: str(self.sys_supervisor.ip_address),
|
||||
ATTR_WAIT_BOOT: self.sys_config.wait_boot,
|
||||
ATTR_TIMEZONE: self.sys_config.timezone,
|
||||
|
|
|
@ -283,7 +283,7 @@ def setup_diagnostics(coresys: CoreSys) -> None:
|
|||
|
||||
def filter_data(event, hint):
|
||||
# Ignore issue if system is not supported or diagnostics is disabled
|
||||
if not coresys.config.diagnostics or not coresys.core.healthy:
|
||||
if not coresys.config.diagnostics or not coresys.supported:
|
||||
return None
|
||||
|
||||
# Not full startup - missing information
|
||||
|
|
|
@ -243,6 +243,8 @@ ATTR_ACTIVE = "active"
|
|||
ATTR_APPLICATION = "application"
|
||||
ATTR_INIT = "init"
|
||||
ATTR_DIAGNOSTICS = "diagnostics"
|
||||
ATTR_HEALTHY = "healthy"
|
||||
ATTR_SUPPORTED = "supported"
|
||||
|
||||
PROVIDE_SERVICE = "provide"
|
||||
NEED_SERVICE = "need"
|
||||
|
|
|
@ -19,46 +19,44 @@ class Core(CoreSysAttributes):
|
|||
"""Initialize Supervisor object."""
|
||||
self.coresys: CoreSys = coresys
|
||||
self.state: CoreStates = CoreStates.INITIALIZE
|
||||
self.healthy: bool = True
|
||||
self._healthy: bool = True
|
||||
|
||||
@property
|
||||
def healthy(self) -> bool:
|
||||
"""Return True if system is healthy."""
|
||||
return self._healthy and self.sys_supported
|
||||
|
||||
async def connect(self):
|
||||
"""Connect Supervisor container."""
|
||||
await self.sys_supervisor.load()
|
||||
|
||||
# If a update is failed?
|
||||
if self.sys_dev:
|
||||
self.sys_config.version = self.sys_supervisor.version
|
||||
elif self.sys_config.version != self.sys_supervisor.version:
|
||||
self.healthy = False
|
||||
_LOGGER.critical("Update of Supervisor fails!")
|
||||
|
||||
# If local docker is supported?
|
||||
# If host docker is supported?
|
||||
if not self.sys_docker.info.supported_version:
|
||||
self.healthy = False
|
||||
self.coresys.supported = False
|
||||
_LOGGER.critical(
|
||||
"Docker version %s is not supported by Supervisor!",
|
||||
self.sys_docker.info.version,
|
||||
)
|
||||
elif self.sys_docker.info.inside_lxc:
|
||||
self.healthy = False
|
||||
self.coresys.supported = False
|
||||
_LOGGER.critical(
|
||||
"Detected Docker running inside LXC. Running Home Assistant with the Supervisor on LXC is not supported!"
|
||||
)
|
||||
|
||||
self.sys_docker.info.check_requirements()
|
||||
|
||||
# Dbus available
|
||||
if not SOCKET_DBUS.exists():
|
||||
self.healthy = False
|
||||
self.coresys.supported = False
|
||||
_LOGGER.critical(
|
||||
"DBus is required for Home Assistant. This system is not supported!"
|
||||
)
|
||||
|
||||
# Check if system is healthy
|
||||
if not self.healthy:
|
||||
_LOGGER.critical(
|
||||
"System running in a unhealthy state. Please update you OS or software!"
|
||||
)
|
||||
# If a update is failed?
|
||||
if self.sys_dev:
|
||||
self.sys_config.version = self.sys_supervisor.version
|
||||
elif self.sys_config.version != self.sys_supervisor.version:
|
||||
self._healthy = False
|
||||
_LOGGER.critical("Update of Supervisor fails!")
|
||||
|
||||
async def setup(self):
|
||||
"""Start setting up supervisor orchestration."""
|
||||
|
@ -109,6 +107,12 @@ class Core(CoreSysAttributes):
|
|||
# Load secrets
|
||||
await self.sys_secrets.load()
|
||||
|
||||
# Check if system is healthy
|
||||
if not self.healthy:
|
||||
_LOGGER.critical(
|
||||
"System running in a unhealthy state. Please update you OS or software!"
|
||||
)
|
||||
|
||||
async def start(self):
|
||||
"""Start Supervisor orchestration."""
|
||||
self.state = CoreStates.STARTUP
|
||||
|
|
|
@ -44,10 +44,13 @@ class CoreSys:
|
|||
|
||||
def __init__(self):
|
||||
"""Initialize coresys."""
|
||||
# Static attributes
|
||||
# Static attributes protected
|
||||
self._machine_id: Optional[str] = None
|
||||
self._machine: Optional[str] = None
|
||||
|
||||
# Static attributes
|
||||
self.supported: bool = True
|
||||
|
||||
# External objects
|
||||
self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop()
|
||||
self._websession: aiohttp.ClientSession = aiohttp.ClientSession()
|
||||
|
@ -459,6 +462,11 @@ class CoreSysAttributes:
|
|||
"""Return True if we run dev mode."""
|
||||
return self.coresys.dev
|
||||
|
||||
@property
|
||||
def sys_supported(self) -> bool:
|
||||
"""Return True if the system is supported."""
|
||||
return self.coresys.supported
|
||||
|
||||
@property
|
||||
def sys_timezone(self) -> str:
|
||||
"""Return timezone."""
|
||||
|
|
Loading…
Reference in New Issue