diff --git a/lnxlink/config_setup.py b/lnxlink/config_setup.py index 3f5dede..41ab5ec 100755 --- a/lnxlink/config_setup.py +++ b/lnxlink/config_setup.py @@ -69,10 +69,9 @@ def userprompt_config(config_path): "This will update the MQTT credentials and topics, these are the default topics:" ) logger.info( - " MQTT Topic prefix for for monitoring: %s/%s/%s/...", + " MQTT Topic prefix for for monitoring: %s/%s/...", config["mqtt"]["prefix"], config["mqtt"]["clientId"], - config["mqtt"]["statsPrefix"], ) logger.info( " MQTT Topic prefix for for commands: %s/%s/commands/...", @@ -114,20 +113,15 @@ def userprompt_config(config_path): input(f" Change clientId [{config['mqtt']['clientId']}]: ") or config["mqtt"]["clientId"] ) - config["mqtt"]["statsPrefix"] = ( - input(f" Change statsPrefix [{config['mqtt']['statsPrefix']}]: ") - or config["mqtt"]["statsPrefix"] - ) with open(config_path, "w", encoding="UTF-8") as file: file.write(yaml.dump(config, default_flow_style=False, sort_keys=False)) logger.info("\nAll changes have been saved.") logger.info( - " MQTT Topic prefix for for monitoring: %s/%s/%s/...", + " MQTT Topic prefix for for monitoring: %s/%s/...", config["mqtt"]["prefix"], config["mqtt"]["clientId"], - config["mqtt"]["statsPrefix"], ) logger.info( " MQTT Topic prefix for for commands: %s/%s/commands/...", diff --git a/lnxlink/modules/disk_usage.py b/lnxlink/modules/disk_usage.py index 69cd578..98728e2 100644 --- a/lnxlink/modules/disk_usage.py +++ b/lnxlink/modules/disk_usage.py @@ -8,16 +8,13 @@ class Addon: def __init__(self, lnxlink): """Setup addon""" self.name = "Disk Usage" + self.lnxlink = lnxlink + self.disks = self._get_disks() def exposed_controls(self): """Exposes to home assistant""" discovery_info = {} - for disk in psutil.disk_partitions(): - if disk.fstype == "squashfs": - continue - if "docker/overlay" in disk.mountpoint: - continue - device = disk.device.replace("/", "_").strip("_") + for device in self.disks: discovery_info[f"Disk {device}"] = { "type": "sensor", "icon": "mdi:harddisk", @@ -31,6 +28,23 @@ def exposed_controls(self): def get_info(self): """Gather information from the system""" + disks = self._get_disks() + mounted = set(disks) - set(self.disks) + unmounted = set(self.disks) - set(disks) + # print(mounted, unmounted) + for disk_name in unmounted: + disks[disk_name] = self.disks[disk_name] + self.disks[disk_name]['connected'] = False + self.disks = disks + for disk_name in mounted: + self.lnxlink.setup_discovery() + return self.disks + + def _bytetomb(self, byte): + return round(byte / 1024 / 1024, 1) + + def _get_disks(self): + """Get a list of all disks""" disks = {} for disk in psutil.disk_partitions(): if disk.fstype == "squashfs": @@ -44,7 +58,5 @@ def get_info(self): disks[device]["used"] = self._bytetomb(disk_stats.used) disks[device]["free"] = self._bytetomb(disk_stats.free) disks[device]["percent"] = disk_stats.percent + disks[device]["connected"] = True return disks - - def _bytetomb(self, byte): - return round(byte / 1024 / 1024, 1)