hass-core/homeassistant/components/systemmonitor/util.py
G Johansson 4f0ee20ec5
Add config flow to System Monitor (#104906)
* Initial commit for config flow to System Monitor

* sensors

* Fixes

* Works

* Add import

* entity_registry_enabled_default = False

* entity_category = diagnostic

* Create issue

* issue in config flow

* Tests

* test requirement

* codeowner

* Fix names

* processes

* Fix type

* reviews

* get info during startup once

* Select process

* Legacy import of resources

* requirements

* Allow custom

* Fix tests

* strings

* strings

* Always enable process sensors

* Fix docstrings

* skip remove sensors if no sensors

* Modify sensors

* Fix tests
2023-12-26 18:29:32 +01:00

42 lines
1.3 KiB
Python

"""Utils for System Monitor."""
import logging
import os
import psutil
_LOGGER = logging.getLogger(__name__)
def get_all_disk_mounts() -> list[str]:
"""Return all disk mount points on system."""
disks: list[str] = []
for part in psutil.disk_partitions(all=False):
if os.name == "nt":
if "cdrom" in part.opts or part.fstype == "":
# skip cd-rom drives with no disk in it; they may raise
# ENOENT, pop-up a Windows GUI error for a non-ready
# partition or just hang.
continue
disks.append(part.mountpoint)
_LOGGER.debug("Adding disks: %s", ", ".join(disks))
return disks
def get_all_network_interfaces() -> list[str]:
"""Return all network interfaces on system."""
interfaces: list[str] = []
for interface, _ in psutil.net_if_addrs().items():
interfaces.append(interface)
_LOGGER.debug("Adding interfaces: %s", ", ".join(interfaces))
return interfaces
def get_all_running_processes() -> list[str]:
"""Return all running processes on system."""
processes: list[str] = []
for proc in psutil.process_iter(["name"]):
if proc.name() not in processes:
processes.append(proc.name())
_LOGGER.debug("Running processes: %s", ", ".join(processes))
return processes