Don't round in energy cost sensor (#56258)
This commit is contained in:
parent
56b94d6809
commit
efe467217a
1 changed files with 2 additions and 4 deletions
|
@ -221,7 +221,6 @@ class EnergyCostSensor(SensorEntity):
|
|||
self._attr_state_class = STATE_CLASS_TOTAL
|
||||
self._config = config
|
||||
self._last_energy_sensor_state: State | None = None
|
||||
self._cur_value = 0.0
|
||||
# add_finished is set when either of async_added_to_hass or add_to_platform_abort
|
||||
# is called
|
||||
self.add_finished = asyncio.Event()
|
||||
|
@ -229,7 +228,6 @@ class EnergyCostSensor(SensorEntity):
|
|||
def _reset(self, energy_state: State) -> None:
|
||||
"""Reset the cost sensor."""
|
||||
self._attr_native_value = 0.0
|
||||
self._cur_value = 0.0
|
||||
self._attr_last_reset = dt_util.utcnow()
|
||||
self._last_energy_sensor_state = energy_state
|
||||
self.async_write_ha_state()
|
||||
|
@ -339,8 +337,8 @@ class EnergyCostSensor(SensorEntity):
|
|||
self._reset(energy_state_copy)
|
||||
# Update with newly incurred cost
|
||||
old_energy_value = float(self._last_energy_sensor_state.state)
|
||||
self._cur_value += (energy - old_energy_value) * energy_price
|
||||
self._attr_native_value = round(self._cur_value, 2)
|
||||
cur_value = cast(float, self._attr_native_value)
|
||||
self._attr_native_value = cur_value + (energy - old_energy_value) * energy_price
|
||||
|
||||
self._last_energy_sensor_state = energy_state
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue