mirror of
https://github.com/xiaochao99/fn_nas
synced 2025-12-24 05:47:11 +00:00
modified: custom_components/fn_nas/manifest.json
modified: custom_components/fn_nas/sensor.py 修复已知问题
This commit is contained in:
@@ -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"],
|
||||
|
||||
@@ -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):
|
||||
"""返回额外的状态属性"""
|
||||
|
||||
Reference in New Issue
Block a user