Skip to content

Commit

Permalink
Sync genset runninghours with startstop service
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinvdZee committed Jul 19, 2024
1 parent 539d081 commit 6ad5bf5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions genset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
'/Error/0/Id': dummy,
'/ProductId': dummy,
'/DeviceInstance': dummy,
'/Start': dummy
'/Start': dummy,
'/Engine/OperatingHours': dummy
},
'com.victronenergy.dcgenset': {
'/RemoteStartModeEnabled': dummy,
'/Connected': dummy,
'/Error/0/Id': dummy,
'/ProductId': dummy,
'/DeviceInstance': dummy,
'/Start': dummy
'/Start': dummy,
'/Engine/OperatingHours': dummy
}
}

Expand Down
17 changes: 12 additions & 5 deletions startstop.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ def dbus_value_changed(self, dbusServiceName, dbusPath, options, changes, device
dbusPath == '/Ac/State/AcIn1Available':
self._set_capabilities()

if dbusPath == '/Engine/OperatingHours':
self._update_accumulated_time(gensetHours=changes['Value'])

if dbusServiceName != 'com.victronenergy.system':
return
if dbusPath == '/AutoSelectedBatteryMeasurement' and self._settings['batterymeasurement'] == 'default':
Expand Down Expand Up @@ -931,11 +934,15 @@ def _check_quiet_hours(self):

return active

def _update_accumulated_time(self):
seconds = self._dbusservice['/Runtime']
accumulated = seconds - self._last_runtime_update
def _update_accumulated_time(self, gensetHours=None):
# If connected genset reports /Engine/OperatingHours, use that and also clear the offset value.
if (gensetHours):
self._settings['accumulatedtotalOffset'] = 0

seconds = gensetHours or self._dbusservice['/Runtime']
accumulated = seconds - self._last_runtime_update if (gensetHours == None) else 0

self._settings['accumulatedtotal'] = accumulatedtotal = int(self._settings['accumulatedtotal']) + accumulated
self._settings['accumulatedtotal'] = accumulatedtotal = gensetHours or int(self._settings['accumulatedtotal']) + accumulated
# Using calendar to get timestamp in UTC, not local time
today_date = str(calendar.timegm(datetime.date.today().timetuple()))

Expand All @@ -956,7 +963,7 @@ def _update_accumulated_time(self):
while len(accumulated_days) > HISTORY_DAYS:
accumulated_days.pop(min(accumulated_days.keys()), None)

# Upadate settings
# Update settings
self._settings['accumulateddaily'] = json.dumps(accumulated_days, sort_keys=True)
self._dbusservice['/TodayRuntime'] = self._interval_runtime(0)
self._dbusservice['/TestRunIntervalRuntime'] = self._interval_runtime(self._settings['testruninterval'])
Expand Down

0 comments on commit 6ad5bf5

Please sign in to comment.