Skip to content

Commit

Permalink
Merge pull request #131 from Dimand/master
Browse files Browse the repository at this point in the history
Fix inconsistent HDD mapping
  • Loading branch information
tomaae authored Mar 1, 2024
2 parents 1f937c8 + 092c08d commit 50a5bb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions custom_components/truenas/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def get_disk(self) -> None:
self.ds["disk"] = parse_api(
data=self.ds["disk"],
source=self.api.query("disk"),
key="devname",
key="identifier",
vals=[
{"name": "name", "default": "unknown"},
{"name": "devname", "default": "unknown"},
Expand All @@ -760,6 +760,8 @@ def get_disk(self) -> None:
{"name": "model", "default": "unknown"},
{"name": "rotationrate", "default": "unknown"},
{"name": "type", "default": "unknown"},
{"name": "zfs_guid", "default": "unknown"},
{"name": "identifier", "default": "unknown"},
],
ensure_vals=[
{"name": "temperature", "default": 0},
Expand All @@ -774,9 +776,11 @@ def get_disk(self) -> None:
)

if temps:
for uid in self.ds["disk"]:
if uid in temps:
self.ds["disk"][uid]["temperature"] = temps[uid]
for uid, vals in self.ds["disk"].items():
if vals["name"] in temps: # looks for devname here
self.ds["disk"][uid]["temperature"] = temps[vals["name"]]
# return devname temp to uid disk
# I feel like this will break in the future when TrueNAS updates to a more sensible system. Currently their own long term stats are broken by the changing devnames.

# ---------------------------
# get_jail
Expand Down
8 changes: 6 additions & 2 deletions custom_components/truenas/sensor_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
"model",
"rotationrate",
"type",
"name",
"devname",
"zfs_guid",
"identifier",
]

DEVICE_ATTRIBUTES_CPU = [
Expand Down Expand Up @@ -365,9 +369,9 @@ class TrueNASSensorEntityDescription(SensorEntityDescription):
ha_group="Disks",
data_path="disk",
data_attribute="temperature",
data_name="name",
data_name="identifier",
data_uid="",
data_reference="devname",
data_reference="identifier",
data_attributes_list=DEVICE_ATTRIBUTES_DISK,
),
TrueNASSensorEntityDescription(
Expand Down

0 comments on commit 50a5bb7

Please sign in to comment.