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 coordinator
pull/111666/head
J. Nick Koston 2024-02-27 22:31:02 -10:00 committed by GitHub
parent f9d9ac48c7
commit 01a6b85a35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -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(

View File

@ -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