Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #313 #324

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions custom_components/proxmoxve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
name="Disk free",
icon="mdi:harddisk",
native_unit_of_measurement=UnitOfInformation.BYTES,
value_fn=lambda x: (x.disk_total - x.disk_used),
value_fn=lambda x: (x.disk_total - x.disk_used)
if (UNDEFINED not in (x.disk_total, x.disk_used))
else 0,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
Expand All @@ -75,7 +77,9 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
icon="mdi:harddisk",
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x > 0 else 0,
value_fn=lambda x: 1 - (x.disk_used / x.disk_total) if x.disk_total > 0 else 0,
value_fn=lambda x: 1 - (x.disk_used / x.disk_total)
if (UNDEFINED not in (x.disk_used, x.disk_total) and x.disk_total > 0)
else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
entity_registry_enabled_default=False,
Expand Down Expand Up @@ -111,7 +115,9 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
icon="mdi:harddisk",
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x > 0 else 0,
value_fn=lambda x: (x.disk_used / x.disk_total) if x.disk_total > 0 else 0,
value_fn=lambda x: (x.disk_used / x.disk_total)
if (UNDEFINED not in (x.disk_used, x.disk_total) and x.disk_total > 0)
else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
translation_key="disk_used_perc",
Expand All @@ -136,7 +142,7 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x > 0 else 0,
value_fn=lambda x: (x.memory_free / x.memory_total)
if x.memory_total > 0
if (UNDEFINED not in (x.memory_free, x.memory_total) and x.memory_total > 0)
else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
Expand Down Expand Up @@ -173,7 +179,7 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x > 0 else 0,
value_fn=lambda x: (x.memory_used / x.memory_total)
if x.memory_total > 0
if (UNDEFINED not in (x.memory_used, x.memory_total) and x.memory_total > 0)
else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
Expand All @@ -199,7 +205,9 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
icon="mdi:memory",
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x > 0 else 0,
value_fn=lambda x: (x.swap_free / x.swap_total) if x.swap_total > 0 else 0,
value_fn=lambda x: (x.swap_free / x.swap_total)
if (UNDEFINED not in (x.swap_free, x.swap_total) and x.swap_total > 0)
else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
entity_registry_enabled_default=False,
Expand Down Expand Up @@ -235,7 +243,9 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
icon="mdi:memory",
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x > 0 else 0,
value_fn=lambda x: (x.swap_used / x.swap_total) if x.swap_total > 0 else 0,
value_fn=lambda x: (x.swap_used / x.swap_total)
if (UNDEFINED not in (x.swap_used, x.swap_total) and x.swap_total > 0)
else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
entity_registry_enabled_default=False,
Expand Down Expand Up @@ -342,7 +352,7 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
icon="mdi:server",
translation_key="status_raw",
value_fn=lambda x: x.health
if x.health not in ["running", "stopped"]
if (x.health not in ["running", "stopped", UNDEFINED])
else x.status,
),
*PROXMOX_SENSOR_CPU,
Expand Down
Loading