mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-09 10:16:29 +00:00
add interface dbus class
This commit is contained in:
parent
10219a348f
commit
6f770b78af
@ -1,6 +1,7 @@
|
||||
"""DBus interface objects."""
|
||||
|
||||
from .systemd import Systemd
|
||||
from .hostname import Hostname
|
||||
from ..coresys import CoreSysAttributes
|
||||
|
||||
|
||||
@ -11,12 +12,19 @@ class DBusManager(CoreSysAttributes):
|
||||
"""Initialize DBus Interface."""
|
||||
self.coresys = coresys
|
||||
self._systemd = Systemd()
|
||||
self._hostname = Hostname()
|
||||
|
||||
@property
|
||||
def systemd(self):
|
||||
"""Return Systemd Interface."""
|
||||
return self._systemd
|
||||
|
||||
@property
|
||||
def hostname(self):
|
||||
"""Return hostname Interface."""
|
||||
return self._hostname
|
||||
|
||||
async def load(self):
|
||||
"""Connect interfaces to dbus."""
|
||||
await self.systemd.connect()
|
||||
await self.hostname.connect()
|
||||
|
@ -1 +1,23 @@
|
||||
"""DBus interface for hostname."""
|
||||
import logging
|
||||
|
||||
from .interface import DBusInterface
|
||||
from .utils import dbus_connected
|
||||
from ..exceptions import DBusError
|
||||
from ..utils.gdbus import DBus
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DBUS_NAME = 'org.freedesktop.hostname1'
|
||||
DBUS_OBJECT = '/org/freedesktop/hostname1'
|
||||
|
||||
|
||||
class Hostname(DBusInterface):
|
||||
"""Handle DBus interface for hostname/system."""
|
||||
|
||||
async def connect(self):
|
||||
"""Connect do bus."""
|
||||
try:
|
||||
self.dbus = await DBus.connect(DBUS_NAME, DBUS_OBJECT)
|
||||
except DBusError:
|
||||
_LOGGER.warning("Can't connect to hostname")
|
||||
|
18
hassio/dbus/interface.py
Normal file
18
hassio/dbus/interface.py
Normal file
@ -0,0 +1,18 @@
|
||||
"""Interface class for dbus wrappers."""
|
||||
|
||||
|
||||
class DBusInterface:
|
||||
"""Handle DBus interface for hostname/system."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize systemd."""
|
||||
self.dbus = None
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
"""Return True, if they is connected to dbus."""
|
||||
return self.dbus is not None
|
||||
|
||||
async def connect(self):
|
||||
"""Connect do bus."""
|
||||
raise NotImplementedError()
|
@ -1,6 +1,7 @@
|
||||
"""Interface to Systemd over dbus."""
|
||||
import logging
|
||||
|
||||
from .interface import DBusInterface
|
||||
from .utils import dbus_connected
|
||||
from ..exceptions import DBusError
|
||||
from ..utils.gdbus import DBus
|
||||
@ -11,18 +12,9 @@ DBUS_NAME = 'org.freedesktop.systemd1'
|
||||
DBUS_OBJECT = '/org/freedesktop/systemd1'
|
||||
|
||||
|
||||
class Systemd:
|
||||
class Systemd(DBusInterface):
|
||||
"""Systemd function handler."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize systemd."""
|
||||
self.dbus = None
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
"""Return True, if they is connected to dbus."""
|
||||
return self.dbus is not None
|
||||
|
||||
async def connect(self):
|
||||
"""Connect do bus."""
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user