Skip to content

Commit

Permalink
Merge pull request #97 from dougiteixeira/add-sensors-1
Browse files Browse the repository at this point in the history
Add sensors to disk used and swap free
  • Loading branch information
dougiteixeira authored Jun 16, 2023
2 parents 8d531c9 + 395107f commit a7a2659
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions custom_components/proxmoxve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
),
ProxmoxSensorEntityDescription(
key="disk_free",
name="Disk free",
icon="mdi:harddisk",
native_unit_of_measurement=UnitOfInformation.BYTES,
value_fn=lambda x: (x.disk_total - x.disk_used),
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
entity_registry_enabled_default=False,
),
ProxmoxSensorEntityDescription(
key="disk_free_perc",
name="Disk free percentage",
Expand Down Expand Up @@ -186,6 +198,17 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
entity_registry_enabled_default=False,
),
ProxmoxSensorEntityDescription(
key="swap_used",
name="Swap used",
icon="mdi:memory",
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
entity_registry_enabled_default=False,
),
ProxmoxSensorEntityDescription(
key="swap_used_perc",
name="Swap used percentage",
Expand All @@ -209,6 +232,27 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr


PROXMOX_SENSOR_VM: Final[tuple[ProxmoxSensorEntityDescription, ...]] = (
ProxmoxSensorEntityDescription(
key=ProxmoxKeyAPIParse.CPU,
name="CPU used",
icon="mdi:cpu-64-bit",
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x >= 0 else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
),
ProxmoxSensorEntityDescription(
key="disk_free",
name="Disk free",
icon="mdi:harddisk",
native_unit_of_measurement=UnitOfInformation.BYTES,
value_fn=lambda x: (x.disk_total - x.disk_used),
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
entity_registry_enabled_default=False,
),
ProxmoxSensorEntityDescription(
key="disk_free_perc",
name="Disk free percentage",
Expand Down Expand Up @@ -251,15 +295,6 @@ class ProxmoxSensorEntityDescription(ProxmoxEntityDescription, SensorEntityDescr
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
),
ProxmoxSensorEntityDescription(
key=ProxmoxKeyAPIParse.CPU,
name="CPU used",
icon="mdi:cpu-64-bit",
native_unit_of_measurement=PERCENTAGE,
conversion_fn=lambda x: (x * 100) if x >= 0 else 0,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1,
),
ProxmoxSensorEntityDescription(
key=ProxmoxKeyAPIParse.MEMORY_FREE,
name="Memory free",
Expand Down

0 comments on commit a7a2659

Please sign in to comment.