diff --git a/supervisor/hardware/disk.py b/supervisor/hardware/disk.py index 90dc1e5a2..538246c47 100644 --- a/supervisor/hardware/disk.py +++ b/supervisor/hardware/disk.py @@ -9,7 +9,12 @@ from typing import Any from supervisor.resolution.const import UnhealthyReason from ..coresys import CoreSys, CoreSysAttributes -from ..exceptions import DBusError, DBusObjectError, HardwareNotFound +from ..exceptions import ( + DBusError, + DBusNotConnectedError, + DBusObjectError, + HardwareNotFound, +) from .const import UdevSubsystem from .data import Device @@ -207,6 +212,8 @@ class HwDisk(CoreSysAttributes): try: block_device = self.sys_dbus.udisks2.get_block_device_by_path(device_path) drive = self.sys_dbus.udisks2.get_drive(block_device.drive) + except DBusNotConnectedError: + return None except DBusObjectError: _LOGGER.warning( "Unable to find UDisks2 drive for device at %s", device_path.as_posix() diff --git a/tests/hardware/test_disk.py b/tests/hardware/test_disk.py index 2e435b149..adb804b98 100644 --- a/tests/hardware/test_disk.py +++ b/tests/hardware/test_disk.py @@ -376,3 +376,14 @@ async def test_try_get_nvme_life_time_missing_percent_used( coresys.config.path_supervisor ) assert lifetime is None + + +async def test_try_get_nvme_life_time_dbus_not_connected(coresys: CoreSys): + """Test getting lifetime info from an NVMe when DBUS is not connected.""" + # Set the dbus for udisks2 bus to be None, to make it forcibly disconnected. + coresys.dbus.udisks2.dbus = None + + lifetime = await coresys.hardware.disk.get_disk_life_time( + coresys.config.path_supervisor + ) + assert lifetime is None