mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 10:16:29 +00:00
Cleanup
This commit is contained in:
parent
1c2e0e5749
commit
3efbe11d49
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user