Skip to content

Commit

Permalink
Fixing codesmells
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTown committed Apr 26, 2023
1 parent 4b3e9a7 commit ebce0b5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
18 changes: 9 additions & 9 deletions Hector9000/HectorController.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ def available_drinks_as_JSON(self):

# todo: give all Infos for stearing or ....
def _get_drink_as_JSON(self, msg):
id = int(msg.payload)
drink = drinks.available_drinks[id - 1]
drinkid = int(msg.payload)
drink = drinks.available_drinks[drinkid - 1]
inglist = [{"name": drinks.ingredients[step[1]][0], "ammount": step[2]}
for step in drink["recipe"] if step[0] == "ingr"]
data = {"id": id, "name": drink["name"], "ingredients": inglist}
data = {"id": drinkid, "name": drink["name"], "ingredients": inglist}
debug(data)
return json.dumps(data)

def _get_ingredients(self, msg):
def _get_ingredients(self):
debug("get_AllIngredients_asJson")
return self.db.get_AllIngredients_asJson()

def _get_servo(self, msg):
debug("_get_servo: " + msg)
id = int(msg.payload)
return self.db.get_Servo(id)
servoid = int(msg.payload)
return self.db.get_Servo(servoid)

def _get_all_servos(self, msg):
def _get_all_servos(self):
debug("get_all_servos")
return self.db.get_Servos_asJson()

Expand Down Expand Up @@ -136,8 +136,8 @@ def _do_set_servo(self, msg):

def _do_dose_drink(self, msg):
debug("start dosing drink")
id = int(msg.payload)
drink = drinks.available_drinks[id - 1]
drinkid = int(msg.payload)
drink = drinks.available_drinks[drinkid - 1]
# Return ID of drink to identify that drink creation starts
self.client.publish(self.get_returnTopic(msg.topic), msg.payload)
progress = 0
Expand Down
4 changes: 2 additions & 2 deletions Hector9000/HectorHardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ def valve_dose(
self.scale_tare()
self.pump_start()
self.valve_open(index)
sr = self.scale_readout()
sr: float = self.scale_readout()
if sr < -10:
amount = amount + sr
balance = False
last_over = False
last = sr
last: float = sr
while True:
sr = self.scale_readout()
if balance and sr < -10:
Expand Down
8 changes: 2 additions & 6 deletions Hector9000/HectorServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# HectorServer.py Hector server with MQTT interface
#

# imports

import time
import re
Expand All @@ -25,7 +24,6 @@
from Hector9000.HectorSimulator import HectorSimulator as Hector


# global vars
MainTopic = "Hector9000/Hardware/"
MQTTIP = "localhost"
MQTTPORT = 1883
Expand Down Expand Up @@ -138,9 +136,9 @@ def do_all_valve_close():
hector.light_off()


def do_valve_open(index, open):
def do_valve_open(index):
log("open valve %d" % index)
hector.valve_open(index, open)
hector.valve_open(index)


def do_valve_close(index):
Expand All @@ -158,8 +156,6 @@ def do_ping(num, retract):
hector.ping(num, retract)


# high-level functions

def dry(pump):
log("drying pump %d" % pump)
hector.valve_open(pump)
Expand Down
2 changes: 1 addition & 1 deletion Hector9000/conf/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sqlite3 as lite
import datetime
import json
from time import *
from time import mktime, strptime, strftime, localtime


# ToDo:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Chat: Join the Chat at [Discord](https://discord.gg/MHJh4bBddY)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=H3c702_Hector9000&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=H3c702_Hector9000)

| Branch | Status |
| ------------- | ------------- |
| Master | [![Build Status(Master)](https://travis-ci.com/H3c702/Hector9000.svg?branch=master&label=master)](https://travis-ci.com/H3c702/Hector9000/branches) |
Expand Down
2 changes: 1 addition & 1 deletion tests/test_HectorController.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_Get_DrinkByID(self):
print(drink)
assert drink == '{"id": 5, "name": "Virgin Sunrise", "ingredients": [{"name": "Orange Juice", "ammount": 140}, {"name": "Grenadine", "ammount": 15}]}'

def __exit__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self.dbhelper.removeDB()


Expand Down
2 changes: 1 addition & 1 deletion tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ def test_set_settings(self, setting, value):

# ---------------------------------------------------------------------

def __exit__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self.dbhelper.removeDB()

0 comments on commit ebce0b5

Please sign in to comment.