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):
|
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
|
||||||
|
@ -14,7 +14,7 @@ class SystemControl(CoreSysAttributes):
|
|||||||
"""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 SystemControl(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,16 +32,20 @@ class SystemControl(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):
|
async def set_hostname(self, hostname):
|
||||||
"""Set local a new 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)
|
_LOGGER.info("Set Hostname %s", hostname)
|
||||||
await self.sys_dbus.hostname.set_hostname(hostname)
|
await self.sys_dbus.hostname.set_hostname(hostname)
|
||||||
await self.sys_host.info.update()
|
await self.sys_host.info.update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user