diff --git a/homeassistant/components/energy/sensor.py b/homeassistant/components/energy/sensor.py index 387a08141a2..0c4c5eeb3b9 100644 --- a/homeassistant/components/energy/sensor.py +++ b/homeassistant/components/energy/sensor.py @@ -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