Skip to content

Commit

Permalink
Update suggested display precision and naming for energy and power se…
Browse files Browse the repository at this point in the history
…nsors
  • Loading branch information
magico13 committed Aug 13, 2024
1 parent f27b7fd commit d7a5c81
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions custom_components/emporia_vue/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ def __init__(self, coordinator, identifier) -> None:
self._iskwh = self.scale_is_energy()

self._attr_has_entity_name = True
self._attr_suggested_display_precision = 3
if self._iskwh:
self._attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
self._attr_device_class = SensorDeviceClass.ENERGY
self._attr_state_class = SensorStateClass.TOTAL
self._attr_name = f"Energy {self._scale}"
self._attr_suggested_display_precision = 3
self._attr_name = f"Energy {self.scale_readable()}"
else:
self._attr_native_unit_of_measurement = UnitOfPower.WATT
self._attr_device_class = SensorDeviceClass.POWER
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_name = f"Power {self._scale}"
self._attr_suggested_display_precision = 1
self._attr_name = f"Power {self.scale_readable()}"

@property
def device_info(self) -> DeviceInfo:
Expand Down Expand Up @@ -154,3 +155,13 @@ def scale_is_energy(self):
Scale.SECOND.value,
Scale.MINUTES_15.value,
)

def scale_readable(self):
"""Return a human readable scale."""
if self._scale == Scale.MINUTE.value:
return "Minute Average"
if self._scale == Scale.DAY.value:
return "Today"
if self._scale == Scale.MONTH.value:
return "This Month"
return self._scale

0 comments on commit d7a5c81

Please sign in to comment.