Skip to content

Commit

Permalink
Fix charging/dischaging status indicator
Browse files Browse the repository at this point in the history
Reimplement charging/discharging status indicator
  • Loading branch information
hif2k1 authored Sep 25, 2022
1 parent 254af28 commit 22730a7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions custom_components/battery_sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def updateBattery(self, import_amount, export_amount):
amount_to_discharge = 0.0
net_export = max(export_amount - amount_to_charge, 0)
net_import = max(amount_to_charge - export_amount, 0) + import_amount
self._charging = True
if self._tariff_sensor_id is not None:
net_money_saved = -1*amount_to_charge*float(self._hass.states.get(self._tariff_sensor_id).state)
else:
Expand All @@ -330,6 +331,10 @@ def updateBattery(self, import_amount, export_amount):
self._hass.states.get(self._tariff_sensor_id) is not None and
self._hass.states.get(self._tariff_sensor_id).state not in [STATE_UNAVAILABLE, STATE_UNKNOWN]):
net_money_saved = amount_to_discharge*float(self._hass.states.get(self._tariff_sensor_id).state)
if amount_to_charge > amount_to_discharge:
self._charging = True
else:
self._charging = False

self._charge_state = float(self._charge_state) + amount_to_charge - amount_to_discharge

Expand Down

0 comments on commit 22730a7

Please sign in to comment.