From b6fabe3d680b339768a1f8ca8e3989e4a0f92f2d Mon Sep 17 00:00:00 2001 From: xiaochao Date: Tue, 9 Dec 2025 19:54:31 +0800 Subject: [PATCH] modified: custom_components/fn_nas/manifest.json modified: custom_components/fn_nas/sensor.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复已知问题 --- custom_components/fn_nas/manifest.json | 2 +- custom_components/fn_nas/sensor.py | 63 +++----------------------- 2 files changed, 7 insertions(+), 58 deletions(-) diff --git a/custom_components/fn_nas/manifest.json b/custom_components/fn_nas/manifest.json index c8b9921..137a188 100644 --- a/custom_components/fn_nas/manifest.json +++ b/custom_components/fn_nas/manifest.json @@ -1,7 +1,7 @@ { "domain": "fn_nas", "name": "飞牛NAS", - "version": "1.4.0", + "version": "1.4.1", "documentation": "https://github.com/xiaochao99/fn_nas", "dependencies": [], "codeowners": ["@xiaochao99"], diff --git a/custom_components/fn_nas/sensor.py b/custom_components/fn_nas/sensor.py index 883f23b..c6fed57 100644 --- a/custom_components/fn_nas/sensor.py +++ b/custom_components/fn_nas/sensor.py @@ -389,25 +389,8 @@ class DiskSensor(CoordinatorEntity, SensorEntity): @property def native_unit_of_measurement(self): - """动态返回单位(仅对size类型传感器)""" - if self.sensor_type != "size": - return self._attr_native_unit_of_measurement - - # 对于size类型传感器,根据实际数据确定单位 - for zpool in self.coordinator.data.get("zpools", []): - if zpool["name"] == self.zpool_name: - size_str = zpool.get("size", "") - if size_str.endswith("T") or size_str.endswith("Ti"): - return "TB" - elif size_str.endswith("G") or size_str.endswith("Gi"): - return "GB" - elif size_str.endswith("M") or size_str.endswith("Mi"): - return "MB" - elif size_str.endswith("K") or size_str.endswith("Ki"): - return "KB" - else: - return "GB" # 默认单位 - return "GB" # 默认单位 + """返回内存单位""" + return self._attr_native_unit_of_measurement @property def extra_state_attributes(self): @@ -684,25 +667,8 @@ class MemoryAvailableSensor(CoordinatorEntity, SensorEntity): @property def native_unit_of_measurement(self): - """动态返回单位(仅对size类型传感器)""" - if self.sensor_type != "size": - return self._attr_native_unit_of_measurement - - # 对于size类型传感器,根据实际数据确定单位 - for zpool in self.coordinator.data.get("zpools", []): - if zpool["name"] == self.zpool_name: - size_str = zpool.get("size", "") - if size_str.endswith("T") or size_str.endswith("Ti"): - return "TB" - elif size_str.endswith("G") or size_str.endswith("Gi"): - return "GB" - elif size_str.endswith("M") or size_str.endswith("Mi"): - return "MB" - elif size_str.endswith("K") or size_str.endswith("Ki"): - return "KB" - else: - return "GB" # 默认单位 - return "GB" # 默认单位 + """返回内存单位""" + return self._attr_native_unit_of_measurement @property def extra_state_attributes(self): @@ -858,25 +824,8 @@ class ZFSPoolSensor(CoordinatorEntity, SensorEntity): @property def native_unit_of_measurement(self): - """动态返回单位(仅对size类型传感器)""" - if self.sensor_type != "size": - return self._attr_native_unit_of_measurement - - # 对于size类型传感器,根据实际数据确定单位 - for zpool in self.coordinator.data.get("zpools", []): - if zpool["name"] == self.zpool_name: - size_str = zpool.get("size", "") - if size_str.endswith("T") or size_str.endswith("Ti"): - return "TB" - elif size_str.endswith("G") or size_str.endswith("Gi"): - return "GB" - elif size_str.endswith("M") or size_str.endswith("Mi"): - return "MB" - elif size_str.endswith("K") or size_str.endswith("Ki"): - return "KB" - else: - return "GB" # 默认单位 - return "GB" # 默认单位 + """返回内存单位""" + return self._attr_native_unit_of_measurement @property def extra_state_attributes(self):