Skip to content

Commit

Permalink
removed duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaae committed Apr 3, 2024
1 parent 5d61497 commit a6ec473
Showing 1 changed file with 39 additions and 80 deletions.
119 changes: 39 additions & 80 deletions custom_components/truenas/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a6ec473

Please sign in to comment.