From 2c5ed512dac389f3157df379453fd938149d9acd Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:32:33 +0200 Subject: [PATCH] Fixed crash when pool goes offline, fixes #152 --- custom_components/truenas/coordinator.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/custom_components/truenas/coordinator.py b/custom_components/truenas/coordinator.py index 07f9656..50a2f46 100644 --- a/custom_components/truenas/coordinator.py +++ b/custom_components/truenas/coordinator.py @@ -782,13 +782,16 @@ def get_pool(self) -> None: self.ds["pool"][uid].pop("root_dataset") - self.ds["pool"][uid]["usage"] = round( - ( - self.ds["pool"][uid]["available_gib"] - / self.ds["pool"][uid]["total_gib"] + if self.ds["pool"][uid]["total_gib"] > 0: + self.ds["pool"][uid]["usage"] = round( + ( + self.ds["pool"][uid]["available_gib"] + / self.ds["pool"][uid]["total_gib"] + ) + * 100 ) - * 100 - ) + else: + self.ds["pool"][uid]["usage"] = 0 # --------------------------- # get_dataset