diff --git a/hassio/dbus/utils.py b/hassio/dbus/utils.py index b8656a235..94da81d9a 100644 --- a/hassio/dbus/utils.py +++ b/hassio/dbus/utils.py @@ -8,7 +8,7 @@ def dbus_connected(method): def wrap_dbus(api, *args, **kwargs): """Check if dbus is connected before call a method.""" if api.dbus is None: - raise DBusNotConnectedError(f"{api!s} not connected to dbus!") + raise DBusNotConnectedError() return method(api, *args, **kwargs) return wrap_dbus diff --git a/hassio/host/control.py b/hassio/host/control.py index b17f8da84..77559bc4d 100644 --- a/hassio/host/control.py +++ b/hassio/host/control.py @@ -14,7 +14,7 @@ class SystemControl(CoreSysAttributes): """Initialize host power handling.""" self.coresys = coresys - def _check_dbus(self): + def _check_systemd(self): """Check if systemd is connect or raise error.""" if not self.sys_dbus.systemd.is_connected: _LOGGER.error("No systemd dbus connection available") @@ -22,7 +22,7 @@ class SystemControl(CoreSysAttributes): async def reboot(self): """Reboot host system.""" - self._check_dbus() + self._check_systemd() _LOGGER.info("Initialize host reboot over systemd") try: @@ -32,16 +32,20 @@ class SystemControl(CoreSysAttributes): async def shutdown(self): """Shutdown host system.""" - self._check_dbus() + self._check_systemd() _LOGGER.info("Initialize host power off over systemd") try: await self.sys_core.shutdown() finally: 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()