From fd4acc09f4a92f7b0ae1df04b80e87b590677e64 Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 2 Oct 2021 17:44:49 +0200 Subject: [PATCH 01/22] Auto stash before rebase of "origin/development" --- Hector9000/HectorServer.py | 4 ++-- Hector9000/conf/database.py | 12 ++++++------ Hector9000/tools/SetValveIng.py | 9 +++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Hector9000/HectorServer.py b/Hector9000/HectorServer.py index b2ee06c..970ecbc 100644 --- a/Hector9000/HectorServer.py +++ b/Hector9000/HectorServer.py @@ -11,8 +11,8 @@ import paho.mqtt.client as mqtt from Hector9000.conf import HectorConfig as HC -from Hector9000.HectorHardware import HectorHardware as Hector -# from Hector9000.HectorSimulator import HectorSimulator as Hector +#from Hector9000.HectorHardware import HectorHardware as Hector +from Hector9000.HectorSimulator import HectorSimulator as Hector # global vars diff --git a/Hector9000/conf/database.py b/Hector9000/conf/database.py index 6daadde..152188e 100644 --- a/Hector9000/conf/database.py +++ b/Hector9000/conf/database.py @@ -146,30 +146,30 @@ def _import_settings(self): """INSERT INTO "Settings" ("setting", "value") VALUES ('cupsize', '400');""") self.con.commit() - def _check_Table_is_Filled(self, table): + def _check_Table_is_Filled(self, table: str): self.cur.execute("SELECT * FROM " + table) items = self.cur.fetchall() return len(items) > 0 - def get_Setting(self, setting): + def get_Setting(self, setting: str): self.cur.execute( "SELECT value from Settings where setting = ? ;", (setting,)) items = self.cur.fetchone() return items[0] - def set_Setting(self, setting, value): + def set_Setting(self, setting: str, value: str): self.cur.execute( "UPDATE Settings set value = ? where setting = ? ;", (value, setting)) self.con.commit() return self.get_Setting(setting) - def get_Servo(self, servo): + def get_Servo(self, servo: int): self.cur.execute( "SELECT Code FROM Servos WHERE ServoNr = ? ;", (servo,)) items = self.cur.fetchone() return items[0] - def set_Servo(self, servo, code): + def set_Servo(self, servo: int, code: str): self.cur.execute( "UPDATE Servos set Code = ? where ServoNr = ? ;", (code, servo)) self.con.commit() @@ -222,7 +222,7 @@ def get_AllIngredients_asJson(self): return json.dumps({"Ingredients": datalist}) - def countUpDrink(self, drink): + def countUpDrink(self, drink: str): self.cur.execute( "INSERT INTO DrinksLog (drink, date) VALUES (?, ?)", (drink, diff --git a/Hector9000/tools/SetValveIng.py b/Hector9000/tools/SetValveIng.py index 8a70526..ed9ceff 100644 --- a/Hector9000/tools/SetValveIng.py +++ b/Hector9000/tools/SetValveIng.py @@ -54,6 +54,15 @@ def get_Valves(): if 0 < valve <= 12: print(ing[1] + " goes into " + str(valve)) db.set_Servo(valve, ing[0]) + if valve == 13: + print("------------------") + print(db.get_AllIngredients_asJson()) + print("------------------") + if valve == 14: + print("------------------") + print(db.get_Servos_asJson()) + print("------------------") + except ValueError: print("Oops! That was no valid number. Try again...") From ad5885f3853628d06f363c683aaafe43cc92e44a Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 2 Oct 2021 22:45:02 +0200 Subject: [PATCH 02/22] Revert "Merge branch 'master' into development" This reverts commit a339db9d3a944e1cf5585a6904c18e7c35b4f902. --- .github/ISSUE_TEMPLATE/custom.md | 8 ++++ .github/workflows/python-app.yml | 33 -------------- .gitignore | 2 + .travis.yml | 6 ++- Hector9000/HectorController.py | 18 ++++++-- Hector9000/HectorHardware.py | 22 ---------- Hector9000/HectorRemote.py | 6 +++ Hector9000/HectorServer.py | 6 ++- Hector9000/LEDStripServer.py | 6 +-- Hector9000/conf/database.py | 24 ++++++++-- Hector9000/conf/hx711.py | 1 + Hector9000/utils/HectorAPI.py | 2 +- Hector9000/utils/LEDStripConnector.py | 24 +++++----- Makefile | 38 ++++++++++++++++ README.md | 12 ++++- pyproject.toml | 6 +++ requirements.txt | 6 +-- setup.py | 63 ++++++++++++++------------- setup.sh | 3 +- 19 files changed, 170 insertions(+), 116 deletions(-) delete mode 100644 .github/workflows/python-app.yml create mode 100644 Makefile create mode 100644 pyproject.toml diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md index 3141775..dd366cf 100644 --- a/.github/ISSUE_TEMPLATE/custom.md +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -1,8 +1,12 @@ --- name: Custom issue template + about: Describe this issue template's purpose here. + title: '' + labels: '' + assignees: '' --- @@ -12,8 +16,12 @@ Your description: -------------- Pi version: + Pi OS: + Hector version: + Python version: + -------------- Error message: diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 8d704f6..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,33 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Python application - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - name: Install mosquito - run: sudo apt-get -y install mosquitto - - name: Install dependencies - run: | - python setup.py develop - pip install pytest flake8 autopep8 - - name: Lint with flake8 - run: | - python -m pytest - diff --git a/.gitignore b/.gitignore index 193a78b..96aaca2 100755 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ .idea/dictionaries venv/ .vscode/ +build/ +Hector9000.egg-info/ # Sensitive or high-churn files: .idea/**/dataSources/ diff --git a/.travis.yml b/.travis.yml index 558c605..c4a5d67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ python: - "3.6" - "3.7" - "3.8" + - "3.9" before_install: - sudo apt-get -y install mosquitto @@ -12,9 +13,10 @@ addons: # command to install dependencies install: - - python setup.py develop + - pip install -e .[dev] # command to run tests script: # - cd $TRAVIS_BUILD_DIR/src - - python -m pytest + - make test + - make lint diff --git a/Hector9000/HectorController.py b/Hector9000/HectorController.py index f87c6d7..853adff 100644 --- a/Hector9000/HectorController.py +++ b/Hector9000/HectorController.py @@ -73,10 +73,14 @@ def _get_ingredients(self, msg): return self.db.get_AllIngredients_asJson() def _get_servo(self, msg): - debug("get_Ingredient") + debug("_get_servo: " + msg) id = int(msg.payload) return self.db.get_Servo(id) + def _get_all_servos(self, msg): + debug("get_all_servos") + return self.db.get_Servos_asJson() + def _set_servo(self, msg): debug("set_Servo") ing = json.loads(msg.payload) @@ -117,6 +121,12 @@ def _do_get_servo(self, msg): msg.topic), self._get_servo(msg)) + def _do_get_all_servos(self, msg): + self.client.publish( + self.get_returnTopic( + msg.topic), + self._get_all_servos(msg)) + def _do_set_servo(self, msg): self.client.publish( self.get_returnTopic( @@ -205,6 +215,8 @@ def on_message(self, client, userdata, msg): self._do_get_ingredients(msg) elif currentTopic == self.TopicPrefix + "get_servo": self._do_get_servo(msg) + elif currentTopic == self.TopicPrefix + "get_allservos": + self._do_get_all_servos(msg) elif currentTopic == self.TopicPrefix + "set_servo": self._do_set_servo(msg) elif currentTopic == self.TopicPrefix + "light_on": @@ -219,11 +231,11 @@ def on_message(self, client, userdata, msg): elif currentTopic == self.TopicPrefix + "cleanMe": # ToDo: Develop proper methode in Server for i in range(12): - self.hector.clean(1) + self.hector.clean(i) pass elif currentTopic == self.TopicPrefix + "dryMe": for i in range(12): - self.hector.dry(1) + self.hector.dry(i) pass elif currentTopic == self.TopicPrefix + "openAllValves": self.hector.all_valve_open() diff --git a/Hector9000/HectorHardware.py b/Hector9000/HectorHardware.py index 5dd3dac..49af350 100644 --- a/Hector9000/HectorHardware.py +++ b/Hector9000/HectorHardware.py @@ -288,25 +288,3 @@ def set_servo_pulse(self, channel, pulse): # end class HectorHardware - - -# main (for testing only) -if __name__ == "__main__": - hector = HectorHardware(config) - hector.finger(0) - hector.arm_in() - for i in range(hector.numValves): - log("close valve %d = channel %d" % (i, hector.valveChannels[i])) - hector.valve_close(hector.valveChannels[i]) - input("Bitte Glas auf die Markierung stellen") - # hector.ping(1) - hector.arm_out() - hector.valve_dose(1, 100) - hector.valve_dose(3, 20) - hector.finger(1) - hector.valve_dose(11, 100) - hector.arm_in() - hector.ping(3) - hector.finger(0) - hector.cleanAndExit() - log("done.") diff --git a/Hector9000/HectorRemote.py b/Hector9000/HectorRemote.py index f734c53..f3863cd 100644 --- a/Hector9000/HectorRemote.py +++ b/Hector9000/HectorRemote.py @@ -135,6 +135,12 @@ def ping(self, num, retract=True, cback=None): def cleanAndExit(self): self.pub_with_subtopic("clean_and_exit") + def clean(self, valve): + self.pub_with_subtopic("cleanMe", valve) + + def dry(self, valve): + self.pub_with_subtopic("dryMe", valve) + def ledstripmessage(self, topic, color, type): message = str(color[0]) + "," + str(color[1]) + \ "," + str(color[2]) + "," + str(type) diff --git a/Hector9000/HectorServer.py b/Hector9000/HectorServer.py index 0d5c800..b2ee06c 100644 --- a/Hector9000/HectorServer.py +++ b/Hector9000/HectorServer.py @@ -12,7 +12,7 @@ from Hector9000.conf import HectorConfig as HC from Hector9000.HectorHardware import HectorHardware as Hector -#from Hector9000.HectorSimulator import HectorSimulator as Hector +# from Hector9000.HectorSimulator import HectorSimulator as Hector # global vars @@ -243,6 +243,10 @@ def on_message(client, userdata, msg): pass client.loop_write() log("Return Send - Dosing Complete") + elif topic == "cleanMe": + clean(int(msg.payload.decode("utf-8"))) + elif topic == "dryMe": + dry(int(msg.payload.decode("utf-8"))) else: warning("Unknown topic") diff --git a/Hector9000/LEDStripServer.py b/Hector9000/LEDStripServer.py index 442d844..f799a30 100644 --- a/Hector9000/LEDStripServer.py +++ b/Hector9000/LEDStripServer.py @@ -24,7 +24,7 @@ def on_message(client, userdata, msg): if topic == "standart": print("standart") args = tuple(msg.payload.decode("utf-8").split(",")) - if msg.payload.decode("utf-8") is "": + if msg.payload.decode("utf-8") == "": pixels.standart() elif len(args) == 1: pixels.standart(type=args[0]) @@ -36,7 +36,7 @@ def on_message(client, userdata, msg): elif topic == "standby": print("standby") args = tuple(msg.payload.decode("utf-8").split(",")) - if msg.payload.decode("utf-8") is "": + if msg.payload.decode("utf-8") == "": pixels.standby() elif len(args) == 1: pixels.standby(type=args[0]) @@ -48,7 +48,7 @@ def on_message(client, userdata, msg): elif topic == "dosedrink": print("dosedrink") args = list(msg.payload.decode("utf-8").split(",")) - if msg.payload.decode("utf-8") is "": + if msg.payload.decode("utf-8") == "": print("no args") pixels.dosedrink() elif len(args) == 1: diff --git a/Hector9000/conf/database.py b/Hector9000/conf/database.py index a556272..6daadde 100644 --- a/Hector9000/conf/database.py +++ b/Hector9000/conf/database.py @@ -44,7 +44,7 @@ def createIfNotExists(self): PRIMARY KEY(`code`));""") self.cur.execute(""" - CREATE TABLE if not exists Settings ('setting' TEXT UNIQUE, 'value' TEXT, PRIMARY KEY('setting'));""") + CREATE TABLE if not exists Settings ('setting' TEXT UNIQUE, 'value' TEXT, PRIMARY KEY('setting'));""") self.con.commit() @@ -188,7 +188,16 @@ def get_Servos_asList(self): return array def get_Servos_asJson(self): - return json.dumps(self.get_Servos()) + datalist = [] + for servo in self.get_Servos(): + data = { + "servo": servo[0], + "ingri": servo[1], + "volume": servo[2], + } + datalist.append(data) + + return json.dumps({"Servos": datalist}) def get_AllIngredients(self): self.cur.execute("SELECT Code, Name, IsAlcoholic FROM Ingredients") @@ -202,7 +211,16 @@ def get_AllIngredientsAsDict(self): return Ingdict def get_AllIngredients_asJson(self): - return json.dumps(self.get_AllIngredients()) + datalist = [] + for ingredient in self.get_AllIngredients(): + data = { + "code": ingredient[0], + "name": ingredient[1], + "isAlcoholic": ingredient[2], + } + datalist.append(data) + + return json.dumps({"Ingredients": datalist}) def countUpDrink(self, drink): self.cur.execute( diff --git a/Hector9000/conf/hx711.py b/Hector9000/conf/hx711.py index 943730a..bf2b4da 100644 --- a/Hector9000/conf/hx711.py +++ b/Hector9000/conf/hx711.py @@ -1,3 +1,4 @@ +# flake8: noqa import RPi.GPIO as GPIO import time import numpy # sudo apt-get python-numpy diff --git a/Hector9000/utils/HectorAPI.py b/Hector9000/utils/HectorAPI.py index 294dfb9..2163c94 100644 --- a/Hector9000/utils/HectorAPI.py +++ b/Hector9000/utils/HectorAPI.py @@ -36,7 +36,7 @@ def arm_in(self, cback=debugOut): @abc.abstractmethod def arm_isInOutPos(self): - return false + return False @abc.abstractmethod def scale_readout(self): diff --git a/Hector9000/utils/LEDStripConnector.py b/Hector9000/utils/LEDStripConnector.py index a578e90..a6a7201 100644 --- a/Hector9000/utils/LEDStripConnector.py +++ b/Hector9000/utils/LEDStripConnector.py @@ -30,23 +30,23 @@ def __init__(self): self.drinkcolor = (0, 0, 0) def standart(self, color=(80, 80, 30), type=0): - if type is 0: + if type == 0: self.pixels.fill(color) self.mode = 0 - elif type is 1: + elif type == 1: self.mode = 1 - elif type is 2: + elif type == 2: self.mode = 2 - elif type is 3: + elif type == 3: self.mode = 3 - elif type is 4: + elif type == 4: self.mode = 4 else: self.pixels.fill(color) self.mode = 0 def standby(self, color=(80, 80, 30), type=0): - if type is 0: + if type == 0: self.pixels.fill(color) else: self.pixels.fill((0, 0, 0)) @@ -103,15 +103,15 @@ def drinkloop(self): # mode 2: Strobo # mode 3: def led_loop(self): - if self.mode is 1: + if self.mode == 1: self.mode1() - elif self.mode is 2: + elif self.mode == 2: self.mode2() - elif self.mode is 3: + elif self.mode == 3: self.mode3() - elif self.mode is 4: + elif self.mode == 4: self.mode4() - elif self.mode is 99: + elif self.mode == 99: # dosedrink self.drinkloop() @@ -184,7 +184,7 @@ def mode4(self): self.rainbow_cycle(0.001) # rainbow cycle with 1ms delay per step -if __name__ is "__main__": +if __name__ == "__main__": test = LEDStripConnector() test.finish() test.dosedrink() diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9d21285 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +VIRTUALENV := python3 -m venv + +## help - Display help about make targets for this Makefile +help: + @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t + +## venv - Install the virtual environment +venv: + $(VIRTUALENV) ~/.venv/python_project/ + ln -snf ~/.venv/python_project/ venv + venv/bin/pip install -e ."[dev]" + +# activate - Activate venv +activate: + source venv/bin/activate + +## install - Install the project locally +install: | venv + +## clean - Remove the virtual environment and clear out .pyc files +clean: + rm -rf ~/.venv/python_project/ venv + find . -name '*.pyc' -delete + rm -rf dist + rm -rf build + rm -rf *.egg-info + +## lint - Lint the project +lint: + flake8 Hector9000/*.py --count --select=E1,E2,E9,F63,F7,F82 --show-source --statistics + #venv/bin/flake8 tests/*.py --count --select=E1,E2,E9,F63,F7,F82 --show-source --statistics + +## test - Test the project +test: + python -m pytest + + +.PHONY: help install clean lint test activate \ No newline at end of file diff --git a/README.md b/README.md index 844532f..c8a728b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,14 @@ Minimal Requirements - RaspberryPi 3 - Debian bases Linux (to use installscript) +Prepare Raspberry +--- +Activate I2C: + + sudo raspi-config + +Here go to "Interfacing Options" and Activate/Enable I2C + Install on RaspberryPi ---- First you have to clone the github repo of Hector @@ -33,7 +41,7 @@ Then run this command to setup all necessary tools: ./setup.sh -Or run it with the option "-c" to preset the mqtt preconfig for the WebUI +Or run it with the option "-c" to preset the mqtt preconfigure for the WebUI ./setup.sh -c @@ -66,7 +74,7 @@ A future extension might allow multi-language UIs. Assigning valves --- -The available ingreduents are also moved to the db and can initial be edited in the databas.py +The available ingredients are also moved to the db and can initial be edited in the databas.py or over the WEB UI in the future. For teh meantime you can use the script "SetValveIng.py". diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b5a3c46 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 113011f..2703a80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,16 +11,16 @@ docutils==0.14 idna==2.8 more-itertools==7.0.0 packaging==19.0 -paho-mqtt==1.5.0 +paho-mqtt==1.5.1 pluggy==0.12.0 py==1.10.0 Pygments==2.7.4 pyparsing==2.4.0 pytest==5.4.1 -requests==2.26.0 +requests==2.21.0 six==1.12.0 spidev==3.2 -urllib3==1.25.9 +urllib3==1.24.2 wcwidth==0.1.7 webcolors==1.3 RPi.GPIO==0.7.0 diff --git a/setup.py b/setup.py index 8a306cb..081b83f 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="Hector9000", - version="0.0.1", + version="0.1.0", author="DevTown", author_email="Hector@dev-town.de", description="Fancy barbot with lots of needless features and ...of course... WiFi and a bunch of blinky LEDs", @@ -20,34 +20,37 @@ ], python_requires='>=3.6', install_requires=[ - 'Adafruit-GPIO==1.0.3', - 'Adafruit-PCA9685==1.0.1', - 'Adafruit-PureIO>=1.1.5', - 'atomicwrites==1.3.0', - 'adafruit-circuitpython-neopixel==6.0.0', - 'attrs==19.1.0', - 'board==0.0.0.post0', - 'certifi==2018.11.29', - 'chardet==3.0.4', - 'docutils==0.14', - 'idna==2.8', - 'more-itertools==7.0.0', - 'packaging==19.0', - 'paho-mqtt==1.5.0', - 'pluggy==0.12.0', - 'py==1.10.0', - 'Pygments==2.7.4', - 'pyparsing==2.4.0', - 'requests==2.26.0', - 'six==1.12.0', - 'spidev==3.2', - 'urllib3==1.25.9', - 'wcwidth==0.1.7', - 'webcolors==1.3', - 'RPi.GPIO==0.7.0', - 'zipp==3.1.0', + 'Adafruit-GPIO==1.0.3', + 'Adafruit-PCA9685==1.0.1', + 'Adafruit-PureIO>=1.1.5', + 'atomicwrites==1.3.0', + 'adafruit-circuitpython-neopixel==6.0.0', + 'attrs==19.1.0', + 'board==0.0.0.post0', + 'certifi==2018.11.29', + 'chardet==3.0.4', + 'docutils==0.14', + 'idna==2.8', + 'more-itertools==7.0.0', + 'packaging==19.0', + 'paho-mqtt==1.5.1', + 'pluggy==0.12.0', + 'py==1.10.0', + 'Pygments==2.7.4', + 'pyparsing==2.4.0', + 'requests==2.21.0', + 'six==1.12.0', + 'spidev==3.2', + 'urllib3==1.24.2', + 'wcwidth==0.1.7', + 'webcolors==1.3', + 'RPi.GPIO==0.7.0', + 'zipp==3.1.0', ], - tests_require=['pytest', 'flake8', 'autopep8'], - entry_points={"console_scripts": ["HectorServer = Hector.HectorServer:main", - "HectorController = Hector.HectorController:main"]}, + extras_require={ + 'dev': ['pytest', 'flake8', 'autopep8']} + , + entry_points={"console_scripts": ["HectorServer = Hector9000.HectorServer:main", + "HectorController = Hector9000.HectorController:main", + "LEDStripServer = Hector9000.LEDStripServer:main"]}, ) diff --git a/setup.sh b/setup.sh index 15967d9..440690f 100644 --- a/setup.sh +++ b/setup.sh @@ -74,8 +74,9 @@ then echo 'listener 9001' >> /etc/mosquitto/mosquitto.conf echo 'protocol websockets' >> /etc/mosquitto/mosquitto.conf echo 'socket_domain ipv4' >> /etc/mosquitto/mosquitto.conf -fi + systemctl start mosquitto +fi echo "install Hector9000" python3 setup.py install From a836006062a8f4cf75a90288237c1ea26cd73449 Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 2 Oct 2021 22:48:46 +0200 Subject: [PATCH 03/22] Auto stash before revert of "Merge branch 'master' into development" --- .github/workflows/python-app.yml | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..8d704f6 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,33 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install mosquito + run: sudo apt-get -y install mosquitto + - name: Install dependencies + run: | + python setup.py develop + pip install pytest flake8 autopep8 + - name: Lint with flake8 + run: | + python -m pytest + From bf929233173d66e7920ef7a1e618f8b0fb3d5b47 Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 3 Oct 2021 20:55:08 +0200 Subject: [PATCH 04/22] Add develop to Action --- .github/workflows/python-app.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 9333f1d..64b49dc 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,13 @@ name: Python application on: push: - branches: [ master ] + branches: + - master + - development pull_request: - branches: [ master ] + branches: + - master + - development jobs: build: From 6d610ad8712d4325e5ebf02e1ccd327b571a0b0e Mon Sep 17 00:00:00 2001 From: DevTown Date: Wed, 6 Oct 2021 09:25:33 +0200 Subject: [PATCH 05/22] Add new var types --- Hector9000/HectorServer.py | 2 +- Hector9000/utils/HectorAPI.py | 20 ++++++++++---------- Hector9000/utils/LEDStripAPI.py | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Hector9000/HectorServer.py b/Hector9000/HectorServer.py index 970ecbc..3014a02 100644 --- a/Hector9000/HectorServer.py +++ b/Hector9000/HectorServer.py @@ -11,7 +11,7 @@ import paho.mqtt.client as mqtt from Hector9000.conf import HectorConfig as HC -#from Hector9000.HectorHardware import HectorHardware as Hector +# from Hector9000.HectorHardware import HectorHardware as Hector from Hector9000.HectorSimulator import HectorSimulator as Hector diff --git a/Hector9000/utils/HectorAPI.py b/Hector9000/utils/HectorAPI.py index 2163c94..8a4801d 100644 --- a/Hector9000/utils/HectorAPI.py +++ b/Hector9000/utils/HectorAPI.py @@ -27,11 +27,11 @@ def light_off(self): pass @abc.abstractmethod - def arm_out(self, cback=debugOut): + def arm_out(self, cback = debugOut): pass @abc.abstractmethod - def arm_in(self, cback=debugOut): + def arm_in(self, cback = debugOut): pass @abc.abstractmethod @@ -55,32 +55,32 @@ def pump_stop(self): pass @abc.abstractmethod - def valve_open(self, index, open=1): + def valve_open(self, index: int, open: int = 1): pass @abc.abstractmethod - def valve_close(self, index): + def valve_close(self, index: int): pass @abc.abstractmethod def valve_dose( self, - index, + index: int, amount, - timeout=30, - cback=debugOut, + timeout: int = 30, + cback = debugOut, progress=( 0, 100), - topic=""): + topic: str = ""): return 0 @abc.abstractmethod - def finger(self, pos=0): + def finger(self, pos: int = 0): pass @abc.abstractmethod - def ping(self, num, retract=True, cback=None): + def ping(self, num: int, retract: bool = True, cback = None): pass @abc.abstractmethod diff --git a/Hector9000/utils/LEDStripAPI.py b/Hector9000/utils/LEDStripAPI.py index 2f50d12..7b63371 100644 --- a/Hector9000/utils/LEDStripAPI.py +++ b/Hector9000/utils/LEDStripAPI.py @@ -7,7 +7,7 @@ import abc -def debugOut(name, value): +def debugOut(name: str, value: str): print("=> %s: %d" % (name, value)) @@ -18,17 +18,17 @@ def __init__(self): pass @abc.abstractmethod - def standart(self, color=(80, 80, 30), type=0): + def standart(self, color=(80, 80, 30), type = 0): pass @abc.abstractmethod - def dosedrink(self, color=(20, 20, 255), type=0): + def dosedrink(self, color=(20, 20, 255), type = 0): pass @abc.abstractmethod - def drinkfinish(self, color=(80, 80, 30), type=0): + def drinkfinish(self, color=(80, 80, 30), type = 0): pass @abc.abstractmethod - def standby(self, color=(80, 80, 30), type=0): + def standby(self, color=(80, 80, 30), type = 0): pass From 516c9e256fe04414dc7d4bdb2785fb04071f8b98 Mon Sep 17 00:00:00 2001 From: DevTown Date: Wed, 6 Oct 2021 09:25:41 +0200 Subject: [PATCH 06/22] Fix MakeFile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9d21285..0e5b9c5 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ venv: ln -snf ~/.venv/python_project/ venv venv/bin/pip install -e ."[dev]" -# activate - Activate venv +## activate - Activate venv activate: source venv/bin/activate From 2af483f67a3e7ff4c8b9fb4a849158e88f066ad0 Mon Sep 17 00:00:00 2001 From: DevTown Date: Tue, 16 Nov 2021 20:44:40 +0100 Subject: [PATCH 07/22] Add new Databsefunctions --- Hector9000/conf/database.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Hector9000/conf/database.py b/Hector9000/conf/database.py index 152188e..1b26426 100644 --- a/Hector9000/conf/database.py +++ b/Hector9000/conf/database.py @@ -191,7 +191,7 @@ def get_Servos_asJson(self): datalist = [] for servo in self.get_Servos(): data = { - "servo": servo[0], + "servo": servo[0], "ingri": servo[1], "volume": servo[2], } @@ -222,6 +222,17 @@ def get_AllIngredients_asJson(self): return json.dumps({"Ingredients": datalist}) + def add_Ingredient(self, short: str, long: str, isAlcohol: int): + self.cur.execute( + "INSERT INTO Ingredients(Code, Name, IsAlcoholic) VALUES (?,?,?)", + (short, long, isAlcohol)) + self.con.commit() + + def delete_Ingredient(self, code: str): + self.cur.execute("DELETE FROM Ingredients WHERE Code = ?", + code) + self.con.commit() + def countUpDrink(self, drink: str): self.cur.execute( "INSERT INTO DrinksLog (drink, date) VALUES (?, ?)", @@ -264,4 +275,4 @@ def get_Drinks_Log(self): (strftime( "%a %Y-%m-%d %H:%M:%S", localtime(tstamp)), - name)) + name)) From 2ea7bbfe8b0b188ed10efaa17d8f49a022b05152 Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 4 Dec 2021 22:20:12 +0100 Subject: [PATCH 08/22] Add tool to add ing to DB --- Hector9000/tools/Editingredients.py | 71 +++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Hector9000/tools/Editingredients.py diff --git a/Hector9000/tools/Editingredients.py b/Hector9000/tools/Editingredients.py new file mode 100644 index 0000000..8d44a66 --- /dev/null +++ b/Hector9000/tools/Editingredients.py @@ -0,0 +1,71 @@ +from Hector9000.conf.database import Database as hdb + +db = hdb() + + +def print_IngList(): + print("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") + inglist = db.get_AllIngredients() + counter = 0 + print("Ing List:") + + for x in inglist: + print(str(counter) + ": " + x[0] + " | " + x[1]) + counter = counter + 1 + pass + + +def add_Ing(): + shortname: str = str(input("Enter shortform:")) + longname: str = str(input("Enter longname:")) + isAlcoholic: int = int(input("Is Alcholic(1=yes 0=false):")) + + if isAlcoholic > 1: + isAlcoholic = 1 + if isAlcoholic < 0: + isAlcoholic = 0 + + db.add_Ingredient(shortname, longname, isAlcoholic) + + print_IngList() + pass + + +def dell_Ing(): + print_IngList() + + index: int = int(input("Please enter number:")) + print("DELETE: " + db.get_AllIngredients()[index][0]) + db.delete_Ingredient(db.get_AllIngredients()[index][0]) + pass + + +while True: + function: int = 0 + + print("1 -> print Ing List") + print("2 -> Add new Ing") + print("3 -> Delte Ing") + + print("10 -> print Ing List") + + function = int(input("Chose function:")) + + try: + if function == 1: + print_IngList() + if function == 2: + add_Ing() + if function == 3: + dell_Ing() + if function == 10: + print("------------------") + print(db.get_AllIngredients_asJson()) + print("------------------") + if function == -4: + print("------------------") + print(db.get_Servos_asJson()) + print("------------------") + + except ValueError: + print("Oops! That was no valid number. Try again...") From 0c3dc974434eab5d7f5110d8fe4f418406af15ec Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 4 Dec 2021 23:28:33 +0100 Subject: [PATCH 09/22] Add README-Region for Ingredients --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8a728b..ae24e8f 100644 --- a/README.md +++ b/README.md @@ -70,18 +70,27 @@ Or you can use the WebUI when it is implemented. A future extension might allow multi-language UIs. +Add Ingredients +--- +To edit the Ingredients that can be used you can edit the +database.py or use the tool in the tools folder. + + python3 Hector9000/tools/Editingredients.py + Assigning valves --- - The available ingredients are also moved to the db and can initial be edited in the databas.py or over the WEB UI in the future. -For teh meantime you can use the script "SetValveIng.py". +For the meantime you can use the script "SetValveIng.py". python3 Hector9000/tools/SetValveIng.py + + + Development on non-Hector hardware : --- From e10baa2a53d11c5c318489404d1118ac524bc036 Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 4 Dec 2021 23:28:53 +0100 Subject: [PATCH 10/22] Make output nicer for list of ing. --- Hector9000/tools/Editingredients.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Hector9000/tools/Editingredients.py b/Hector9000/tools/Editingredients.py index 8d44a66..9eba2ad 100644 --- a/Hector9000/tools/Editingredients.py +++ b/Hector9000/tools/Editingredients.py @@ -12,6 +12,8 @@ def print_IngList(): for x in inglist: print(str(counter) + ": " + x[0] + " | " + x[1]) counter = counter + 1 + + print("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") pass From 16007c92491236f2f2861d898b06bd13ce982a82 Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 18 Dec 2021 22:58:37 +0100 Subject: [PATCH 11/22] Update Unittests --- Hector9000/conf/database.py | 2 +- tests/helpers/h9kTestHelper.py | 41 ++++++++++++++++----------------- tests/test_database.py | 42 +++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/Hector9000/conf/database.py b/Hector9000/conf/database.py index 1b26426..0acf907 100644 --- a/Hector9000/conf/database.py +++ b/Hector9000/conf/database.py @@ -230,7 +230,7 @@ def add_Ingredient(self, short: str, long: str, isAlcohol: int): def delete_Ingredient(self, code: str): self.cur.execute("DELETE FROM Ingredients WHERE Code = ?", - code) + (code,)) self.con.commit() def countUpDrink(self, drink: str): diff --git a/tests/helpers/h9kTestHelper.py b/tests/helpers/h9kTestHelper.py index f8bbcfe..664301d 100644 --- a/tests/helpers/h9kTestHelper.py +++ b/tests/helpers/h9kTestHelper.py @@ -5,24 +5,23 @@ class dbHelper: - def __init__(self): - self.database = Hector.conf.database.Database() - - def prepareDB(self): - self.resetDB() - - self.database.createIfNotExists() - self.database.setDefaultValues() - - def resetDB(self): - #self.database.cur.execute("DELETE FROM Drinks;") - self.database.cur.execute("DELETE FROM settings;") - self.database.cur.execute("DELETE FROM Servos;") - #self.database.cur.execute("DELETE FROM Ingredients;") - #self.database.cur.execute("DELETE FROM Actions;") - self.database.cur.execute("DELETE FROM DrinksLog;") - self.database.cur.execute("DELETE FROM IngredientsLog;") - - - def removeDB(self): - os.remove("./h9k.db") + def __init__(self): + self.database = Hector.conf.database.Database() + + def prepareDB(self): + self.resetDB() + + self.database.createIfNotExists() + self.database.setDefaultValues() + + def resetDB(self): + # self.database.cur.execute("DELETE FROM Drinks;") + self.database.cur.execute("DELETE FROM settings;") + self.database.cur.execute("DELETE FROM Servos;") + self.database.cur.execute("DELETE FROM Ingredients;") + # self.database.cur.execute("DELETE FROM Actions;") + self.database.cur.execute("DELETE FROM DrinksLog;") + self.database.cur.execute("DELETE FROM IngredientsLog;") + + def removeDB(self): + os.remove("./h9k.db") diff --git a/tests/test_database.py b/tests/test_database.py index 888e056..5ae9fef 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -6,41 +6,65 @@ class Test_database: dbhelper = h9kTestHelper.dbHelper() - def test_GetServos(self): + @pytest.fixture(autouse=True) + def run_around_tests(self): + # Code that will run before your test, for example: self.dbhelper.prepareDB() + # A test function will be run at this point + yield + # Code that will run after your test, for example: + self.dbhelper.resetDB() + # assert files_before == files_after + + def test_GetServos(self): servos = self.dbhelper.database.get_Servos() assert len(servos) == 12 def test_GetServosAsList(self): - self.dbhelper.prepareDB() servos = self.dbhelper.database.get_Servos_asList() assert "['gren', 'rum', 'vodka', 'gin', 'tequila', 'gibe', 'lime', 'tonic', 'mate', " \ "'gga', 'pine', 'oj']" == str(servos) @pytest.mark.parametrize("servo, code", [(1, "gren"), (2, "rum")]) def test_Get_Servo(self, servo, code): - self.dbhelper.prepareDB() servo = self.dbhelper.database.get_Servo(servo) assert servo == code @pytest.mark.parametrize("servo, code", [(1, "oj"), (2, "gibe")]) def test_Set_Servo(self, servo, code): - self.dbhelper.prepareDB() item = self.dbhelper.database.set_Servo(servo, code) assert item == code - def test_GetIngredients(self): - self.dbhelper.prepareDB() + def test_addIngredient(self): + self.dbhelper.database.add_Ingredient("abcd", "Abcdefg", 1) + ing = self.dbhelper.database.get_AllIngredientsAsDict() + assert "{'gin': ('Gin', True), 'rum': ('Rum', True), 'vodka': ('Vodka', True), 'tequila': ('Tequila', True), " \ + "'tonic': ('Tonic Water', False), 'coke': ('Cola', False), 'oj': ('Orange Juice', False), " \ + "'gren': ('Grenadine', False), 'mmix': ('Margarita Mix', True), 'mate': ('Mate', False), " \ + "'pine': ('Pineapple Juice', False), 'raspberry': ('Raspberry', False), 'gga': ('Ginger Ale', False), " \ + "'cocos': ('Cocos', False), 'mango': ('Mango Juice', False), 'lms': ('Limettensaft', False), " \ + "'coin': ('Cointreau', True), 'lime': ('Lime', False), 'gibe': ('Ginger Beer', False), 'abcd': ('Abcdefg', True)}" == str(ing) + + def test_deleteIIngredient(self): + self.dbhelper.database.delete_Ingredient("gin") + ing = self.dbhelper.database.get_AllIngredientsAsDict() + assert "{'rum': ('Rum', True), 'vodka': ('Vodka', True), 'tequila': ('Tequila', True), " \ + "'tonic': ('Tonic Water', False), 'coke': ('Cola', False), 'oj': ('Orange Juice', False), " \ + "'gren': ('Grenadine', False), 'mmix': ('Margarita Mix', True), 'mate': ('Mate', False), " \ + "'pine': ('Pineapple Juice', False), 'raspberry': ('Raspberry', False), 'gga': ('Ginger Ale', False), " \ + "'cocos': ('Cocos', False), 'mango': ('Mango Juice', False), 'lms': ('Limettensaft', False), " \ + "'coin': ('Cointreau', True), 'lime': ('Lime', False), 'gibe': ('Ginger Beer', False)}" == str(ing) + + def test_GetIngredients(self): ing = self.dbhelper.database.get_AllIngredients() assert ing[0][1] == "Gin" def test_get_AllIngredientsAsDict(self): - self.dbhelper.prepareDB() ing = self.dbhelper.database.get_AllIngredientsAsDict() print(ing) assert "{'gin': ('Gin', True), 'rum': ('Rum', True), 'vodka': ('Vodka', True), 'tequila': ('Tequila', True), " \ @@ -51,14 +75,12 @@ def test_get_AllIngredientsAsDict(self): "'coin': ('Cointreau', True), 'lime': ('Lime', False), 'gibe': ('Ginger Beer', False)}" == str(ing) def test_count_up_ingredient(self): - self.dbhelper.prepareDB() self.dbhelper.database.countUpIngredient("Gin", 200) ingrcount = self.dbhelper.database.get_Ingredients_Log() assert len(ingrcount) == 1 def test_count_up_Drinks(self): - self.dbhelper.prepareDB() self.dbhelper.database.countUpDrink("Mate") drinkCount = self.dbhelper.database.get_Drinks_Log() @@ -66,14 +88,12 @@ def test_count_up_Drinks(self): @pytest.mark.parametrize("setting, value", [("cupsize", 400)]) def test_get_settings(self, setting, value): - self.dbhelper.prepareDB() item = int(self.dbhelper.database.get_Setting(setting)) assert item == value @pytest.mark.parametrize("setting, value", [("cupsize", "20")]) def test_set_settings(self, setting, value): - self.dbhelper.prepareDB() item = self.dbhelper.database.set_Setting(setting, value) assert item == value From e1d91ae5700660334558d9a7d2e602ddd6923aba Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 18 Dec 2021 22:59:07 +0100 Subject: [PATCH 12/22] Update Requirements and Setup --- Makefile | 2 +- requirements.txt | 2 +- setup.py | 6 +++--- setup.sh | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0e5b9c5..a82daab 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ help: venv: $(VIRTUALENV) ~/.venv/python_project/ ln -snf ~/.venv/python_project/ venv - venv/bin/pip install -e ."[dev]" + venv/bin/pip install -e '.[dev]' ## activate - Activate venv activate: diff --git a/requirements.txt b/requirements.txt index 912d23b..8df5d90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ pyparsing==2.4.0 pytest==5.4.1 requests==2.21.0 six==1.12.0 -spidev==3.2 +spidev==3.5 urllib3==1.26.5 wcwidth==0.1.7 webcolors==1.3 diff --git a/setup.py b/setup.py index a286dc8..9597382 100644 --- a/setup.py +++ b/setup.py @@ -40,15 +40,15 @@ 'pyparsing==2.4.0', 'requests==2.26.0', 'six==1.12.0', - 'spidev==3.2', 'urllib3==1.26.5', 'wcwidth==0.1.7', 'webcolors==1.3', - 'RPi.GPIO==0.7.0', 'zipp==3.1.0', ], extras_require={ - 'dev': ['pytest', 'flake8', 'autopep8']} + 'dev': ['pytest', 'flake8', 'autopep8'], + "pi": ['RPi.GPIO==0.7.0', 'spidev==3.5'], + } , entry_points={"console_scripts": ["HectorServer = Hector9000.HectorServer:main", "HectorController = Hector9000.HectorController:main", diff --git a/setup.sh b/setup.sh index 440690f..03f320f 100644 --- a/setup.sh +++ b/setup.sh @@ -79,4 +79,4 @@ then fi echo "install Hector9000" -python3 setup.py install +pip install -e '.[pi]' From ce2b4be4318a29be0d53ceefe874a804ea1427ce Mon Sep 17 00:00:00 2001 From: DevTown Date: Mon, 20 Dec 2021 21:09:35 +0100 Subject: [PATCH 13/22] Update paho-mqtt to 1.6.1 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8df5d90..8e5511a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ docutils==0.14 idna==2.8 more-itertools==7.0.0 packaging==19.0 -paho-mqtt==1.5.1 +paho-mqtt==1.6.1 pluggy==0.12.0 py==1.10.0 Pygments==2.7.4 diff --git a/setup.py b/setup.py index 9597382..ec3a6ac 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ 'idna==2.8', 'more-itertools==7.0.0', 'packaging==19.0', - 'paho-mqtt==1.5.0', + 'paho-mqtt==1.6.1', 'pluggy==0.12.0', 'py==1.10.0', 'Pygments==2.7.4', From dd27c53683d2eb1c96a974859dd53ba8dad78995 Mon Sep 17 00:00:00 2001 From: DevTown Date: Mon, 20 Dec 2021 21:14:17 +0100 Subject: [PATCH 14/22] rollback paho-mqtt --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8e5511a..8df5d90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ docutils==0.14 idna==2.8 more-itertools==7.0.0 packaging==19.0 -paho-mqtt==1.6.1 +paho-mqtt==1.5.1 pluggy==0.12.0 py==1.10.0 Pygments==2.7.4 diff --git a/setup.py b/setup.py index ec3a6ac..f78d5dc 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ 'idna==2.8', 'more-itertools==7.0.0', 'packaging==19.0', - 'paho-mqtt==1.6.1', + 'paho-mqtt==1.5.1', 'pluggy==0.12.0', 'py==1.10.0', 'Pygments==2.7.4', From e507cd9c2a5394405b638258a5a0a9ef7593e338 Mon Sep 17 00:00:00 2001 From: DevTown Date: Mon, 20 Dec 2021 21:16:40 +0100 Subject: [PATCH 15/22] add python 3.9, 3.10 --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 64b49dc..2d6efb8 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.6','3.7','3.8' ] + python-version: ['3.6','3.7','3.8','3.9','3.10' ] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 2b3cd8ae176a7cd4f7fa4d5590581f6f476792e3 Mon Sep 17 00:00:00 2001 From: DevTown Date: Thu, 23 Dec 2021 19:38:34 +0100 Subject: [PATCH 16/22] Test new paho-mqtt --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8df5d90..175dc48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ docutils==0.14 idna==2.8 more-itertools==7.0.0 packaging==19.0 -paho-mqtt==1.5.1 +paho-mqtt==1.6.0 pluggy==0.12.0 py==1.10.0 Pygments==2.7.4 diff --git a/setup.py b/setup.py index f78d5dc..8ca0c26 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ 'idna==2.8', 'more-itertools==7.0.0', 'packaging==19.0', - 'paho-mqtt==1.5.1', + 'paho-mqtt==1.6.0', 'pluggy==0.12.0', 'py==1.10.0', 'Pygments==2.7.4', From f38dfc1388ab8a20b78a8150ffcab8d053125b7e Mon Sep 17 00:00:00 2001 From: DevTown Date: Thu, 23 Dec 2021 19:42:12 +0100 Subject: [PATCH 17/22] Update Workflow --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2d6efb8..ffcd479 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.6','3.7','3.8','3.9','3.10' ] + python-version: ['3.8','3.9','3.10' ] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 461fe20f82fd5fb0c742cbeaa74117f3a8b8cf00 Mon Sep 17 00:00:00 2001 From: DevTown Date: Thu, 23 Dec 2021 19:44:06 +0100 Subject: [PATCH 18/22] Update paho-mqtt to 1.6.1 --- README.md | 1 + requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae24e8f..58fe752 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Minimal Requirements - RaspberryPi 3 - Debian bases Linux (to use installscript) + - Python 3.8 Prepare Raspberry --- diff --git a/requirements.txt b/requirements.txt index 175dc48..8e5511a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ docutils==0.14 idna==2.8 more-itertools==7.0.0 packaging==19.0 -paho-mqtt==1.6.0 +paho-mqtt==1.6.1 pluggy==0.12.0 py==1.10.0 Pygments==2.7.4 diff --git a/setup.py b/setup.py index 8ca0c26..ec3a6ac 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ 'idna==2.8', 'more-itertools==7.0.0', 'packaging==19.0', - 'paho-mqtt==1.6.0', + 'paho-mqtt==1.6.1', 'pluggy==0.12.0', 'py==1.10.0', 'Pygments==2.7.4', From a2eeeca9cb7fde3d43dca52222fa66e81ec40112 Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 19 Feb 2022 20:00:27 +0100 Subject: [PATCH 19/22] Update requirements, change version in setup.py --- .gitignore | 2 ++ requirements.txt | 2 +- setup.py | 8 +++++--- start.sh | 1 - 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 96aaca2..1708e61 100755 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,5 @@ src/Hector9000/log *.py-0 *.py-1 + +/dist \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8e5511a..4f5039c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ py==1.10.0 Pygments==2.7.4 pyparsing==2.4.0 pytest==5.4.1 -requests==2.21.0 +requests==2.27.1 six==1.12.0 spidev==3.5 urllib3==1.26.5 diff --git a/setup.py b/setup.py index ec3a6ac..931d0e9 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="Hector9000", - version="0.1.0", + version="0.1.0rc2", author="DevTown", author_email="Hector@dev-town.de", description="Fancy barbot with lots of needless features and ...of course... WiFi and a bunch of blinky LEDs", @@ -16,7 +16,9 @@ classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", - "Operating System :: OS Raspbian", + "Natural Language :: English", + "Natural Language :: German", + "Operating System :: OS Independent", ], python_requires='>=3.6', install_requires=[ @@ -38,7 +40,7 @@ 'py==1.10.0', 'Pygments==2.7.4', 'pyparsing==2.4.0', - 'requests==2.26.0', + 'requests==2.27.1', 'six==1.12.0', 'urllib3==1.26.5', 'wcwidth==0.1.7', diff --git a/start.sh b/start.sh index d3cb9c4..040051d 100644 --- a/start.sh +++ b/start.sh @@ -16,4 +16,3 @@ nohup python3 Hector9000/HectorController.py > Controller.out 2>&1 & echo "Start HectorLED-Server" nohup sudo python3 Hector9000/LEDStripServer.py > /dev/null 2>&1 & - From 8e4e6f3b1227c61d2d1a19021462da1358863e5f Mon Sep 17 00:00:00 2001 From: DevTown Date: Thu, 17 Mar 2022 21:41:18 +0100 Subject: [PATCH 20/22] Modify mqtt config to allow anon usage --- setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.sh b/setup.sh index 03f320f..c126503 100644 --- a/setup.sh +++ b/setup.sh @@ -74,6 +74,7 @@ then echo 'listener 9001' >> /etc/mosquitto/mosquitto.conf echo 'protocol websockets' >> /etc/mosquitto/mosquitto.conf echo 'socket_domain ipv4' >> /etc/mosquitto/mosquitto.conf + echo 'allow_anonymous true' >> /etc/mosquitto/mosquitto.conf systemctl start mosquitto fi From ccad571b2b40d20d5f7952d9acbac78e83e8e92b Mon Sep 17 00:00:00 2001 From: DevTown Date: Fri, 18 Mar 2022 21:39:23 +0100 Subject: [PATCH 21/22] Test older setupstyle --- setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index c126503..ec820fd 100644 --- a/setup.sh +++ b/setup.sh @@ -80,4 +80,5 @@ then fi echo "install Hector9000" -pip install -e '.[pi]' +#pip install -e . +python setup.py develop From c8d2f801612e23b35f8bed4ca8d80c2660956d1c Mon Sep 17 00:00:00 2001 From: DevTown Date: Sat, 19 Mar 2022 22:08:42 +0100 Subject: [PATCH 22/22] Update --- .github/workflows/python-app.yml | 2 +- Hector9000/HectorServer.py | 33 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ffcd479..58cb654 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Python application +name: Hector9000Test on: push: diff --git a/Hector9000/HectorServer.py b/Hector9000/HectorServer.py index 3014a02..ac0a371 100644 --- a/Hector9000/HectorServer.py +++ b/Hector9000/HectorServer.py @@ -8,11 +8,20 @@ import time import re +import traceback +import os + import paho.mqtt.client as mqtt from Hector9000.conf import HectorConfig as HC -# from Hector9000.HectorHardware import HectorHardware as Hector -from Hector9000.HectorSimulator import HectorSimulator as Hector +isSim = 0 +#isSim = os.environ.get('isHectorSim', 0) + +print(isSim) +if isSim != 1: + from Hector9000.HectorHardware import HectorHardware as Hector +else: + from Hector9000.HectorSimulator import HectorSimulator as Hector # global vars @@ -235,13 +244,19 @@ def on_message(client, userdata, msg): ret = do_valve_dose(index=args[0], amount=args[1], timeout=args[2]) res = 1 if ret else -1 log("Sending return") - client.publish(MainTopic + topic + "/return", res) - # ToDo: this line ^ causes trouble. Sometimes it just doesnt send the - # publish causing errors. Some tests need to be written to test the - # most reliable way to fix this - while not client.want_write(): - pass - client.loop_write() + try: + client.publish(MainTopic + topic + "/return", res) + # ToDo: this line ^ causes trouble. Sometimes it just doesnt send the + # publish causing errors. Some tests need to be written to test the + # most reliable way to fix this + while not client.want_write(): + pass + except Exception as e: + # as first try if error try again :-( + log(traceback.format_exc()) + client.publish(MainTopic + topic + "/return", res) + while not client.want_write(): + pass log("Return Send - Dosing Complete") elif topic == "cleanMe": clean(int(msg.payload.decode("utf-8")))