modified: custom_components/fn_nas/manifest.json

modified:   custom_components/fn_nas/sensor.py

修复已知问题
This commit is contained in:
xiaochao
2025-12-09 19:54:31 +08:00
parent 035a7e7413
commit b6fabe3d68
2 changed files with 7 additions and 58 deletions

View File

@@ -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"],

View File

@@ -389,26 +389,9 @@ 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" # 默认单位
@property
def extra_state_attributes(self):
return {
@@ -684,26 +667,9 @@ 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" # 默认单位
@property
def extra_state_attributes(self):
"""返回总内存和已用内存GB以及原始字节值"""
@@ -858,26 +824,9 @@ 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" # 默认单位
@property
def extra_state_attributes(self):
"""返回额外的状态属性"""