fix charging timer

This commit is contained in:
Viktor Markstädter
2022-04-10 19:56:12 +02:00
parent c7e0754a69
commit dedbda2c84

View File

@ -67,8 +67,8 @@ class DbusGoeChargerService:
# last update # last update
self._lastUpdate = 0 self._lastUpdate = 0
# charge start time (0 is not charging) # charging time in float
self._startChargeTime = 0 self._chargingTime = 0.0
# add _update function 'timer' # add _update function 'timer'
gobject.timeout_add(250, self._update) # pause 250ms before the next request gobject.timeout_add(250, self._update) # pause 250ms before the next request
@ -178,14 +178,13 @@ class DbusGoeChargerService:
self._dbusservice['/SetCurrent'] = int(data['amp']) self._dbusservice['/SetCurrent'] = int(data['amp'])
self._dbusservice['/MaxCurrent'] = int(data['ama']) self._dbusservice['/MaxCurrent'] = int(data['ama'])
# update startChargeTime based on state change # update chargingTime, increment charge time only on active charging (2), reset when no car connected (1)
startDetected = self._dbusservice['/Status'] != 2 and int(data['car']) == 2 timeDelta = time.time() - self._lastUpdate
stopDetected = self._dbusservice['/Status'] == 2 and int(data['car']) != 2 if int(data['car']) == 2: # vehicle loads
if startDetected: self._chargingTime += timeDelta
self._startChargeTime = time.time() elif int(data['car']) == 1: # charging station ready, no vehicle
elif stopDetected: self._chargingTime = 0
self._startChargeTime = 0 self._dbusservice['/ChargingTime'] = int(self._chargingTime)
self._dbusservice['/ChargingTime'] = int(time.time() - self._startChargeTime) if self._startChargeTime else 0
self._dbusservice['/Mode'] = 0 # Manual, no control self._dbusservice['/Mode'] = 0 # Manual, no control
self._dbusservice['/MCU/Temperature'] = int(data['tmp']) self._dbusservice['/MCU/Temperature'] = int(data['tmp'])