mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 19:16:29 +00:00
Make dbus connection more robust (#2325)
* Make dbus connection more robust * move rauc down
This commit is contained in:
parent
80763c4bbf
commit
3d79891249
@ -1,9 +1,11 @@
|
||||
"""D-Bus interface objects."""
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from ..const import SOCKET_DBUS
|
||||
from ..coresys import CoreSys, CoreSysAttributes
|
||||
from ..exceptions import DBusNotConnectedError
|
||||
from .hostname import Hostname
|
||||
from .interface import DBusInterface
|
||||
from .network import NetworkManager
|
||||
from .rauc import Rauc
|
||||
from .systemd import Systemd
|
||||
@ -45,15 +47,22 @@ class DBusManager(CoreSysAttributes):
|
||||
|
||||
async def load(self) -> None:
|
||||
"""Connect interfaces to D-Bus."""
|
||||
|
||||
try:
|
||||
await self.systemd.connect()
|
||||
await self.hostname.connect()
|
||||
await self.rauc.connect()
|
||||
await self.network.connect()
|
||||
except DBusNotConnectedError:
|
||||
if not SOCKET_DBUS.exists():
|
||||
_LOGGER.error(
|
||||
"No D-Bus support on Host. Disabled any kind of host control!"
|
||||
)
|
||||
return
|
||||
|
||||
dbus_loads: List[DBusInterface] = [
|
||||
self.systemd,
|
||||
self.hostname,
|
||||
self.network,
|
||||
self.rauc,
|
||||
]
|
||||
for dbus in dbus_loads:
|
||||
try:
|
||||
await dbus.connect()
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.warning("Can't load dbus interface %s: %s", dbus.name, err)
|
||||
|
||||
self.sys_host.supported_features.cache_clear()
|
||||
|
@ -23,6 +23,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
class Hostname(DBusInterface):
|
||||
"""Handle D-Bus interface for hostname/system."""
|
||||
|
||||
name = DBUS_NAME_HOSTNAME
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize Properties."""
|
||||
self._hostname: Optional[str] = None
|
||||
|
@ -9,6 +9,7 @@ class DBusInterface(ABC):
|
||||
"""Handle D-Bus interface for hostname/system."""
|
||||
|
||||
dbus: Optional[DBus] = None
|
||||
name: Optional[str] = None
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
|
@ -27,6 +27,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
class NetworkManager(DBusInterface):
|
||||
"""Handle D-Bus interface for Network Manager."""
|
||||
|
||||
name = DBUS_NAME_NM
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize Properties."""
|
||||
self._dns: NetworkManagerDNS = NetworkManagerDNS()
|
||||
|
@ -25,6 +25,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
class Rauc(DBusInterface):
|
||||
"""Handle D-Bus interface for rauc."""
|
||||
|
||||
name = DBUS_NAME_RAUC
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize Properties."""
|
||||
self._operation: Optional[str] = None
|
||||
|
@ -13,6 +13,8 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
class Systemd(DBusInterface):
|
||||
"""Systemd function handler."""
|
||||
|
||||
name = DBUS_NAME_SYSTEMD
|
||||
|
||||
async def connect(self):
|
||||
"""Connect to D-Bus."""
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user