mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-26 18:46:29 +00:00
Merge pull request #451 from home-assistant/cleanups
Cleanups & restructs
This commit is contained in:
commit
d94715be2b
18
API.md
18
API.md
@ -226,14 +226,15 @@ return:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "",
|
"hostname": "hostname|null",
|
||||||
"version": "",
|
"features": ["shutdown", "reboot", "update", "hostname"],
|
||||||
"last_version": "",
|
"operating_system": "Hass.io-OS XY|Ubuntu 16.4|null",
|
||||||
"features": ["shutdown", "reboot", "update", "hostname", "network_info", "network_control"],
|
"kernel": "4.15.7|null",
|
||||||
"hostname": "",
|
"chassis": "specific|null",
|
||||||
"operating_system": "",
|
"type": "Hass.io-OS Type|null",
|
||||||
"kernel": "",
|
"deployment": "stable|beta|dev|null",
|
||||||
"chassis": ""
|
"version": "xy|null",
|
||||||
|
"last_version": "xy|null",
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -302,6 +303,7 @@ Optional:
|
|||||||
{
|
{
|
||||||
"version": "INSTALL_VERSION",
|
"version": "INSTALL_VERSION",
|
||||||
"last_version": "LAST_VERSION",
|
"last_version": "LAST_VERSION",
|
||||||
|
"machine": "Image machine type",
|
||||||
"image": "str",
|
"image": "str",
|
||||||
"custom": "bool -> if custom image",
|
"custom": "bool -> if custom image",
|
||||||
"boot": "bool",
|
"boot": "bool",
|
||||||
|
@ -9,7 +9,8 @@ from ..const import (
|
|||||||
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_IMAGE, ATTR_CUSTOM, ATTR_BOOT,
|
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_IMAGE, ATTR_CUSTOM, ATTR_BOOT,
|
||||||
ATTR_PORT, ATTR_PASSWORD, ATTR_SSL, ATTR_WATCHDOG, ATTR_CPU_PERCENT,
|
ATTR_PORT, ATTR_PASSWORD, ATTR_SSL, ATTR_WATCHDOG, ATTR_CPU_PERCENT,
|
||||||
ATTR_MEMORY_USAGE, ATTR_MEMORY_LIMIT, ATTR_NETWORK_RX, ATTR_NETWORK_TX,
|
ATTR_MEMORY_USAGE, ATTR_MEMORY_LIMIT, ATTR_NETWORK_RX, ATTR_NETWORK_TX,
|
||||||
ATTR_BLK_READ, ATTR_BLK_WRITE, ATTR_WAIT_BOOT, CONTENT_TYPE_BINARY)
|
ATTR_BLK_READ, ATTR_BLK_WRITE, ATTR_WAIT_BOOT, ATTR_MACHINE,
|
||||||
|
CONTENT_TYPE_BINARY)
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
from ..validate import NETWORK_PORT, DOCKER_IMAGE
|
from ..validate import NETWORK_PORT, DOCKER_IMAGE
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ class APIHomeAssistant(CoreSysAttributes):
|
|||||||
return {
|
return {
|
||||||
ATTR_VERSION: self.sys_homeassistant.version,
|
ATTR_VERSION: self.sys_homeassistant.version,
|
||||||
ATTR_LAST_VERSION: self.sys_homeassistant.last_version,
|
ATTR_LAST_VERSION: self.sys_homeassistant.last_version,
|
||||||
|
ATTR_MACHINE: self.sys_homeassistant.machine,
|
||||||
ATTR_IMAGE: self.sys_homeassistant.image,
|
ATTR_IMAGE: self.sys_homeassistant.image,
|
||||||
ATTR_CUSTOM: self.sys_homeassistant.is_custom_image,
|
ATTR_CUSTOM: self.sys_homeassistant.is_custom_image,
|
||||||
ATTR_BOOT: self.sys_homeassistant.boot,
|
ATTR_BOOT: self.sys_homeassistant.boot,
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
"""Init file for HassIO host rest api."""
|
"""Init file for HassIO host rest api."""
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from .utils import api_process, api_validate
|
from .utils import api_process, api_validate
|
||||||
from ..const import (
|
from ..const import (
|
||||||
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_TYPE, ATTR_HOSTNAME, ATTR_FEATURES,
|
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_HOSTNAME, ATTR_FEATURES, ATTR_KERNEL,
|
||||||
ATTR_OPERATING_SYSTEM, ATTR_KERNEL, ATTR_CHASSIS)
|
ATTR_TYPE, ATTR_OPERATING_SYSTEM, ATTR_CHASSIS, ATTR_DEPLOYMENT)
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -28,14 +27,15 @@ class APIHost(CoreSysAttributes):
|
|||||||
async def info(self, request):
|
async def info(self, request):
|
||||||
"""Return host information."""
|
"""Return host information."""
|
||||||
return {
|
return {
|
||||||
ATTR_TYPE: None,
|
ATTR_CHASSIS: self.sys_host.info.chassis,
|
||||||
ATTR_CHASSIS: self.sys_host.local.chassis,
|
|
||||||
ATTR_VERSION: None,
|
ATTR_VERSION: None,
|
||||||
ATTR_LAST_VERSION: None,
|
ATTR_LAST_VERSION: None,
|
||||||
|
ATTR_TYPE: None,
|
||||||
ATTR_FEATURES: self.sys_host.supperted_features,
|
ATTR_FEATURES: self.sys_host.supperted_features,
|
||||||
ATTR_HOSTNAME: self.sys_host.local.hostname,
|
ATTR_HOSTNAME: self.sys_host.info.hostname,
|
||||||
ATTR_OPERATING_SYSTEM: self.sys_host.local.operating_system,
|
ATTR_OPERATING_SYSTEM: self.sys_host.info.operating_system,
|
||||||
ATTR_KERNEL: self.sys_host.local.kernel,
|
ATTR_DEPLOYMENT: self.sys_host.info.deployment,
|
||||||
|
ATTR_KERNEL: self.sys_host.info.kernel,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
@ -45,31 +45,26 @@ class APIHost(CoreSysAttributes):
|
|||||||
|
|
||||||
# hostname
|
# hostname
|
||||||
if ATTR_HOSTNAME in body:
|
if ATTR_HOSTNAME in body:
|
||||||
await self.sys_host.local.set_hostname(body[ATTR_HOSTNAME])
|
await self.sys_host.control.set_hostname(body[ATTR_HOSTNAME])
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
def reboot(self, request):
|
def reboot(self, request):
|
||||||
"""Reboot host."""
|
"""Reboot host."""
|
||||||
return self.sys_host.power.reboot()
|
return self.sys_host.control.reboot()
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
def shutdown(self, request):
|
def shutdown(self, request):
|
||||||
"""Poweroff host."""
|
"""Poweroff host."""
|
||||||
return self.sys_host.power.shutdown()
|
return self.sys_host.control.shutdown()
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
def reload(self, request):
|
def reload(self, request):
|
||||||
"""Reload host data."""
|
"""Reload host data."""
|
||||||
return self._host_control.load()
|
return self.sys_host.reload()
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
async def update(self, request):
|
async def update(self, request):
|
||||||
"""Update host OS."""
|
"""Update host OS."""
|
||||||
body = await api_validate(SCHEMA_VERSION, request)
|
pass
|
||||||
version = body.get(ATTR_VERSION, self._host_control.last_version)
|
# body = await api_validate(SCHEMA_VERSION, request)
|
||||||
|
# version = body.get(ATTR_VERSION, self.sys_host.last_version)
|
||||||
if version == self._host_control.version:
|
|
||||||
raise RuntimeError(f"Version {version} is already in use")
|
|
||||||
|
|
||||||
return await asyncio.shield(
|
|
||||||
self._host_control.update(version=version))
|
|
||||||
|
@ -52,7 +52,9 @@ ENV_TIME = 'TZ'
|
|||||||
|
|
||||||
REQUEST_FROM = 'HASSIO_FROM'
|
REQUEST_FROM = 'HASSIO_FROM'
|
||||||
|
|
||||||
|
ATTR_MACHINE = 'machine'
|
||||||
ATTR_WAIT_BOOT = 'wait_boot'
|
ATTR_WAIT_BOOT = 'wait_boot'
|
||||||
|
ATTR_DEPLOYMENT = 'deployment'
|
||||||
ATTR_WATCHDOG = 'watchdog'
|
ATTR_WATCHDOG = 'watchdog'
|
||||||
ATTR_CHANGELOG = 'changelog'
|
ATTR_CHANGELOG = 'changelog'
|
||||||
ATTR_DATE = 'date'
|
ATTR_DATE = 'date'
|
||||||
|
@ -8,7 +8,7 @@ def dbus_connected(method):
|
|||||||
def wrap_dbus(api, *args, **kwargs):
|
def wrap_dbus(api, *args, **kwargs):
|
||||||
"""Check if dbus is connected before call a method."""
|
"""Check if dbus is connected before call a method."""
|
||||||
if api.dbus is None:
|
if api.dbus is None:
|
||||||
raise DBusNotConnectedError(f"{api!s} not connected to dbus!")
|
raise DBusNotConnectedError()
|
||||||
return method(api, *args, **kwargs)
|
return method(api, *args, **kwargs)
|
||||||
|
|
||||||
return wrap_dbus
|
return wrap_dbus
|
||||||
|
@ -35,7 +35,7 @@ class DBusError(HassioError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DBusNotConnectedError(HassioNotSupportedError):
|
class DBusNotConnectedError(HostNotSupportedError):
|
||||||
"""DBus is not connected and call a method."""
|
"""DBus is not connected and call a method."""
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""Host function like audio/dbus/systemd."""
|
"""Host function like audio/dbus/systemd."""
|
||||||
|
|
||||||
from .alsa import AlsaAudio
|
from .alsa import AlsaAudio
|
||||||
from .power import PowerControl
|
from .control import SystemControl
|
||||||
from .local import LocalCenter
|
from .info import InfoCenter
|
||||||
from ..const import FEATURES_REBOOT, FEATURES_SHUTDOWN, FEATURES_HOSTNAME
|
from ..const import FEATURES_REBOOT, FEATURES_SHUTDOWN, FEATURES_HOSTNAME
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
|
|
||||||
@ -14,8 +14,8 @@ class HostManager(CoreSysAttributes):
|
|||||||
"""Initialize Host manager."""
|
"""Initialize Host manager."""
|
||||||
self.coresys = coresys
|
self.coresys = coresys
|
||||||
self._alsa = AlsaAudio(coresys)
|
self._alsa = AlsaAudio(coresys)
|
||||||
self._power = PowerControl(coresys)
|
self._control = SystemControl(coresys)
|
||||||
self._local = LocalCenter(coresys)
|
self._info = InfoCenter(coresys)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def alsa(self):
|
def alsa(self):
|
||||||
@ -23,14 +23,14 @@ class HostManager(CoreSysAttributes):
|
|||||||
return self._alsa
|
return self._alsa
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def power(self):
|
def control(self):
|
||||||
"""Return host power handler."""
|
"""Return host control handler."""
|
||||||
return self._power
|
return self._control
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def local(self):
|
def info(self):
|
||||||
"""Return host local handler."""
|
"""Return host info handler."""
|
||||||
return self._local
|
return self._info
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supperted_features(self):
|
def supperted_features(self):
|
||||||
@ -51,7 +51,7 @@ class HostManager(CoreSysAttributes):
|
|||||||
async def load(self):
|
async def load(self):
|
||||||
"""Load host functions."""
|
"""Load host functions."""
|
||||||
if self.sys_dbus.hostname.is_connected:
|
if self.sys_dbus.hostname.is_connected:
|
||||||
await self.local.update()
|
await self.info.update()
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""Reload host information."""
|
"""Reload host information."""
|
||||||
|
@ -7,14 +7,14 @@ from ..exceptions import HostNotSupportedError
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PowerControl(CoreSysAttributes):
|
class SystemControl(CoreSysAttributes):
|
||||||
"""Handle host power controls."""
|
"""Handle host power controls."""
|
||||||
|
|
||||||
def __init__(self, coresys):
|
def __init__(self, coresys):
|
||||||
"""Initialize host power handling."""
|
"""Initialize host power handling."""
|
||||||
self.coresys = coresys
|
self.coresys = coresys
|
||||||
|
|
||||||
def _check_dbus(self):
|
def _check_systemd(self):
|
||||||
"""Check if systemd is connect or raise error."""
|
"""Check if systemd is connect or raise error."""
|
||||||
if not self.sys_dbus.systemd.is_connected:
|
if not self.sys_dbus.systemd.is_connected:
|
||||||
_LOGGER.error("No systemd dbus connection available")
|
_LOGGER.error("No systemd dbus connection available")
|
||||||
@ -22,7 +22,7 @@ class PowerControl(CoreSysAttributes):
|
|||||||
|
|
||||||
async def reboot(self):
|
async def reboot(self):
|
||||||
"""Reboot host system."""
|
"""Reboot host system."""
|
||||||
self._check_dbus()
|
self._check_systemd()
|
||||||
|
|
||||||
_LOGGER.info("Initialize host reboot over systemd")
|
_LOGGER.info("Initialize host reboot over systemd")
|
||||||
try:
|
try:
|
||||||
@ -32,10 +32,20 @@ class PowerControl(CoreSysAttributes):
|
|||||||
|
|
||||||
async def shutdown(self):
|
async def shutdown(self):
|
||||||
"""Shutdown host system."""
|
"""Shutdown host system."""
|
||||||
self._check_dbus()
|
self._check_systemd()
|
||||||
|
|
||||||
_LOGGER.info("Initialize host power off over systemd")
|
_LOGGER.info("Initialize host power off over systemd")
|
||||||
try:
|
try:
|
||||||
await self.sys_core.shutdown()
|
await self.sys_core.shutdown()
|
||||||
finally:
|
finally:
|
||||||
await self.sys_dbus.systemd.power_off()
|
await self.sys_dbus.systemd.power_off()
|
||||||
|
|
||||||
|
async def set_hostname(self, hostname):
|
||||||
|
"""Set local a new Hostname."""
|
||||||
|
if not self.sys_dbus.systemd.is_connected:
|
||||||
|
_LOGGER.error("No hostname dbus connection available")
|
||||||
|
raise HostNotSupportedError()
|
||||||
|
|
||||||
|
_LOGGER.info("Set Hostname %s", hostname)
|
||||||
|
await self.sys_dbus.hostname.set_hostname(hostname)
|
||||||
|
await self.sys_host.info.update()
|
@ -6,10 +6,8 @@ from ..exceptions import HassioError, HostNotSupportedError
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
UNKNOWN = 'Unknown'
|
|
||||||
|
|
||||||
|
class InfoCenter(CoreSysAttributes):
|
||||||
class LocalCenter(CoreSysAttributes):
|
|
||||||
"""Handle local system information controls."""
|
"""Handle local system information controls."""
|
||||||
|
|
||||||
def __init__(self, coresys):
|
def __init__(self, coresys):
|
||||||
@ -20,48 +18,41 @@ class LocalCenter(CoreSysAttributes):
|
|||||||
@property
|
@property
|
||||||
def hostname(self):
|
def hostname(self):
|
||||||
"""Return local hostname."""
|
"""Return local hostname."""
|
||||||
return self._data.get('Hostname', UNKNOWN)
|
return self._data.get('Hostname') or None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chassis(self):
|
def chassis(self):
|
||||||
"""Return local chassis type."""
|
"""Return local chassis type."""
|
||||||
return self._data.get('Chassis', UNKNOWN)
|
return self._data.get('Chassis') or None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def deployment(self):
|
||||||
|
"""Return local deployment type."""
|
||||||
|
return self._data.get('Deployment') or None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def kernel(self):
|
def kernel(self):
|
||||||
"""Return local kernel version."""
|
"""Return local kernel version."""
|
||||||
return self._data.get('KernelRelease', UNKNOWN)
|
return self._data.get('KernelRelease') or None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def operating_system(self):
|
def operating_system(self):
|
||||||
"""Return local operating system."""
|
"""Return local operating system."""
|
||||||
return self._data.get('OperatingSystemPrettyName', UNKNOWN)
|
return self._data.get('OperatingSystemPrettyName') or None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cpe(self):
|
def cpe(self):
|
||||||
"""Return local CPE."""
|
"""Return local CPE."""
|
||||||
return self._data.get('OperatingSystemCPEName', UNKNOWN)
|
return self._data.get('OperatingSystemCPEName') or None
|
||||||
|
|
||||||
def _check_dbus(self):
|
|
||||||
"""Check if systemd is connect or raise error."""
|
|
||||||
if not self.sys_dbus.hostname.is_connected:
|
|
||||||
_LOGGER.error("No hostname dbus connection available")
|
|
||||||
raise HostNotSupportedError()
|
|
||||||
|
|
||||||
async def update(self):
|
async def update(self):
|
||||||
"""Update properties over dbus."""
|
"""Update properties over dbus."""
|
||||||
self._check_dbus()
|
if not self.sys_dbus.systemd.is_connected:
|
||||||
|
_LOGGER.error("No hostname dbus connection available")
|
||||||
|
raise HostNotSupportedError()
|
||||||
|
|
||||||
_LOGGER.info("Update local host information")
|
_LOGGER.info("Update local host information")
|
||||||
try:
|
try:
|
||||||
self._data = await self.sys_dbus.hostname.get_properties()
|
self._data = await self.sys_dbus.hostname.get_properties()
|
||||||
except HassioError:
|
except HassioError:
|
||||||
_LOGGER.warning("Can't update host system information!")
|
_LOGGER.warning("Can't update host system information!")
|
||||||
|
|
||||||
async def set_hostname(self, hostname):
|
|
||||||
"""Set local a new Hostname."""
|
|
||||||
self._check_dbus()
|
|
||||||
|
|
||||||
_LOGGER.info("Set Hostname %s", hostname)
|
|
||||||
await self.sys_dbus.hostname.set_hostname(hostname)
|
|
||||||
await self.update()
|
|
Loading…
x
Reference in New Issue
Block a user