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",
|
"domain": "fn_nas",
|
||||||
"name": "飞牛NAS",
|
"name": "飞牛NAS",
|
||||||
"version": "1.4.0",
|
"version": "1.4.1",
|
||||||
"documentation": "https://github.com/xiaochao99/fn_nas",
|
"documentation": "https://github.com/xiaochao99/fn_nas",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@xiaochao99"],
|
"codeowners": ["@xiaochao99"],
|
||||||
|
|||||||
@@ -389,25 +389,8 @@ class DiskSensor(CoordinatorEntity, SensorEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self):
|
||||||
"""动态返回单位(仅对size类型传感器)"""
|
"""返回内存单位"""
|
||||||
if self.sensor_type != "size":
|
return self._attr_native_unit_of_measurement
|
||||||
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
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
@@ -684,25 +667,8 @@ class MemoryAvailableSensor(CoordinatorEntity, SensorEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self):
|
||||||
"""动态返回单位(仅对size类型传感器)"""
|
"""返回内存单位"""
|
||||||
if self.sensor_type != "size":
|
return self._attr_native_unit_of_measurement
|
||||||
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
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
@@ -858,25 +824,8 @@ class ZFSPoolSensor(CoordinatorEntity, SensorEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self):
|
def native_unit_of_measurement(self):
|
||||||
"""动态返回单位(仅对size类型传感器)"""
|
"""返回内存单位"""
|
||||||
if self.sensor_type != "size":
|
return self._attr_native_unit_of_measurement
|
||||||
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
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user