From a0d106529ceea2f5818b2bae7ec199e13f99e948 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 18 Dec 2019 23:46:42 +0100 Subject: [PATCH] Report error correct for rauc (#1403) * Report error correct * Use new style --- hassio/dbus/rauc.py | 56 ++++++++++++++++++++++++++++++++++++++------- hassio/hassos.py | 10 +++++--- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/hassio/dbus/rauc.py b/hassio/dbus/rauc.py index 7b2b35aad..cb713addd 100644 --- a/hassio/dbus/rauc.py +++ b/hassio/dbus/rauc.py @@ -1,5 +1,6 @@ """D-Bus interface for rauc.""" import logging +from typing import Optional from .interface import DBusInterface from .utils import dbus_connected @@ -15,6 +16,14 @@ DBUS_OBJECT = "/" class Rauc(DBusInterface): """Handle D-Bus interface for rauc.""" + def __init__(self): + """Initialize Properties.""" + self._operation: Optional[str] = None + self._last_error: Optional[str] = None + self._compatible: Optional[str] = None + self._variant: Optional[str] = None + self._boot_slot: Optional[str] = None + async def connect(self): """Connect to D-Bus.""" try: @@ -24,6 +33,31 @@ class Rauc(DBusInterface): except DBusInterfaceError: _LOGGER.warning("Host has no rauc support. OTA updates have been disabled.") + @property + def operation(self) -> Optional[str]: + """Return the current (global) operation.""" + return self._operation + + @property + def last_error(self) -> Optional[str]: + """Return the last message of the last error that occurred.""" + return self._last_error + + @property + def compatible(self) -> Optional[str]: + """Return the system compatible string.""" + return self._compatible + + @property + def variant(self) -> Optional[str]: + """Return the system variant string.""" + return self._variant + + @property + def boot_slot(self) -> Optional[str]: + """Return the used boot slot.""" + return self._boot_slot + @dbus_connected def install(self, raucb_file): """Install rauc bundle file. @@ -40,14 +74,6 @@ class Rauc(DBusInterface): """ return self.dbus.Installer.GetSlotStatus() - @dbus_connected - def get_properties(self): - """Return rauc informations. - - Return a coroutine. - """ - return self.dbus.get_properties(f"{DBUS_NAME}.Installer") - @dbus_connected def signal_completed(self): """Return a signal wrapper for completed signal. @@ -55,3 +81,17 @@ class Rauc(DBusInterface): Return a coroutine. """ return self.dbus.wait_signal(f"{DBUS_NAME}.Installer.Completed") + + @dbus_connected + async def update(self): + """Update Properties.""" + data = await self.dbus.get_properties(f"{DBUS_NAME}.Installer") + if not data: + _LOGGER.warning("Can't get properties for rauc") + return + + self._operation = data.get("Operation") + self._last_error = data.get("LastError") + self._compatible = data.get("Compatible") + self._variant = data.get("Variant") + self._boot_slot = data.get("BootSlot") diff --git a/hassio/hassos.py b/hassio/hassos.py index b394b71f6..d0add98b1 100644 --- a/hassio/hassos.py +++ b/hassio/hassos.py @@ -128,7 +128,11 @@ class HassOS(CoreSysAttributes): self._version = cpe.get_version()[0] self._board = cpe.get_target_hardware()[0] - _LOGGER.info("Detect HassOS %s on host system", self.version) + await self.sys_dbus.rauc.update() + + _LOGGER.info( + "Detect HassOS %s / BootSlot %s", self.version, self.sys_dbus.rauc.boot_slot + ) with suppress(DockerAPIError): await self.instance.attach(tag="latest") @@ -174,8 +178,8 @@ class HassOS(CoreSysAttributes): return # Update fails - rauc_status = await self.sys_dbus.get_properties() - _LOGGER.error("HassOS update fails with: %s", rauc_status.get("LastError")) + await self.sys_dbus.rauc.update() + _LOGGER.error("HassOS update fails with: %s", self.sys_dbus.rauc.last_error) raise HassOSUpdateError() async def update_cli(self, version: Optional[str] = None) -> None: