From c141e5605afa49e4386fb838b73e792a793e966a Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Wed, 3 Nov 2021 23:08:47 +0300 Subject: ac: mostly charged thing --- src/inverter-bot | 3 +++ src/monitor.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/inverter-bot b/src/inverter-bot index 6cbb645..defc712 100755 --- a/src/inverter-bot +++ b/src/inverter-bot @@ -62,6 +62,7 @@ _strings = { 'chrg_evt_current_changed': 'ℹ️ AC charging current set to %d A.', 'chrg_evt_not_charging': 'ℹ️ AC connected but not charging.', 'chrg_evt_na_solar': '⛔️AC connected, but battery won\'t be charged due to active solar power line.', + 'chrg_evt_mostly_charged': '✅ The battery is mostly charged now. The generator can be turned off.', 'battery_level_changed': 'Battery level: %s (%0.1f V under %d W load)', 'error_message': 'Error: %s.' } @@ -392,6 +393,8 @@ def monitor_charging_event_handler(event: ChargingEvent, **kwargs) -> None: args.append(kwargs['current']) elif event == ChargingEvent.AC_CHARGING_UNAVAILABLE_BECAUSE_SOLAR: key = 'na_solar' + elif event == ChargingEvent.AC_MOSTLY_CHARGED: + key = 'mostly_charged' else: logger.error('unknown charging event:', event) return diff --git a/src/monitor.py b/src/monitor.py index 398d76b..5fc2391 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -22,6 +22,7 @@ class ChargingEvent(Enum): AC_CHARGING_STARTED = auto() AC_DISCONNECTED = auto() AC_CURRENT_CHANGED = auto() + AC_MOSTLY_CHARGED = auto() AC_CHARGING_FINISHED = auto() @@ -65,6 +66,7 @@ class InverterMonitor(Thread): interrupted: bool battery_state: BatteryState charging_state: ChargingState + mostly_charged: bool def __init__(self, ac_current_range: Union[List, Tuple] = ()): super().__init__() @@ -86,6 +88,7 @@ class InverterMonitor(Thread): self.active_current = None self.battery_state = BatteryState.NORMAL self.charging_state = ChargingState.NOT_CHARGING + self.mostly_charged = False # other stuff self.interrupted = False @@ -163,6 +166,10 @@ class InverterMonitor(Thread): self.charging_event_handler(ChargingEvent.AC_CHARGING_UNAVAILABLE_BECAUSE_SOLAR) _logger.info('solar power connected during charging, entering AC_BUT_SOLAR state') + if self.mostly_charged and v > 53 and pd != BatteryPowerDirection.CHARGING: + self.ac_charging_stop(ChargingState.AC_DONE) + return + state = ChargingState.AC_OK if pd == BatteryPowerDirection.CHARGING else ChargingState.AC_WAITING if state != self.charging_state: self.charging_state = state @@ -175,7 +182,7 @@ class InverterMonitor(Thread): if self.active_current >= 30: upper_bound = 56.9 elif self.active_current == 20: - upper_bound = 56.6 + upper_bound = 56.7 else: upper_bound = 54 @@ -220,6 +227,7 @@ class InverterMonitor(Thread): if self.currents: self.currents = [] + self.mostly_charged = False self.active_current = None def ac_charging_next_current(self): @@ -232,6 +240,10 @@ class InverterMonitor(Thread): self.ac_charging_stop(ChargingState.AC_DONE) return + if current <= 10 and not self.mostly_charged: + self.mostly_charged = True + self.charging_event_handler(ChargingEvent.AC_MOSTLY_CHARGED) + try: response = inverter.exec('set-max-ac-charging-current', (0, current)) if response['result'] != 'ok': -- cgit v1.2.3