diff --git a/custom_components/proxmoxve/coordinator.py b/custom_components/proxmoxve/coordinator.py index 872146a..679e0ed 100644 --- a/custom_components/proxmoxve/coordinator.py +++ b/custom_components/proxmoxve/coordinator.py @@ -676,23 +676,40 @@ def poll_api_attributes() -> dict[str, Any] | None: if disk["devpath"] == self.resource_id: disk_attributes = {} disk_attributes_api = await self.hass.async_add_executor_job(poll_api_attributes) - for disk_attribute in disk_attributes_api["attributes"]: - if disk_attribute["name"] == "Power_Cycle_Count": - disk_attributes[disk_attribute["name"]]=disk_attribute["raw"] - elif disk_attribute["name"] == "Temperature_Celsius": - disk_attributes[disk_attribute["name"]]=disk_attribute["raw"].split(" ", 1)[0] + + attributes_json = [] + if "attributes" in disk_attributes_api: + attributes_json = disk_attributes_api["attributes"] + else: + if "type" in disk_attributes_api and disk_attributes_api["type"] == "text": + attributes_text = disk_attributes_api["text"].split("\n") + for value_text in attributes_text: + value_json = value_text.split(":") + if len(value_json) >= 2: + attributes_json.append( + { + "name": value_json[0].strip(), + "raw": value_json[1].strip(), + } + ) + + for disk_attribute in attributes_json: + if disk_attribute["name"] in ("Power_Cycle_Count", "Power Cycles"): + disk_attributes["Power_Cycle_Count"]=disk_attribute["raw"] + elif disk_attribute["name"] in ("Temperature_Celsius", "Temperature"): + disk_attributes["Temperature_Celsius"]=disk_attribute["raw"].split(" ", 1)[0] return ProxmoxDiskData( type=ProxmoxType.Disk, node=self.node_name, path=self.resource_id, - size=disk["size"], - health=disk["health"], - vendor=disk["vendor"], - serial=disk["serial"], - model=disk["model"], - disk_rpm=disk["rpm"], - disk_type=disk["type"], + size=disk["size"] if "size" in disk else None, + health=disk["health"] if "health" in disk else None, + vendor=disk["vendor"] if "vendor" in disk else None, + serial=disk["serial"] if "serial" in disk else None, + model=disk["model"] if "model" in disk else None, + disk_rpm=disk["rpm"] if "rpm" in disk else None, + disk_type=disk["type"] if "type" in disk else None, temperature=disk_attributes["Temperature_Celsius"] if "Temperature_Celsius" in disk_attributes else None, power_cycles=disk_attributes["Power_Cycle_Count"] if "Power_Cycle_Count" in disk_attributes else None, ) diff --git a/custom_components/proxmoxve/diagnostics.py b/custom_components/proxmoxve/diagnostics.py index 45e51cf..b61c0e2 100644 --- a/custom_components/proxmoxve/diagnostics.py +++ b/custom_components/proxmoxve/diagnostics.py @@ -49,7 +49,7 @@ def poll_api_attributes(proxmox, node: str, disk: str) -> dict[str, Any] | None: if error.status_code == 403: resources = "403 Forbidden: Permission check failed" else: - resources = "Error" + resources = error nodes = {} @@ -59,7 +59,7 @@ def poll_api_attributes(proxmox, node: str, disk: str) -> dict[str, Any] | None: if error.status_code == 403: nodes_api = "403 Forbidden: Permission check failed" else: - nodes_api = "Error" + nodes_api = error for node in nodes_api: nodes[node["node"]] = node @@ -70,7 +70,7 @@ def poll_api_attributes(proxmox, node: str, disk: str) -> dict[str, Any] | None: if error.status_code == 403: nodes[node["node"]]["qemu"] = "403 Forbidden: Permission check failed" else: - nodes[node["node"]]["qemu"] = "Error" + nodes[node["node"]]["qemu"] = error try: nodes[node["node"]]["lxc"] = await hass.async_add_executor_job(proxmox.nodes(node["node"]).lxc.get) @@ -78,7 +78,7 @@ def poll_api_attributes(proxmox, node: str, disk: str) -> dict[str, Any] | None: if error.status_code == 403: nodes[node["node"]]["lxc"] = "403 Forbidden: Permission check failed" else: - nodes[node["node"]]["lxc"] = "Error" + nodes[node["node"]]["lxc"] = error try: nodes[node["node"]]["storage"] = await hass.async_add_executor_job(proxmox.nodes(node["node"]).storage.get) @@ -86,7 +86,7 @@ def poll_api_attributes(proxmox, node: str, disk: str) -> dict[str, Any] | None: if error.status_code == 403: nodes[node["node"]]["storage"] = "403 Forbidden: Permission check failed" else: - nodes[node["node"]]["storage"] = "Error" + nodes[node["node"]]["storage"] = error try: nodes[node["node"]]["updates"] = await hass.async_add_executor_job(proxmox.nodes(node["node"]).apt.update.get) @@ -94,7 +94,12 @@ def poll_api_attributes(proxmox, node: str, disk: str) -> dict[str, Any] | None: if error.status_code == 403: nodes[node["node"]]["updates"] = "403 Forbidden: Permission check failed" else: - nodes[node["node"]]["updates"] = "Error" + nodes[node["node"]]["updates"] = error + + try: + nodes[node["node"]]["versions"] = await hass.async_add_executor_job(proxmox.nodes(node["node"]).apt.versions.get) + except ResourceException as error: + nodes[node["node"]]["updates"] = error try: disks = await hass.async_add_executor_job(proxmox.nodes(node["node"]).disks.list.get) diff --git a/custom_components/proxmoxve/manifest.json b/custom_components/proxmoxve/manifest.json index f532903..921331e 100644 --- a/custom_components/proxmoxve/manifest.json +++ b/custom_components/proxmoxve/manifest.json @@ -8,5 +8,5 @@ "issue_tracker": "https://github.com/dougiteixeira/proxmoxve/issues", "loggers": ["proxmoxer"], "requirements": ["proxmoxer==2.0.1"], - "version": "3.2.0" + "version": "3.1.0" }