Avoid creating system monitor disk sensors for non-dirs (#111695)
Avoid creating system monitor sensors for non-dirs Currently we create sensors for /etc/hosts, /etc/asound.conf, since they are bind mounts in the container. These all have to have their own coordinatorpull/111666/head
parent
f9d9ac48c7
commit
01a6b85a35
|
@ -30,6 +30,12 @@ def get_all_disk_mounts(hass: HomeAssistant) -> set[str]:
|
|||
# Ignore disks which are memory
|
||||
continue
|
||||
try:
|
||||
if not os.path.isdir(part.mountpoint):
|
||||
_LOGGER.debug(
|
||||
"Mountpoint %s was excluded because it is not a directory",
|
||||
part.mountpoint,
|
||||
)
|
||||
continue
|
||||
usage = psutil_wrapper.psutil.disk_usage(part.mountpoint)
|
||||
except PermissionError:
|
||||
_LOGGER.debug(
|
||||
|
|
|
@ -162,6 +162,7 @@ def mock_psutil(mock_process: list[MockProcess]) -> Generator:
|
|||
sdiskpart("test", "/", "ext4", "", 1, 1),
|
||||
sdiskpart("test2", "/media/share", "ext4", "", 1, 1),
|
||||
sdiskpart("test3", "/incorrect", "", "", 1, 1),
|
||||
sdiskpart("hosts", "/etc/hosts", "bind", "", 1, 1),
|
||||
sdiskpart("proc", "/proc/run", "proc", "", 1, 1),
|
||||
]
|
||||
mock_psutil.boot_time.return_value = 1708786800.0
|
||||
|
@ -172,6 +173,11 @@ def mock_psutil(mock_process: list[MockProcess]) -> Generator:
|
|||
@pytest.fixture
|
||||
def mock_os() -> Generator:
|
||||
"""Mock os."""
|
||||
|
||||
def isdir(path: str) -> bool:
|
||||
"""Mock os.path.isdir."""
|
||||
return path != "/etc/hosts"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.systemmonitor.coordinator.os"
|
||||
) as mock_os, patch(
|
||||
|
@ -179,4 +185,5 @@ def mock_os() -> Generator:
|
|||
) as mock_os_util:
|
||||
mock_os_util.name = "nt"
|
||||
mock_os.getloadavg.return_value = (1, 2, 3)
|
||||
mock_os_util.path.isdir = isdir
|
||||
yield mock_os
|
||||
|
|
Loading…
Reference in New Issue