extarct s3 data with decompression

This commit is contained in:
kostas 2024-05-30 13:19:04 +02:00
parent 5813ecfee3
commit 2e8dab4bbe
1 changed files with 212 additions and 191 deletions

View File

@ -5,7 +5,9 @@ import logging
import re
import socket
import sys
import gobject
import typing
from gi.repository import GLib as glib
import signals
import config as cfg
@ -23,8 +25,10 @@ from python_libs.ie_dbus.dbus_service import DBusService
if False:
from typing import Callable, List, Iterable, NoReturn
RESET_REGISTER = 0x2087
SETTINGS_SERVICE_PREFIX = 'com.victronenergy.settings'
INVERTER_SERVICE_PREFIX = 'com.victronenergy.vebus.'
def init_modbus(tty):
@ -182,6 +186,7 @@ def publish_aggregates(service, signals, battery_statuses):
continue
values = [s.get_value(battery_status) for battery_status in battery_statuses]
value = s.aggregate(values)
service.own_properties.set(s.dbus_path, value, s.unit)
@ -273,6 +278,14 @@ def create_update_task(modbus, service, batteries):
logging.debug('starting update cycle')
# Checking if we have excess power and if so charge batteries more
target = service.remote_properties.get(get_service(SETTINGS_SERVICE_PREFIX) + '/Settings/CGwacs/AcPowerSetPoint').value or 0
actual = service.remote_properties.get(get_service(INVERTER_SERVICE_PREFIX) + '/Ac/Out/P').value or 0
if actual>target:
service.own_properties.set('/Info/MaxChargeCurrent').value = min([battery.i_max for battery in batteries])
if service.own_properties.get('/ResetBatteries').value == 1:
reset_batteries(modbus, batteries)
@ -297,6 +310,7 @@ def create_watchdog_task(main_loop):
The watchdog kills the main loop if the alive flag is not periodically reset by the update task.
Who watches the watchdog?
"""
def watchdog_task():
# type: () -> bool
@ -313,6 +327,13 @@ def create_watchdog_task(main_loop):
return watchdog_task
def get_service(self, prefix: str) -> Optional[unicode]:
service = next((s for s in self.available_services if s.startswith(prefix)), None)
if service is None:
raise Exception('no service matching ' + prefix + '* available')
return service
def main(argv):
# type: (List[str]) -> ()
@ -332,7 +353,7 @@ def main(argv):
service.own_properties.set('/ResetBatteries', value=False, writable=True) # initial value = False
main_loop = gobject.MainLoop()
main_loop = GLib.MainLoop()
service_signals = signals.init_service_signals(batteries)
publish_service_signals(service, service_signals)
@ -341,8 +362,8 @@ def main(argv):
update_task() # run it right away, so that all props are initialized before anyone can ask
watchdog_task = create_watchdog_task(main_loop)
gobject.timeout_add(cfg.UPDATE_INTERVAL * 2, watchdog_task, priority = gobject.PRIORITY_LOW) # add watchdog first
gobject.timeout_add(cfg.UPDATE_INTERVAL, update_task, priority = gobject.PRIORITY_LOW) # call update once every update_interval
GLib.timeout_add(cfg.UPDATE_INTERVAL * 2, watchdog_task, priority = GLib.PRIORITY_LOW) # add watchdog first
GLib.timeout_add(cfg.UPDATE_INTERVAL, update_task, priority = GLib.PRIORITY_LOW) # call update once every update_interval
logging.info('starting gobject.MainLoop')
main_loop.run()