Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC Release #35

Merged
merged 27 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
name: Custom issue template

about: Describe this issue template's purpose here.

title: ''

labels: ''

assignees: ''

---
Expand All @@ -12,8 +16,12 @@ Your description:

--------------
Pi version:

Pi OS:

Hector version:

Python version:

--------------
Error message:
12 changes: 8 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# 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:
branches: [ master ]
branches:
- master
- development
pull_request:
branches: [ master ]
branches:
- master
- development

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.6','3.7','3.8' ]
python-version: ['3.8','3.9','3.10' ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
.idea/dictionaries
venv/
.vscode/
build/
Hector9000.egg-info/

# Sensitive or high-churn files:
.idea/**/dataSources/
Expand Down Expand Up @@ -98,3 +100,5 @@ src/Hector9000/log
*.py-0

*.py-1

/dist
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"

before_install:
- sudo apt-get -y install mosquitto
Expand All @@ -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
18 changes: 15 additions & 3 deletions Hector9000/HectorController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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":
Expand All @@ -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()
Expand Down
22 changes: 0 additions & 22 deletions Hector9000/HectorHardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
6 changes: 6 additions & 0 deletions Hector9000/HectorRemote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 28 additions & 9 deletions Hector9000/HectorServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -235,14 +244,24 @@ 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")))
elif topic == "dryMe":
dry(int(msg.payload.decode("utf-8")))
else:
warning("Unknown topic")

Expand Down
6 changes: 3 additions & 3 deletions Hector9000/LEDStripServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
Expand All @@ -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:
Expand Down
49 changes: 39 additions & 10 deletions Hector9000/conf/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -202,9 +211,29 @@ 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 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):
def countUpDrink(self, drink: str):
self.cur.execute(
"INSERT INTO DrinksLog (drink, date) VALUES (?, ?)",
(drink,
Expand Down Expand Up @@ -246,4 +275,4 @@ def get_Drinks_Log(self):
(strftime(
"%a %Y-%m-%d %H:%M:%S",
localtime(tstamp)),
name))
name))
1 change: 1 addition & 0 deletions Hector9000/conf/hx711.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa
import RPi.GPIO as GPIO
import time
import numpy # sudo apt-get python-numpy
Expand Down
Loading