From 50ff14184c926e7a2a2f7087d30d285c782f66ec Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 5 Aug 2023 16:05:44 +0200 Subject: [PATCH 01/27] another dependabot security update on cryptography --- cbpi/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 7eeec87..b57f14a 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.11" +__version__ = "4.1.12.a1" __codename__ = "Groundhog Day" diff --git a/requirements.txt b/requirements.txt index dfafb21..0b8e3b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ aiohttp-session==2.12.0 aiohttp-swagger==1.0.16 aiojobs==1.1.0 aiosqlite==0.17.0 -cryptography==41.0.2 +cryptography==41.0.3 pyopenssl==23.2.0 requests==2.31.0 voluptuous==0.13.1 diff --git a/setup.py b/setup.py index 7d9854d..2f745e6 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ setup(name='cbpi4', "aiohttp-swagger==1.0.16", "aiojobs==1.1.0 ", "aiosqlite==0.17.0", - "cryptography==41.0.2", + "cryptography==41.0.3", "pyopenssl==23.2.0", "requests==2.31.0", "voluptuous==0.13.1", From 72ea6ac2d7d47987643ddef75843ade547d96b40 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 8 Sep 2023 18:06:13 +0200 Subject: [PATCH 02/27] adaption for kleiner Brauhelfer 2.6 database change (old DB version of KBH won't work) --- cbpi/__init__.py | 4 ++-- cbpi/controller/upload_controller.py | 24 ++++++++++-------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index b57f14a..f746ee6 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.12.a1" -__codename__ = "Groundhog Day" +__version__ = "4.2.0.a1" +__codename__ = "Indian Summer" diff --git a/cbpi/controller/upload_controller.py b/cbpi/controller/upload_controller.py index e2828a2..46f16e0 100644 --- a/cbpi/controller/upload_controller.py +++ b/cbpi/controller/upload_controller.py @@ -170,7 +170,7 @@ class UploadController: # load beerxml file located in upload folder self.path = self.cbpi.config_folder.get_upload_file("kbh.db") if os.path.exists(self.path) is False: - self.cbpi.notify("File Not Found", "Please upload a kbh V2 databsel file", NotificationType.ERROR) + self.cbpi.notify("File Not Found", "Please upload a kbh V2 database file", NotificationType.ERROR) try: # Get Recipe Nmae @@ -179,19 +179,19 @@ class UploadController: c.execute('SELECT Sudname FROM Sud WHERE ID = ?', (Recipe_ID,)) row = c.fetchone() name = row[0] - # get MashIn Temp mashin_temp = None - c.execute('SELECT Temp FROM Rasten WHERE Typ = 0 AND SudID = ?', (Recipe_ID,)) + c.execute('SELECT TempWasser FROM Maischplan WHERE Typ = 0 AND SudID = ?', (Recipe_ID,)) row = c.fetchone() try: if self.cbpi.config.get("TEMP_UNIT", "C") == "C": - mashin_temp = str(int(row[0])) + mashin_temp = str(float(row[0])) else: - mashin_temp = str(round(9.0 / 5.0 * int(row[0]) + 32)) + mashin_temp = str(round(9.0 / 5.0 * float(row[0]) + 32)) except: pass - + + logging.error(mashin_temp) # get the hop addition times c.execute('SELECT Zeit, Name FROM Hopfengaben WHERE Vorderwuerze <> 1 AND SudID = ?', (Recipe_ID,)) hops = c.fetchall() @@ -201,11 +201,9 @@ class UploadController: whirlpool.append(hop) for whirl in whirlpool: hops.remove(whirl) - # get the misc addition times c.execute('SELECT Zugabedauer, Name FROM WeitereZutatenGaben WHERE Zeitpunkt = 1 AND SudID = ?', (Recipe_ID,)) miscs = c.fetchall() - try: c.execute('SELECT Zeit, Name FROM Hopfengaben WHERE Vorderwuerze = 1 AND SudID = ?', (Recipe_ID,)) FW_Hops = c.fetchall() @@ -216,9 +214,7 @@ class UploadController: c.execute('SELECT Kochdauer FROM Sud WHERE ID = ?', (Recipe_ID,)) row = c.fetchone() BoilTime = str(int(row[0])) - - - + await self.create_recipe(name) if mashin_temp is not None: @@ -238,7 +234,7 @@ class UploadController: } await self.create_step(step_string) - for row in c.execute('SELECT Name, Temp, Dauer FROM Rasten WHERE Typ <> 0 AND SudID = ?', (Recipe_ID,)): + for row in c.execute('SELECT Name, TempRast, DauerRast FROM Maischplan WHERE Typ <> 0 AND SudID = ?', (Recipe_ID,)): if mashin_temp is None and self.addmashin == "Yes": step_type = self.mashin if self.mashin != "" else "MashInStep" step_string = { "name": "MashIn", @@ -246,7 +242,7 @@ class UploadController: "AutoMode": self.AutoMode, "Kettle": self.id, "Sensor": self.kettle.sensor, - "Temp": str(int(row[1])) if self.TEMP_UNIT == "C" else str(round(9.0 / 5.0 * int(row[1]) + 32)), + "Temp": str(float(row[1])) if self.TEMP_UNIT == "C" else str(round(9.0 / 5.0 * float(row[1]) + 32)), "Timer": "0", "Notification": "Target temperature reached. Please add malt." }, @@ -263,7 +259,7 @@ class UploadController: "AutoMode": self.AutoMode, "Kettle": self.id, "Sensor": self.kettle.sensor, - "Temp": str(int(row[1])) if self.TEMP_UNIT == "C" else str(round(9.0 / 5.0 * int(row[1]) + 32)), + "Temp": str(float(row[1])) if self.TEMP_UNIT == "C" else str(round(9.0 / 5.0 * float(row[1]) + 32)), "Timer": str(int(row[2])) }, "status_text": "", From 252c2d171bae2e62e5830f2179f7b2a7bc20f967 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:17:03 +0200 Subject: [PATCH 03/27] test for bookworm -> staring cbpi w/o sudo install with pipx --- cbpi/cli.py | 11 +++++------ cbpi/extension/onewire/__init__.py | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 416883b..2631ba3 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -44,8 +44,8 @@ class CraftBeerPiCli(): def list_one_wire(self): print("List 1Wire") - call(["modprobe", "w1-gpio"]) - call(["modprobe", "w1-therm"]) + call(["sudo","modprobe", "w1-gpio"]) + call(["sudo","modprobe", "w1-therm"]) try: for dirname in os.listdir('/sys/bus/w1/devices'): if (dirname.startswith("28") or dirname.startswith("10")): @@ -155,7 +155,7 @@ class CraftBeerPiCli(): if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False: srcfile = self.config.get_file_path("craftbeerpi.service") destfile = os.path.join("/etc/systemd/system") - shutil.copy(srcfile, destfile) + shutil.os.system('sudo cp "{}" "{}"'.format(srcfile,destfile)) print("Copied craftbeerpi.service to /etc/systemd/system") os.system('systemctl enable craftbeerpi.service') print('Enabled craftbeerpi service') @@ -167,7 +167,7 @@ class CraftBeerPiCli(): print(e) return return - elif(name == "off"): + elif(name == "off"): print("Remove craftbeerpi.service from systemd") try: status = os.popen('systemctl list-units --type=service --state=running | grep craftbeerpi.service').read() @@ -180,7 +180,7 @@ class CraftBeerPiCli(): print('craftbeerpi.service service is not running') if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is True: - os.remove(os.path.join("/etc/systemd/system","craftbeerpi.service")) + shutil.os.system('sudo rm -rf "{}"'.format(os.path.join("/etc/systemd/system","craftbeerpi.service"))) print("Deleted craftbeerpi.service from /etc/systemd/system") else: print("craftbeerpi.service is not located in /etc/systemd/system") @@ -189,7 +189,6 @@ class CraftBeerPiCli(): return return - def chromium(self, name): '''Enable or disable autostart''' if(name == "status"): diff --git a/cbpi/extension/onewire/__init__.py b/cbpi/extension/onewire/__init__.py index de78c78..56f336f 100644 --- a/cbpi/extension/onewire/__init__.py +++ b/cbpi/extension/onewire/__init__.py @@ -170,7 +170,7 @@ def setup(cbpi): cbpi.plugin.register("OneWire", OneWire) try: # Global Init - call(["modprobe", "w1-gpio"]) - call(["modprobe", "w1-therm"]) + call(["sudo","modprobe", "w1-gpio"]) + call(["sudo","modprobe", "w1-therm"]) except Exception as e: pass From 8b2aaace1e0f33f4558c0389cb46551e0bab0791 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:20:07 +0200 Subject: [PATCH 04/27] changed craftbeerpi.service and cbpi version --- cbpi/__init__.py | 2 +- cbpi/config/craftbeerpi.service | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index f746ee6..da519e1 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a1" +__version__ = "4.2.0.a2" __codename__ = "Indian Summer" diff --git a/cbpi/config/craftbeerpi.service b/cbpi/config/craftbeerpi.service index cd02dce..c8f3d9f 100644 --- a/cbpi/config/craftbeerpi.service +++ b/cbpi/config/craftbeerpi.service @@ -3,7 +3,7 @@ Description=Craftbeer Pi [Service] WorkingDirectory=/home/pi -ExecStart=/usr/local/bin/cbpi start +ExecStart=/home/pi/.local/bin/cbpi start [Install] WantedBy=multi-user.target From e044545a5b91466c9d7e299b818b3097d11394c4 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:33:41 +0200 Subject: [PATCH 05/27] chromium autostart should be also working w/o sudo --- cbpi/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 2631ba3..3845ab5 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -202,7 +202,7 @@ class CraftBeerPiCli(): if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is False: srcfile = self.config.get_file_path("chromium.desktop") destfile = os.path.join("/etc/xdg/autostart/") - shutil.copy(srcfile, destfile) + shutil.os.system('sudo cp "{}" "{}"'.format(srcfile,destfile)) print("Copied chromium.desktop to /etc/xdg/autostart/") else: print("chromium.desktop is already located in /etc/xdg/autostart/") @@ -214,7 +214,7 @@ class CraftBeerPiCli(): print("Remove chromium.desktop from /etc/xdg/autostart/") try: if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is True: - os.remove(os.path.join("/etc/xdg/autostart/","chromium.desktop")) + shutil.os.system('sudo rm -rf "{}"'.format(os.path.join("/etc/xdg/autostart/","chromium.desktop"))) print("Deleted chromium.desktop from /etc/xdg/autostart/") else: print("chromium.desktop is not located in /etc/xdg/autostart/") From 0ec02447d5c26addf82c264bcec43f2280bd4cf3 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:39:00 +0200 Subject: [PATCH 06/27] add shutil to autostart cmdline -> no need to enter pwd several times --- cbpi/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 3845ab5..2b913c1 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -157,9 +157,9 @@ class CraftBeerPiCli(): destfile = os.path.join("/etc/systemd/system") shutil.os.system('sudo cp "{}" "{}"'.format(srcfile,destfile)) print("Copied craftbeerpi.service to /etc/systemd/system") - os.system('systemctl enable craftbeerpi.service') + shutil.os.system('sudo systemctl enable craftbeerpi.service') print('Enabled craftbeerpi service') - os.system('systemctl start craftbeerpi.service') + shutil.os.system('sudo systemctl start craftbeerpi.service') print('Started craftbeerpi.service') else: print("craftbeerpi.service is already located in /etc/systemd/system") @@ -172,9 +172,9 @@ class CraftBeerPiCli(): try: status = os.popen('systemctl list-units --type=service --state=running | grep craftbeerpi.service').read() if status.find("craftbeerpi.service") != -1: - os.system('systemctl stop craftbeerpi.service') + shutil.os.system('sudo systemctl stop craftbeerpi.service') print('Stopped craftbeerpi service') - os.system('systemctl disable craftbeerpi.service') + shutil.os.system('sudo systemctl disable craftbeerpi.service') print('Removed craftbeerpi.service as service') else: print('craftbeerpi.service service is not running') From 4721cf3a8cf5b9e1f7d7d5ced3e70cf9cad6b319 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 15 Oct 2023 09:59:05 +0200 Subject: [PATCH 07/27] support different users for autostart --- cbpi/cli.py | 18 ++++++++++++++++-- cbpi/config/craftbeerpi.service | 9 --------- cbpi/config/craftbeerpi.template | 9 +++++++++ cbpi/configFolder.py | 8 ++++---- 4 files changed, 29 insertions(+), 15 deletions(-) delete mode 100644 cbpi/config/craftbeerpi.service create mode 100644 cbpi/config/craftbeerpi.template diff --git a/cbpi/cli.py b/cbpi/cli.py index 2b913c1..64eca20 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -150,12 +150,27 @@ class CraftBeerPiCli(): else: print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL)) elif(name == "on"): + user=os.getlogin() print("Add craftbeerpi.service to systemd") try: if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False: + templatefile=self.config.get_file_path("craftbeerpi.template") + shutil.os.system('cp "{}" "{}"'.format(templatefile,self.config.get_file_path("craftbeerpi.service"))) srcfile = self.config.get_file_path("craftbeerpi.service") + import jinja2 + + templateLoader = jinja2.FileSystemLoader(searchpath=os.path.join(self.config.get_file_path(""))) + templateEnv = jinja2.Environment(loader=templateLoader) + operatingsystem = str(platform.system()).lower() + if operatingsystem.startswith("win"): + srcfile=str(srcfile).replace('\\','/') + + template = templateEnv.get_template("craftbeerpi.service") + outputText = template.render(user=user) + with open(srcfile, "w") as fh: + fh.write(outputText) destfile = os.path.join("/etc/systemd/system") - shutil.os.system('sudo cp "{}" "{}"'.format(srcfile,destfile)) + shutil.os.system('sudo mv "{}" "{}"'.format(srcfile,destfile)) print("Copied craftbeerpi.service to /etc/systemd/system") shutil.os.system('sudo systemctl enable craftbeerpi.service') print('Enabled craftbeerpi service') @@ -188,7 +203,6 @@ class CraftBeerPiCli(): print(e) return return - def chromium(self, name): '''Enable or disable autostart''' if(name == "status"): diff --git a/cbpi/config/craftbeerpi.service b/cbpi/config/craftbeerpi.service deleted file mode 100644 index c8f3d9f..0000000 --- a/cbpi/config/craftbeerpi.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Craftbeer Pi - -[Service] -WorkingDirectory=/home/pi -ExecStart=/home/pi/.local/bin/cbpi start - -[Install] -WantedBy=multi-user.target diff --git a/cbpi/config/craftbeerpi.template b/cbpi/config/craftbeerpi.template new file mode 100644 index 0000000..1fc26e3 --- /dev/null +++ b/cbpi/config/craftbeerpi.template @@ -0,0 +1,9 @@ +[Unit] +Description=Craftbeer Pi + +[Service] +WorkingDirectory=/home/{{ user }} +ExecStart=/home/{{ user }}/.local/bin/cbpi start + +[Install] +WantedBy=multi-user.target diff --git a/cbpi/configFolder.py b/cbpi/configFolder.py index 807550b..2cffc16 100644 --- a/cbpi/configFolder.py +++ b/cbpi/configFolder.py @@ -94,7 +94,7 @@ class ConfigFolder: #['fermenter_data.json', 'file'], created by fermentation_controller @ start if not available #['step_data.json', 'file'], created by step_controller @ start if not available ['config.json', 'file'], - ['craftbeerpi.service', 'file'], + ['craftbeerpi.template', 'file'], ['chromium.desktop', 'file'], ['dashboard', 'folder'], ['dashboard/widgets', 'folder'], @@ -181,7 +181,7 @@ class ConfigFolder: self.copyDefaultFileIfNotExists("fermenter_data.json") self.copyDefaultFileIfNotExists("step_data.json") self.copyDefaultFileIfNotExists("config.json") - self.copyDefaultFileIfNotExists("craftbeerpi.service") + self.copyDefaultFileIfNotExists("craftbeerpi.template") self.copyDefaultFileIfNotExists("chromium.desktop") print("Config Folder created") @@ -206,5 +206,5 @@ class ConfigFolder: shutil.chown(os.path.join(dirpath, filename), owner, group) except: print("problems assigning file or folder permissions") - print("if this happend on windows its fine") - print("if this happend in the dev container running inside windows its also fine but you might have to rebuild the container if you run into further problems") + print("if this happened on windows its fine") + print("if this happened in the dev container running inside windows its also fine but you might have to rebuild the container if you run into further problems") From 7594395b4bcec016ca7737d449c0dea7488be40f Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:01:17 +0200 Subject: [PATCH 08/27] update version # --- cbpi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index da519e1..218a3d5 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a2" +__version__ = "4.2.0.a3" __codename__ = "Indian Summer" From bead2b30aedba5a53481062d1d8c8602d6827526 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:43:26 +0200 Subject: [PATCH 09/27] copy craftbeerpi.template file to config folder if not existing after upgrade --- cbpi/__init__.py | 2 +- cbpi/configFolder.py | 11 ++++++++--- requirements.txt | 2 +- setup.py | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 218a3d5..8b2bf2b 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a3" +__version__ = "4.2.0.a4" __codename__ = "Indian Summer" diff --git a/cbpi/configFolder.py b/cbpi/configFolder.py index 2cffc16..198bf29 100644 --- a/cbpi/configFolder.py +++ b/cbpi/configFolder.py @@ -106,7 +106,7 @@ class ConfigFolder: ] for checking in required_config_content: if self.inform_missing_content(self.check_for_file_or_folder(os.path.join(self.configFolderPath, checking[0]), checking[1])): - # since there is no complete config we now check if the config folde rmay be completely empty to show hints: + # since there is no complete config we now check if the config folder may be completely empty to show hints: if len(os.listdir(os.path.join(self.configFolderPath))) == 0 : print("***************************************************") print(f"the config folder '{self.configFolderPath}' seems to be completely empty") @@ -118,7 +118,7 @@ class ConfigFolder: print("***************************************************") return False - # if cbpi_dashboard_1.json doesnt exist at the new location (configFolderPath/dashboard) + # if cbpi_dashboard_1.json does'nt exist at the new location (configFolderPath/dashboard) # we move every cbpi_dashboard_n.json file from the old location (configFolderPath) there. # this could be a config zip file restore from version 4.0.7.a4 or prior. dashboard_1_path = os.path.join(self.configFolderPath, 'dashboard', 'cbpi_dashboard_1.json') @@ -132,7 +132,7 @@ class ConfigFolder: try: with open(dashboard_1_path, 'r') as f: data = json.load(f) - if (len(data['elements']) == 0): # there may exist some pathes but pathes without elements in dashboard is not very likely + if (len(data['elements']) == 0): # there may exist some paths but paths without elements in dashboard is not very likely return True else: return False @@ -142,6 +142,11 @@ class ConfigFolder: def inform_missing_content(self, whatsmissing : str): if whatsmissing == "": return False + # Starting with cbpi 4.2.0, the craftbeerpi.service file will be created dynamically from the template file based on the user id. + # Therefore, the service file is replaced with a template file in the config folder + if whatsmissing.find("craftbeerpi.template"): + self.copyDefaultFileIfNotExists("craftbeerpi.template") + return False print("***************************************************") print(f"CraftBeerPi config content not found: {whatsmissing}") print("Please run 'cbpi setup' before starting the server ") diff --git a/requirements.txt b/requirements.txt index 0b8e3b7..5102103 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ aiohttp-session==2.12.0 aiohttp-swagger==1.0.16 aiojobs==1.1.0 aiosqlite==0.17.0 -cryptography==41.0.3 +cryptography==41.0.4 pyopenssl==23.2.0 requests==2.31.0 voluptuous==0.13.1 diff --git a/setup.py b/setup.py index 2f745e6..36cb773 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ setup(name='cbpi4', "aiohttp-swagger==1.0.16", "aiojobs==1.1.0 ", "aiosqlite==0.17.0", - "cryptography==41.0.3", + "cryptography==41.0.4", "pyopenssl==23.2.0", "requests==2.31.0", "voluptuous==0.13.1", From 1b666be9bc75c1d66e98324ff69935220316aa9d Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:30:26 +0200 Subject: [PATCH 10/27] fix for installation on bullseye with sudo and autostart --- cbpi/__init__.py | 2 +- cbpi/cli.py | 5 ++++- cbpi/config/craftbeerpi.template | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 8b2bf2b..7aca342 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a4" +__version__ = "4.2.0.a5" __codename__ = "Indian Summer" diff --git a/cbpi/cli.py b/cbpi/cli.py index 64eca20..a885bf6 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -151,6 +151,9 @@ class CraftBeerPiCli(): print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL)) elif(name == "on"): user=os.getlogin() + path="/usr/local/bin/cbpi start" + if os.path.exists("/home/"+user+"/.local/bin/cbpi") is True: + path="/home/"+user+"/.local/bin/cbpi start" print("Add craftbeerpi.service to systemd") try: if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False: @@ -166,7 +169,7 @@ class CraftBeerPiCli(): srcfile=str(srcfile).replace('\\','/') template = templateEnv.get_template("craftbeerpi.service") - outputText = template.render(user=user) + outputText = template.render(user=user, path=path) with open(srcfile, "w") as fh: fh.write(outputText) destfile = os.path.join("/etc/systemd/system") diff --git a/cbpi/config/craftbeerpi.template b/cbpi/config/craftbeerpi.template index 1fc26e3..eb8092c 100644 --- a/cbpi/config/craftbeerpi.template +++ b/cbpi/config/craftbeerpi.template @@ -3,7 +3,7 @@ Description=Craftbeer Pi [Service] WorkingDirectory=/home/{{ user }} -ExecStart=/home/{{ user }}/.local/bin/cbpi start +ExecStart={{ path }} start [Install] WantedBy=multi-user.target From 6d8faa7f75d9c84352a6b168e6403d5a52aac9a4 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:33:21 +0200 Subject: [PATCH 11/27] fix --- cbpi/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index a885bf6..3618f86 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -151,9 +151,9 @@ class CraftBeerPiCli(): print("CraftBeerPi Autostart is {}OFF{}".format(Fore.RED,Style.RESET_ALL)) elif(name == "on"): user=os.getlogin() - path="/usr/local/bin/cbpi start" + path="/usr/local/bin/cbpi" if os.path.exists("/home/"+user+"/.local/bin/cbpi") is True: - path="/home/"+user+"/.local/bin/cbpi start" + path="/home/"+user+"/.local/bin/cbpi" print("Add craftbeerpi.service to systemd") try: if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is False: From 8457e23eab8c726524d45067d0f3b8dbb8646381 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:14:22 +0200 Subject: [PATCH 12/27] test on onewire setup --- cbpi/__init__.py | 2 +- cbpi/cli.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 7aca342..906a12e 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a5" +__version__ = "4.2.0.a6" __codename__ = "Indian Summer" diff --git a/cbpi/cli.py b/cbpi/cli.py index 3618f86..46e8e38 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -38,8 +38,11 @@ class CraftBeerPiCli(): def setup_one_wire(self): print("Setting up 1Wire") - with open('/boot/config.txt', 'w') as f: - f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") + with open('/boot/config.txt', 'r') as f: + lines=f.readlines() + #f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") + + print(lines) print("/boot/config.txt created") def list_one_wire(self): From 5f4c957fc5b177a04328dfb7a54491adb912d338 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:22:25 +0200 Subject: [PATCH 13/27] extend w1 test --- cbpi/cli.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 46e8e38..25afe8a 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -41,8 +41,15 @@ class CraftBeerPiCli(): with open('/boot/config.txt', 'r') as f: lines=f.readlines() #f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") + active=False + for line in lines: + print(line) + if line.find("dtoverlay=w1-gpio"): + active=True + if not active: + lines.append("dtoverlay=w1-gpio,gpiopin=4,pullup=on") + print("Added w1-gpio") - print(lines) print("/boot/config.txt created") def list_one_wire(self): From 69da4beff76083b44c4aaf78884ded8df301ae17 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:24:47 +0200 Subject: [PATCH 14/27] further test --- cbpi/cli.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 25afe8a..51ee60a 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -41,15 +41,11 @@ class CraftBeerPiCli(): with open('/boot/config.txt', 'r') as f: lines=f.readlines() #f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") - active=False + lines.append("dtoverlay=w1-gpio,gpiopin=4,pullup=on") + for line in lines: print(line) - if line.find("dtoverlay=w1-gpio"): - active=True - if not active: - lines.append("dtoverlay=w1-gpio,gpiopin=4,pullup=on") - print("Added w1-gpio") - + print("/boot/config.txt created") def list_one_wire(self): From aa8e5eec2cb88107e477aa7f9b6bb798ca93af34 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:30:59 +0200 Subject: [PATCH 15/27] further onewire setup test --- cbpi/cli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cbpi/cli.py b/cbpi/cli.py index 51ee60a..b612ec3 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -46,6 +46,12 @@ class CraftBeerPiCli(): for line in lines: print(line) + configtemppath=os.path.join(self.config.get_file_path(""),"config.txt") + print(configtemppath) + + with open(configtemppath, 'w') as f: + f.write(lines) + print("/boot/config.txt created") def list_one_wire(self): From f00a646a2adb16ecd53e4147c80ab103ec5fd335 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:33:37 +0200 Subject: [PATCH 16/27] another onewire setup test --- cbpi/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index b612ec3..483692d 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -50,7 +50,8 @@ class CraftBeerPiCli(): print(configtemppath) with open(configtemppath, 'w') as f: - f.write(lines) + for line in lines: + f.write(line) print("/boot/config.txt created") From 76ee4b74a7cb6cd6e65c4697490577d72f64b76e Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:38:15 +0200 Subject: [PATCH 17/27] next onewire setup test --- cbpi/cli.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 483692d..88d6d5e 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -42,16 +42,15 @@ class CraftBeerPiCli(): lines=f.readlines() #f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") lines.append("dtoverlay=w1-gpio,gpiopin=4,pullup=on") - - for line in lines: - print(line) - - configtemppath=os.path.join(self.config.get_file_path(""),"config.txt") - print(configtemppath) - - with open(configtemppath, 'w') as f: + + configtempfile=os.path.join(self.config.get_file_path(""),"config.txt") + + with open(configtempfile, 'w') as f: for line in lines: f.write(line) + destfile="/boot/config.txt" + + shutil.os.system('sudo mv "{}" "{}"'.format(configtempfile,destfile)) print("/boot/config.txt created") From 60108f0594804631480c968af6b1006c64f58ed3 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:41:30 +0200 Subject: [PATCH 18/27] next test --- cbpi/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index 88d6d5e..d57a3c2 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -50,7 +50,7 @@ class CraftBeerPiCli(): f.write(line) destfile="/boot/config.txt" - shutil.os.system('sudo mv "{}" "{}"'.format(configtempfile,destfile)) + shutil.os.system('sudo cp "{}" "{}"'.format(configtempfile,destfile)) print("/boot/config.txt created") From f03bb14143a99a4331930d0db8af9ffbb2637020 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:45:05 +0200 Subject: [PATCH 19/27] next onewire setup test --- cbpi/cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cbpi/cli.py b/cbpi/cli.py index d57a3c2..ab7d6dd 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -50,7 +50,9 @@ class CraftBeerPiCli(): f.write(line) destfile="/boot/config.txt" + #copy and remove afterwards as mv will work, but raise an error message due to different file owners shutil.os.system('sudo cp "{}" "{}"'.format(configtempfile,destfile)) + shutil.os.system('rm -rf "{}"'.format(configtempfile)) print("/boot/config.txt created") From 550f6551acee7fdf979c5959b8195202fd6dcba7 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:52:32 +0100 Subject: [PATCH 20/27] just some minor changes in the tests --- cbpi/cli.py | 1 - tests/cbpi-test-config/config.json | 6 +++--- tests/test_sensor.py | 1 - tests/test_step.py | 2 -- tests/test_system.py | 1 - 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index ab7d6dd..dbfdb60 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -40,7 +40,6 @@ class CraftBeerPiCli(): print("Setting up 1Wire") with open('/boot/config.txt', 'r') as f: lines=f.readlines() - #f.write("dtoverlay=w1-gpio,gpiopin=4,pullup=on") lines.append("dtoverlay=w1-gpio,gpiopin=4,pullup=on") configtempfile=os.path.join(self.config.get_file_path(""),"config.txt") diff --git a/tests/cbpi-test-config/config.json b/tests/cbpi-test-config/config.json index 298b8b0..c71bc3b 100644 --- a/tests/cbpi-test-config/config.json +++ b/tests/cbpi-test-config/config.json @@ -80,10 +80,10 @@ "options": null, "source": "hidden", "type": "string", - "value": "4.1.10.a1" + "value": "4.2.0.a6" }, "CSVLOGFILES": { - "description": "Write sensor data to csv logfiles", + "description": "Write sensor data to csv logfiles (enabling requires restart)", "name": "CSVLOGFILES", "options": [ { @@ -100,7 +100,7 @@ "value": "Yes" }, "INFLUXDB": { - "description": "Write sensor data to influxdb", + "description": "Write sensor data to influxdb (enabling requires restart)", "name": "INFLUXDB", "options": [ { diff --git a/tests/test_sensor.py b/tests/test_sensor.py index 250c4b9..7544f2b 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -4,7 +4,6 @@ from tests.cbpi_config_fixture import CraftBeerPiTestCase class SensorTestCase(CraftBeerPiTestCase): - @unittest_run_loop async def test_crud(self): data = { diff --git a/tests/test_step.py b/tests/test_step.py index a4ce794..6562ad9 100644 --- a/tests/test_step.py +++ b/tests/test_step.py @@ -4,7 +4,6 @@ from tests.cbpi_config_fixture import CraftBeerPiTestCase class StepTestCase(CraftBeerPiTestCase): - @unittest_run_loop async def test_get(self): resp = await self.client.request("GET", "/step2") @@ -12,7 +11,6 @@ class StepTestCase(CraftBeerPiTestCase): assert resp.status == 200 - @unittest_run_loop async def test_crud(self): data = { "name": "Test", diff --git a/tests/test_system.py b/tests/test_system.py index 3cbbc7b..19bf185 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -4,7 +4,6 @@ from tests.cbpi_config_fixture import CraftBeerPiTestCase class IndexTestCase(CraftBeerPiTestCase): - @unittest_run_loop async def test_endpoints(self): # Test Index Page resp = await self.client.post(path="/system/restart") From aa069c713c5a7301af4ab5cb2a70e236d4a171e6 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 3 Nov 2023 06:55:42 +0100 Subject: [PATCH 21/27] pyfiglet to version 1.0.2 and adaption in system controller to show ip address correctly --- cbpi/__init__.py | 2 +- cbpi/controller/system_controller.py | 4 ++-- requirements.txt | 4 ++-- setup.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 906a12e..4082435 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a6" +__version__ = "4.2.0.a7" __codename__ = "Indian Summer" diff --git a/cbpi/controller/system_controller.py b/cbpi/controller/system_controller.py index b683679..d357d1b 100644 --- a/cbpi/controller/system_controller.py +++ b/cbpi/controller/system_controller.py @@ -219,12 +219,12 @@ class SystemController: for nic, addrs in ethernet.items(): if nic == "eth0": for addr in addrs: - if str(addr.family) == "AddressFamily.AF_INET": + if str(addr.family) == "AddressFamily.AF_INET" or str(addr.family) == "2": if addr.address: eth0IP = addr.address if nic == "wlan0": for addr in addrs: - if str(addr.family) == "AddressFamily.AF_INET": + if str(addr.family) == "AddressFamily.AF_INET" or str(addr.family) == "2": if addr.address: wlan0IP = addr.address info = psutil.net_if_stats() diff --git a/requirements.txt b/requirements.txt index 5102103..2c426f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ cryptography==41.0.4 pyopenssl==23.2.0 requests==2.31.0 voluptuous==0.13.1 -pyfiglet==0.8.post1 +pyfiglet==1.0.2 pandas==1.5.3 shortuuid==1.0.11 tabulate==0.9.0 @@ -20,7 +20,7 @@ cbpi4gui click==8.1.3 importlib_metadata==4.11.1 aiomqtt==1.0.0 -psutil==5.9.4 +psutil==5.9.6 zipp>=0.5 colorama==0.4.6 pytest-aiohttp diff --git a/setup.py b/setup.py index 36cb773..a8735ec 100644 --- a/setup.py +++ b/setup.py @@ -51,14 +51,14 @@ setup(name='cbpi4', "pyopenssl==23.2.0", "requests==2.31.0", "voluptuous==0.13.1", - "pyfiglet==0.8.post1", + "pyfiglet==1.0.2", 'click==8.1.3', 'shortuuid==1.0.11', 'tabulate==0.9.0', 'aiomqtt==1.0.0', 'inquirer==3.1.1', 'colorama==0.4.6', - 'psutil==5.9.4', + 'psutil==5.9.6', 'cbpi4gui', 'importlib_metadata', 'numpy==1.24.1', From 65a1e54632c51443c2a5415aa67cc66d831374a4 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:32:18 +0100 Subject: [PATCH 22/27] always log cbpi version at start (info -> warning) --- cbpi/__init__.py | 2 +- cbpi/craftbeerpi.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 4082435..8b1edcf 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a7" +__version__ = "4.2.0.a8" __codename__ = "Indian Summer" diff --git a/cbpi/craftbeerpi.py b/cbpi/craftbeerpi.py index 975a91a..149b2c3 100644 --- a/cbpi/craftbeerpi.py +++ b/cbpi/craftbeerpi.py @@ -260,9 +260,9 @@ class CraftBeerPi: def _print_logo(self): from pyfiglet import Figlet f = Figlet(font='big') - logger.info("\n%s" % f.renderText("CraftBeerPi %s " % self.version)) - logger.info("www.CraftBeerPi.com") - logger.info("(c) 2021/2022 Manuel Fritsch / Alexander Vollkopf") + logger.warning("\n%s" % f.renderText("CraftBeerPi %s " % self.version)) + logger.warning("www.CraftBeerPi.com") + logger.warning("(c) 2021/2022/2023 Manuel Fritsch / Alexander Vollkopf") def _setup_http_index(self): async def http_index(request): From beb350978e1b77d5163ea44ffe973abe1c6ecb10 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 14 Nov 2023 18:33:23 +0100 Subject: [PATCH 23/27] add debug-log-level to config.yaml to enable different logging level also in cbpi service --- cbpi/__init__.py | 2 +- cbpi/cli.py | 21 ++++++++++++++++----- cbpi/config/config.yaml | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 8b1edcf..21977a3 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a8" +__version__ = "4.2.0.a9" __codename__ = "Indian Summer" diff --git a/cbpi/cli.py b/cbpi/cli.py index dbfdb60..1221547 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -1,6 +1,7 @@ import logging from pathlib import Path import requests +from cbpi import __version__, __codename__ from cbpi.configFolder import ConfigFolder from cbpi.utils.utils import load_config from zipfile import ZipFile @@ -258,16 +259,26 @@ class CraftBeerPiCli(): @click.pass_context @click.option('--config-folder-path', '-c', default="./config", type=click.Path(), help="Specify where the config folder is located. Defaults to './config'.") @click.option('--logs-folder-path', '-l', default="", type=click.Path(), help="Specify where the log folder is located. Defaults to '../logs' relative from the config folder.") -@click.option('--debug-log-level', '-d', default="30", type=int, help="Specify the log level you want to write to all logs. 0=ALL, 10=DEBUG, 20=INFO 30(default)=WARNING, 40=ERROR, 50=CRITICAL") +@click.option('--debug-log-level', '-d', default="99", type=int, help="Specify the log level you want to write to all logs. 0=ALL, 10=DEBUG, 20=INFO 30(default)=WARNING, 40=ERROR, 50=CRITICAL. Can be also set in config.yaml (debug-log-level: INT)") def main(context, config_folder_path, logs_folder_path, debug_log_level): - print("---------------------") - print("Welcome to CBPi") - print("---------------------") + print("--------------------------") + print("Welcome to CBPi "+__version__) + print("--------------------------") if logs_folder_path == "": logs_folder_path = os.path.join(Path(config_folder_path).absolute().parent, 'logs') formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s') + static_config = load_config(ConfigFolder(config_folder_path, logs_folder_path).get_file_path("config.yaml")) + try: + if debug_log_level == 99: + debug_log_level=static_config['debug-log-level'] + except: + debug_log_level=30 + logging.basicConfig(format=formatter, stream=logging.StreamHandler()) logger = logging.getLogger() + print("*******************************") + print("Set Debug-log-level to {}".format(debug_log_level)) + print("*******************************") logger.setLevel(debug_log_level) try: if not os.path.isdir(logs_folder_path): @@ -292,7 +303,7 @@ def setup(context): @click.option('--list', is_flag=True, help="List all 1Wire Devices") @click.option('--setup', is_flag=True, help="Setup 1Wire on Raspberry Pi") def onewire(context, list, setup): - '''Setup 1wire on Raspberry Pi''' + '''(--setup | --list) Setup 1wire on Raspberry Pi or list sensors''' if setup is True: context.obj.setup_one_wire() if list is True: diff --git a/cbpi/config/config.yaml b/cbpi/config/config.yaml index 2f05625..b15c777 100644 --- a/cbpi/config/config.yaml +++ b/cbpi/config/config.yaml @@ -5,7 +5,7 @@ version: 4.0.8 index_url: /cbpi_ui/static/index.html port: 8000 - +debug-log-level: 30 mqtt: false mqtt_host: localhost mqtt_port: 1883 From 35e83cdae10fac24e8e40dc19263e741c00c63bd Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 15 Nov 2023 20:26:05 +0100 Subject: [PATCH 24/27] some options are not available under windows -> added check in cli --- cbpi/__init__.py | 2 +- cbpi/cli.py | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 21977a3..50a86c3 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a9" +__version__ = "4.2.0.rc1" __codename__ = "Indian Summer" diff --git a/cbpi/cli.py b/cbpi/cli.py index 1221547..b8275ff 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -1,4 +1,5 @@ import logging +import sys from pathlib import Path import requests from cbpi import __version__, __codename__ @@ -267,7 +268,8 @@ def main(context, config_folder_path, logs_folder_path, debug_log_level): if logs_folder_path == "": logs_folder_path = os.path.join(Path(config_folder_path).absolute().parent, 'logs') formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s') - static_config = load_config(ConfigFolder(config_folder_path, logs_folder_path).get_file_path("config.yaml")) + config=ConfigFolder(config_folder_path, logs_folder_path) + static_config = load_config(config.get_file_path("config.yaml")) try: if debug_log_level == 99: debug_log_level=static_config['debug-log-level'] @@ -277,7 +279,7 @@ def main(context, config_folder_path, logs_folder_path, debug_log_level): logging.basicConfig(format=formatter, stream=logging.StreamHandler()) logger = logging.getLogger() print("*******************************") - print("Set Debug-log-level to {}".format(debug_log_level)) + print("Debug-log-level is {}".format(debug_log_level)) print("*******************************") logger.setLevel(debug_log_level) try: @@ -289,7 +291,7 @@ def main(context, config_folder_path, logs_folder_path, debug_log_level): except Exception as e: logger.warning("log folder or log file could not be created or accessed. check folder and file permissions or create the logs folder somewhere you have access with a start option like '--log-folder-path=./logs'") logging.critical(e, exc_info=True) - cbpi_cli = CraftBeerPiCli(ConfigFolder(config_folder_path, logs_folder_path)) + cbpi_cli = CraftBeerPiCli(config) context.obj = cbpi_cli @main.command() @@ -304,10 +306,14 @@ def setup(context): @click.option('--setup', is_flag=True, help="Setup 1Wire on Raspberry Pi") def onewire(context, list, setup): '''(--setup | --list) Setup 1wire on Raspberry Pi or list sensors''' - if setup is True: - context.obj.setup_one_wire() - if list is True: - context.obj.list_one_wire() + operationsystem= sys.platform + if not operationsystem.startswith('win'): + if setup is True: + context.obj.setup_one_wire() + if list is True: + context.obj.list_one_wire() + else: + print("Onewire options NOT available under Windows") @main.command() @click.pass_context @@ -337,7 +343,11 @@ def create(context, pluginname=[]): @click.argument('name') def autostart(context, name): '''(on|off|status) Enable or disable autostart''' - context.obj.autostart(name) + operationsystem= sys.platform + if not operationsystem.startswith('win'): + context.obj.autostart(name) + else: + print("Autostart option NOT available under Windows") @main.command() @@ -345,4 +355,8 @@ def autostart(context, name): @click.argument('name') def chromium(context, name): '''(on|off|status) Enable or disable Kiosk mode''' - context.obj.chromium(name) + operationsystem= sys.platform + if not operationsystem.startswith('win'): + context.obj.chromium(name) + else: + print("Chromium option NOT available under Windows") From bb5efce0aebe6b210602a4fad32ac263e3511081 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 16 Nov 2023 07:13:01 +0100 Subject: [PATCH 25/27] update requirements (dependabot alarms and more) --- cbpi/__init__.py | 2 +- requirements.txt | 12 ++++++------ setup.py | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 50a86c3..c9b2907 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.rc1" +__version__ = "4.2.0.rc2" __codename__ = "Indian Summer" diff --git a/requirements.txt b/requirements.txt index 2c426f7..93dd3b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ typing-extensions>=4 -aiohttp==3.8.5 +aiohttp==3.8.6 aiohttp-auth==0.1.1 aiohttp-route-decorator==0.1.4 aiohttp-security==0.4.0 @@ -7,8 +7,8 @@ aiohttp-session==2.12.0 aiohttp-swagger==1.0.16 aiojobs==1.1.0 aiosqlite==0.17.0 -cryptography==41.0.4 -pyopenssl==23.2.0 +cryptography==41.0.5 +pyopenssl==23.3.0 requests==2.31.0 voluptuous==0.13.1 pyfiglet==1.0.2 @@ -17,12 +17,12 @@ shortuuid==1.0.11 tabulate==0.9.0 numpy==1.24.1 cbpi4gui -click==8.1.3 +click==8.1.7 importlib_metadata==4.11.1 -aiomqtt==1.0.0 +aiomqtt==1.2.1 psutil==5.9.6 zipp>=0.5 colorama==0.4.6 pytest-aiohttp coverage==6.3.1 -inquirer==3.1.1 +inquirer==3.1.3 diff --git a/setup.py b/setup.py index a8735ec..06eafca 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setup(name='cbpi4', long_description_content_type='text/markdown', install_requires=[ "typing-extensions>=4", - "aiohttp==3.8.5", + "aiohttp==3.8.6", "aiohttp-auth==0.1.1", "aiohttp-route-decorator==0.1.4", "aiohttp-security==0.4.0", @@ -47,16 +47,16 @@ setup(name='cbpi4', "aiohttp-swagger==1.0.16", "aiojobs==1.1.0 ", "aiosqlite==0.17.0", - "cryptography==41.0.4", - "pyopenssl==23.2.0", + "cryptography==41.0.5", + "pyopenssl==23.3.0", "requests==2.31.0", "voluptuous==0.13.1", "pyfiglet==1.0.2", - 'click==8.1.3', + 'click==8.1.7', 'shortuuid==1.0.11', 'tabulate==0.9.0', - 'aiomqtt==1.0.0', - 'inquirer==3.1.1', + 'aiomqtt==1.2.1', + 'inquirer==3.1.3', 'colorama==0.4.6', 'psutil==5.9.6', 'cbpi4gui', From dbffd8dd17f58439f35a067621503345ff0a4a66 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 19 Nov 2023 08:47:16 +0100 Subject: [PATCH 26/27] add parameter for dashboard grid width --- cbpi/__init__.py | 2 +- cbpi/controller/dashboard_controller.py | 10 +++++++- cbpi/extension/ConfigUpdate/__init__.py | 13 ++++++++++ cbpi/http_endpoints/http_dashboard.py | 34 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index c9b2907..ae9ec3a 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.rc2" +__version__ = "4.2.0.rc3" __codename__ = "Indian Summer" diff --git a/cbpi/controller/dashboard_controller.py b/cbpi/controller/dashboard_controller.py index 2bb77b3..bb7fe44 100644 --- a/cbpi/controller/dashboard_controller.py +++ b/cbpi/controller/dashboard_controller.py @@ -60,11 +60,19 @@ class DashboardController: async def get_current_dashboard(self): current_dashboard_number = self.cbpi.config.get("current_dashboard_number", 1) return current_dashboard_number - + async def set_current_dashboard(self, dashboard_id=1): await self.cbpi.config.set("current_dashboard_number", dashboard_id) return {"status": "OK"} + async def get_current_grid(self): + current_grid = self.cbpi.config.get("current_grid", 5) + return current_grid + + async def set_current_grid(self, grid_width=5): + await self.cbpi.config.set("current_grid", grid_width) + return {"status": "OK"} + async def get_slow_pipe_animation(self): slow_pipe_animation = self.cbpi.config.get("slow_pipe_animation", "Yes") return slow_pipe_animation \ No newline at end of file diff --git a/cbpi/extension/ConfigUpdate/__init__.py b/cbpi/extension/ConfigUpdate/__init__.py index 39f3213..cecb22f 100644 --- a/cbpi/extension/ConfigUpdate/__init__.py +++ b/cbpi/extension/ConfigUpdate/__init__.py @@ -64,6 +64,7 @@ class ConfigUpdate(CBPiExtension): BoilKettle = self.cbpi.config.get("BoilKettle", None) CONFIG_STATUS = self.cbpi.config.get("CONFIG_STATUS", None) self.version=__version__ + current_grid = self.cbpi.config.get("current_grid", None) if boil_temp is None: @@ -491,6 +492,16 @@ class ConfigUpdate(CBPiExtension): source="steps", options=[{"label": "Yes", "value": "Yes"}, {"label": "No", "value": "No"}]) + + if current_grid is None: + logger.info("INIT Current Dashboard Number") + try: + await self.cbpi.config.add("current_grid", 5, type=ConfigType.NUMBER, description="Dashboard Grid Width",source="hidden") + except: + logger.warning('Unable to update database') + else: + if CONFIG_STATUS is None or CONFIG_STATUS != self.version: + await self.cbpi.config.add("current_grid", current_grid, type=ConfigType.NUMBER, description="Dashboard Grid Width",source="hidden") @@ -503,6 +514,8 @@ class ConfigUpdate(CBPiExtension): logger.warning('Unable to update config') + + def setup(cbpi): cbpi.plugin.register("ConfigUpdate", ConfigUpdate) pass diff --git a/cbpi/http_endpoints/http_dashboard.py b/cbpi/http_endpoints/http_dashboard.py index 38073cf..d6142d8 100644 --- a/cbpi/http_endpoints/http_dashboard.py +++ b/cbpi/http_endpoints/http_dashboard.py @@ -156,6 +156,40 @@ class DashBoardHttpEndpoints: """ dashboard_id = int(request.match_info['id']) return web.json_response(await self.cbpi.dashboard.set_current_dashboard(dashboard_id)) + + @request_mapping(path="/currentgrid", method="GET", auth_required=False) + async def get_current_grid(self, request): + """ + --- + description: Get Dashboard Numbers + tags: + - Dashboard + responses: + "200": + description: successful operation + """ + return web.json_response(await self.cbpi.dashboard.get_current_grid(), dumps=json_dumps) + + @request_mapping(path="/{width}/currentgrid", method="POST", auth_required=False) + async def set_current_grid(self, request): + """ + --- + description: Set Current Grid Width + tags: + - Dashboard + parameters: + - name: "width" + in: "path" + description: "Grid Width" + required: true + type: "integer" + format: "int64" + responses: + "200": + description: successful operation + """ + grid_width = int(request.match_info['width']) + return web.json_response(await self.cbpi.dashboard.set_current_grid(grid_width)) @request_mapping(path="/slowPipeAnimation", method="GET", auth_required=False) async def get_slow_pipe_animation(self, request): From a934de16fd47c941425f25086aaa5ff896a937e2 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:02:12 +0100 Subject: [PATCH 27/27] release --- cbpi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index ae9ec3a..130d75c 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.rc3" +__version__ = "4.2.0" __codename__ = "Indian Summer"