From a6ec47356b9b917d0d0c2cb8577aeb21595412bc Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:22:51 +0200 Subject: [PATCH] removed duplicate code --- custom_components/truenas/coordinator.py | 119 ++++++++--------------- 1 file changed, 39 insertions(+), 80 deletions(-) diff --git a/custom_components/truenas/coordinator.py b/custom_components/truenas/coordinator.py index a4e89f9..5d286c2 100644 --- a/custom_components/truenas/coordinator.py +++ b/custom_components/truenas/coordinator.py @@ -130,86 +130,45 @@ async def _async_update_data(self): # --------------------------- def get_systeminfo(self) -> None: """Get system info from TrueNAS.""" - if self._is_scale and self._version_major >= 23: - self.ds["system_info"] = parse_api( - data=self.ds["system_info"], - source=self.api.query("system/info"), - vals=[ - {"name": "version", "default": "unknown"}, - {"name": "hostname", "default": "unknown"}, - {"name": "uptime_seconds", "default": 0}, - {"name": "system_serial", "default": "unknown"}, - {"name": "system_product", "default": "unknown"}, - {"name": "system_manufacturer", "default": "unknown"}, - ], - ensure_vals=[ - {"name": "uptimeEpoch", "default": 0}, - {"name": "cpu_temperature", "default": 0.0}, - {"name": "load_shortterm", "default": 0.0}, - {"name": "load_midterm", "default": 0.0}, - {"name": "load_longterm", "default": 0.0}, - {"name": "cpu_interrupt", "default": 0.0}, - {"name": "cpu_system", "default": 0.0}, - {"name": "cpu_user", "default": 0.0}, - {"name": "cpu_nice", "default": 0.0}, - {"name": "cpu_idle", "default": 0.0}, - {"name": "cpu_usage", "default": 0.0}, - {"name": "cache_size-arc_value", "default": 0.0}, - {"name": "cache_size-L2_value", "default": 0.0}, - {"name": "cache_ratio-arc_value", "default": 0}, - {"name": "cache_ratio-L2_value", "default": 0}, - {"name": "memory-used_value", "default": 0.0}, - {"name": "memory-free_value", "default": 0.0}, - {"name": "memory-cached_value", "default": 0.0}, - {"name": "memory-buffered_value", "default": 0.0}, - {"name": "memory-total_value", "default": 0.0}, - {"name": "memory-usage_percent", "default": 0}, - {"name": "update_available", "type": "bool", "default": False}, - {"name": "update_progress", "default": 0}, - {"name": "update_jobid", "default": 0}, - {"name": "update_state", "default": "unknown"}, - ], - ) - else: - self.ds["system_info"] = parse_api( - data=self.ds["system_info"], - source=self.api.query("system/info"), - vals=[ - {"name": "version", "default": "unknown"}, - {"name": "hostname", "default": "unknown"}, - {"name": "uptime_seconds", "default": 0}, - {"name": "system_serial", "default": "unknown"}, - {"name": "system_product", "default": "unknown"}, - {"name": "system_manufacturer", "default": "unknown"}, - ], - ensure_vals=[ - {"name": "uptimeEpoch", "default": 0}, - {"name": "cpu_temperature", "default": 0.0}, - {"name": "load_shortterm", "default": 0.0}, - {"name": "load_midterm", "default": 0.0}, - {"name": "load_longterm", "default": 0.0}, - {"name": "cpu_interrupt", "default": 0.0}, - {"name": "cpu_system", "default": 0.0}, - {"name": "cpu_user", "default": 0.0}, - {"name": "cpu_nice", "default": 0.0}, - {"name": "cpu_idle", "default": 0.0}, - {"name": "cpu_usage", "default": 0.0}, - {"name": "cache_size-arc_value", "default": 0.0}, - {"name": "cache_size-L2_value", "default": 0.0}, - {"name": "cache_ratio-arc_value", "default": 0}, - {"name": "cache_ratio-L2_value", "default": 0}, - {"name": "memory-used_value", "default": 0.0}, - {"name": "memory-free_value", "default": 0.0}, - {"name": "memory-cached_value", "default": 0.0}, - {"name": "memory-buffered_value", "default": 0.0}, - {"name": "memory-total_value", "default": 0.0}, - {"name": "memory-usage_percent", "default": 0}, - {"name": "update_available", "type": "bool", "default": False}, - {"name": "update_progress", "default": 0}, - {"name": "update_jobid", "default": 0}, - {"name": "update_state", "default": "unknown"}, - ], - ) + self.ds["system_info"] = parse_api( + data=self.ds["system_info"], + source=self.api.query("system/info"), + vals=[ + {"name": "version", "default": "unknown"}, + {"name": "hostname", "default": "unknown"}, + {"name": "uptime_seconds", "default": 0}, + {"name": "system_serial", "default": "unknown"}, + {"name": "system_product", "default": "unknown"}, + {"name": "system_manufacturer", "default": "unknown"}, + ], + ensure_vals=[ + {"name": "uptimeEpoch", "default": 0}, + {"name": "cpu_temperature", "default": 0.0}, + {"name": "load_shortterm", "default": 0.0}, + {"name": "load_midterm", "default": 0.0}, + {"name": "load_longterm", "default": 0.0}, + {"name": "cpu_interrupt", "default": 0.0}, + {"name": "cpu_system", "default": 0.0}, + {"name": "cpu_user", "default": 0.0}, + {"name": "cpu_nice", "default": 0.0}, + {"name": "cpu_idle", "default": 0.0}, + {"name": "cpu_usage", "default": 0.0}, + {"name": "cache_size-arc_value", "default": 0.0}, + {"name": "cache_size-L2_value", "default": 0.0}, + {"name": "cache_ratio-arc_value", "default": 0}, + {"name": "cache_ratio-L2_value", "default": 0}, + {"name": "memory-used_value", "default": 0.0}, + {"name": "memory-free_value", "default": 0.0}, + {"name": "memory-cached_value", "default": 0.0}, + {"name": "memory-buffered_value", "default": 0.0}, + {"name": "memory-total_value", "default": 0.0}, + {"name": "memory-usage_percent", "default": 0}, + {"name": "update_available", "type": "bool", "default": False}, + {"name": "update_progress", "default": 0}, + {"name": "update_jobid", "default": 0}, + {"name": "update_state", "default": "unknown"}, + ], + ) if not self.api.connected(): return