Skip to content

Commit

Permalink
Added total size attribute to pools #52
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaae committed Oct 19, 2022
1 parent 80e8c0e commit 8f59ec9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions custom_components/truenas/binary_sensor_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"scrub_end",
"scrub_secs_left",
"available_gib",
"total_gib",
]

DEVICE_ATTRIBUTES_JAIL = [
Expand Down
1 change: 1 addition & 0 deletions custom_components/truenas/sensor_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"scrub_end",
"scrub_secs_left",
"healthy",
"total_gib",
]

DEVICE_ATTRIBUTES_DATASET = [
Expand Down
32 changes: 26 additions & 6 deletions custom_components/truenas/truenas_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ def get_pool(self):
],
ensure_vals=[
{"name": "available_gib", "default": 0.0},
{"name": "total_gib", "default": 0.0},
],
)

Expand Down Expand Up @@ -583,6 +584,11 @@ def get_pool(self):
"source": "root_dataset/properties/available/parsed",
"default": 0,
},
{
"name": "root_dataset_used",
"source": "root_dataset/properties/used/parsed",
"default": 0,
},
{
"name": "scan_function",
"source": "scan/function",
Expand All @@ -609,23 +615,37 @@ def get_pool(self):
],
ensure_vals=[
{"name": "available_gib", "default": 0.0},
{"name": "total_gib", "default": 0.0},
],
)

# Process pools
tmp_dataset = {
self.data["dataset"][uid]["mountpoint"]: b2gib(vals["available"])
for uid, vals in self.data["dataset"].items()
}
tmp_dataset_available = {}
tmp_dataset_total = {}
for uid, vals in self.data["dataset"].items():
tmp_dataset_available[self.data["dataset"][uid]["mountpoint"]] = b2gib(
vals["available"]
)
tmp_dataset_total[self.data["dataset"][uid]["mountpoint"]] = b2gib(
vals["available"] + vals["used"]
)

for uid, vals in self.data["pool"].items():
if vals["path"] in tmp_dataset:
self.data["pool"][uid]["available_gib"] = tmp_dataset[vals["path"]]
if vals["path"] in tmp_dataset_available:
self.data["pool"][uid]["available_gib"] = tmp_dataset_available[
vals["path"]
]

if vals["path"] in tmp_dataset_total:
self.data["pool"][uid]["total_gib"] = tmp_dataset_total[vals["path"]]

if vals["name"] in ["boot-pool", "freenas-boot"]:
self.data["pool"][uid]["available_gib"] = b2gib(
vals["root_dataset_available"]
)
self.data["pool"][uid]["total_gib"] = b2gib(
vals["root_dataset_available"] + vals["root_dataset_used"]
)
self.data["pool"][uid].pop("root_dataset")

# ---------------------------
Expand Down

0 comments on commit 8f59ec9

Please sign in to comment.