diff --git a/dbus_service.py b/dbus_service.py index 24b33d8..c5fb66b 100644 --- a/dbus_service.py +++ b/dbus_service.py @@ -112,7 +112,7 @@ def __init__( self._dbusservice.add_path("/Connected", 1) self._dbusservice.add_path("/Latency", None) - self._dbusservice.add_path("/FirmwareVersion", 0.1) + self._dbusservice.add_path("/FirmwareVersion", read_version('version.txt')) self._dbusservice.add_path("/HardwareVersion", 0) self._dbusservice.add_path("/Position", self.acposition) # normaly only needed for pvinverter self._dbusservice.add_path("/Serial", self._get_serial(self.pvinverternumber)) diff --git a/helpers.py b/helpers.py index 9c2d4a7..0017f93 100644 --- a/helpers.py +++ b/helpers.py @@ -6,6 +6,7 @@ # system imports import functools import time +import os # our imports: import logging @@ -124,3 +125,15 @@ def wrapped_func(*args, **kwargs): logging.debug(f"function {func.__name__} finished in {round(elapsed_time * 1000)} ms") return result return wrapped_func + +def read_version(file_name): + try: + current_dir = os.path.dirname(os.path.abspath(__file__)) + file_path = os.path.join(current_dir, file_name) + with open(file_path, 'r') as file: + line = file.readline() + version = line.split(':')[-1].strip() + return version + except FileNotFoundError: + logging.error(f"File {file_name} not found in the current directory.") + return 0.1 \ No newline at end of file diff --git a/install.sh b/install.sh index ff317f6..c93d1a7 100755 --- a/install.sh +++ b/install.sh @@ -14,6 +14,15 @@ if [ -f $SCRIPT_DIR/current.log ]; then rm $SCRIPT_DIR/current.log* fi +# check if version.txt exists and is larger than 2.0.0 +if [ -f $SCRIPT_DIR/version.txt ] && + ( [ "$(grep -o 'Version: [^ ]*' version.txt | cut -d' ' -f2)" = "2.0.0" ] || + [ "$(grep -o 'Version: [^ ]*' version.txt | cut -d' ' -f2)" \> "2.0.0" ] ); then + # delete old dbus-opendtu.py file + if [ -f $SCRIPT_DIR/dbus-opendtu.py ]; then + rm $SCRIPT_DIR/dbus-opendtu.py + fi +fi # set permissions for script files chmod a+x $SCRIPT_DIR/restart.sh diff --git a/service/run b/service/run index ee967be..b707432 100644 --- a/service/run +++ b/service/run @@ -2,11 +2,11 @@ #Script Directory SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) #Define the version filename -FILENAME=$(realpath $SCRIPT_DIR/../version.txt) +CODE_VERSION_FILE=$(realpath $SCRIPT_DIR/../version.txt) exec 2>&1 #Check if the file exists -if [ -f "$FILENAME" ]; then +if [ -f "$CODE_VERSION_FILE" ]; then #If the file exists, print its contents to stdout - cat "$FILENAME" + cat "$CODE_VERSION_FILE" fi -python $(realpath $SCRIPT_DIR/../dbus_opendtu.py) +python $(realpath $SCRIPT_DIR/../dbus_opendtu.py) \ No newline at end of file diff --git a/update.sh b/update.sh index fb3cf7f..ade6546 100755 --- a/update.sh +++ b/update.sh @@ -1,6 +1,6 @@ # Set the repository name and username REPO="henne49/dbus-opendtu" -STARTUP_FILE="/data/home/root/rc.local" +STARTUP_FILE="/data/rc.local" #!/bin/bash # Check if the file exists