diff --git a/helper/install.sh b/helper/install.sh index beeed84..6a497f9 100755 --- a/helper/install.sh +++ b/helper/install.sh @@ -5,6 +5,7 @@ if [[ $# -ne 1 ]]; then echo "Usage: $0 [--install|--uninstall|--help]" echo " --install Install the poo recorder" echo " --uninstall Uninstall the poo recorder" + echo " --update Update the installation" echo " --help Show this help message" exit 0 fi @@ -17,6 +18,9 @@ case $key in --uninstall) UNINSTALL=true ;; + --update) + UPDATE=true + ;; --help) echo "Usage: $0 [--install|--uninstall|--help]" echo " --install Install the poo recorder" @@ -45,7 +49,8 @@ install_poo_recorder() { mkdir -p $TARGET_DIR - cp $BASEDIR/../main.py $BASEDIR/../poo.py $BASEDIR/../requirements.txt $TARGET_DIR + rm -rf $BASEDIR/../recorder/__pycache__ + cp -r $BASEDIR/../recorder $BASEDIR/../requirements.txt $TARGET_DIR python3 -m venv "$TARGET_DIR/venv" @@ -53,10 +58,10 @@ install_poo_recorder() { cp $BASEDIR/poo_recorder_template.conf $BASEDIR/poo_recorder.conf - sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/main.py --port 8881+g" poo_recorder.conf - sed -i "s+directory=+directory=$TARGET_DIR+g" poo_recorder.conf - sed -i "s+user=+user=$USER+g" poo_recorder.conf - sed -i "s+group=+group=$USER+g" poo_recorder.conf + sed -i "s+command=+command=$TARGET_DIR/venv/bin/fastapi run $TARGET_DIR/recorder/main.py --port 8881+g" $BASEDIR/poo_recorder.conf + sed -i "s+directory=+directory=$TARGET_DIR+g" $BASEDIR/poo_recorder.conf + sed -i "s+user=+user=$USER+g" $BASEDIR/poo_recorder.conf + sed -i "s+group=+group=$USER+g" $BASEDIR/poo_recorder.conf sudo mv $BASEDIR/poo_recorder.conf /etc/supervisor/conf.d/poo_recorder.conf @@ -80,11 +85,17 @@ uninstall_poo_recorder() { echo "Uninstallation complete." } +update_poo_recorder() { + uninstall_poo_recorder + install_poo_recorder +} if [[ $INSTALL ]]; then install_poo_recorder elif [[ $UNINSTALL ]]; then uninstall_poo_recorder +elif [[ $UPDATE ]]; then + update_poo_recorder else echo "Invalid argument: $key" exit 1 diff --git a/recorder/__init__.py b/recorder/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/recorder/main.py similarity index 91% rename from main.py rename to recorder/main.py index 03f398b..152ccca 100644 --- a/main.py +++ b/recorder/main.py @@ -2,7 +2,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI -from poo import PooRecorder +from recorder.poo import PooRecorder recorder = PooRecorder() diff --git a/poo.py b/recorder/poo.py similarity index 97% rename from poo.py rename to recorder/poo.py index 6a9b6b2..e136e88 100644 --- a/poo.py +++ b/recorder/poo.py @@ -5,7 +5,7 @@ from fastapi_mqtt import FastMQTT, MQTTConfig class PooRecorder: mqtt_config = MQTTConfig(username="mqtt", password="mqtt", reconnect_retries=-1) # noqa: S106 - mqtt = FastMQTT(config=mqtt_config) + mqtt = FastMQTT(config=mqtt_config, client_id="poo_recorder") CONFIG_TOPIC = "homeassistant/text/poo_recorder/config" AVAILABILITY_TOPIC = "studiotj/poo_recorder/status" COMMAND_TOPIC = "studiotj/poo_recorder/update_text"