Skip to content

Commit

Permalink
Merge pull request #4 from tijsverkoyen/use-multiplier
Browse files Browse the repository at this point in the history
Use multiplier for the value
  • Loading branch information
tijsverkoyen authored Nov 3, 2022
2 parents 26d21fb + 113ccae commit e3e3259
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions custom_components/energy_id/meter_reading_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
self._record = record
self._attribute = attribute
self._state = None
self._value = None

@property
def name(self):
Expand Down Expand Up @@ -135,13 +136,23 @@ def unit_of_measurement(self) -> str:

return None

@property
def native_value(self) -> float:
return self._value

@property
def state_class(self) -> str:
return STATE_CLASS_TOTAL_INCREASING

@property
def state(self) -> float:
return self._state
if self._value is None:
return None

if self._meter.multiplier is None:
return self._value

return self._value * self._meter.multiplier

@callback
def _handle_coordinator_update(self) -> None:
Expand All @@ -150,5 +161,5 @@ def _handle_coordinator_update(self) -> None:
_LOGGER.debug(f'Updating meter {self._meter.id} reading {self._attribute} to {reading}')

if reading is not None and reading[RESPONSE_ATTRIBUTE_IGNORE] is False:
self._state = reading[RESPONSE_ATTRIBUTE_VALUE]
self._value = reading[RESPONSE_ATTRIBUTE_VALUE]
self.async_write_ha_state()

0 comments on commit e3e3259

Please sign in to comment.