Skip to content

Commit

Permalink
Autopep applied v3
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBojan committed Feb 29, 2024
1 parent 84698c5 commit 243d4a3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 45 deletions.
16 changes: 4 additions & 12 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ def on_message_handler(client, userdata, message):
if data_value > 95:
# sound the alarm! ask him what do I send #ASK
customLogger.info(
"Temperature of " +
str(data_value) +
" C is too high! Sounding the alarm!")
"Temperature of " + str(data_value) + " C is too high! Sounding the alarm!")
client.publish(temp_alarm_topic, True, qos)

# initializing stats object
Expand Down Expand Up @@ -522,10 +520,7 @@ def on_message_handler(client, userdata, message):
time_value = time.strftime(time_format, time.localtime())
if data_sum > 1000:
# sound the alarm! ask him what do I send #ASK
customLogger.info(
"Load of " +
str(data_sum) +
" kg is too high! Sounding the alarm!")
customLogger.info("Load of " + str(data_sum) + " kg is too high! Sounding the alarm!")
client.publish(load_alarm_topic, True, qos)

# initializing stats object
Expand Down Expand Up @@ -680,8 +675,7 @@ def on_message_handler(client, userdata, message):
str(message.payload.decode("utf-8")))

code = data_service.handle_fuel_data(
str(
message.payload.decode("utf-8")),
str(message.payload.decode("utf-8")),
config.get_fuel_settings_level_limit(),
url,
jwt,
Expand Down Expand Up @@ -785,13 +779,11 @@ def main():
"STATS PUBLISHER ESTABLISHED CONNECTION WITH BROKER.")

stats = stats_service.OverallStats(
config.get_server_url() +
"/stats",
config.get_server_url() + "/stats",
jwt,
config.get_iot_username(),
config.get_time_format(),
gcb_client)

temp_stats_queue = Queue()
load_stats_queue = Queue()
fuel_stats_queue = Queue()
Expand Down
12 changes: 3 additions & 9 deletions src/can_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,9 @@ def on_message_received(self, msg):
"{:.2f}".format(value), str(
time.strftime(
time_format, time.localtime())), celzius), qos)
customLogger.info(
"Temperature: " +
data_pattern.format(
"{:.2f}".format(value),
str(
time.strftime(
time_format,
time.localtime())),
celzius))
customLogger.info("Temperature: " + data_pattern.format("{:.2f}".format(value),
str(time.strftime(time_format,time.localtime())),
celzius))
elif hex(msg.arbitration_id) == "0x124" and self.load_client is not None:
self.load_client.publish(
load_topic, data_pattern.format(
Expand Down
8 changes: 5 additions & 3 deletions src/config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ def try_open(self):

self.config = {
fuel_settings: {
"fuel_level_limit": 200, "mode": "SIMULATOR"}, temp_settings: {
"temp_interval": 20, "mode": "SIMULATOR"}, load_settings: {
"load_interval": 20, "mode": "SIMULATOR"}, }
level_limit: 200, mode: "SIMULATOR"}, temp_settings: {
interval: 20, mode: "SIMULATOR"}, load_settings: {
interval: 20, mode: "SIMULATOR"}, server_url: "", mqtt_broker: {
username: "", password: ""
}}

def get_temp_mode(self):
return self.config[temp_settings][mode]
Expand Down
10 changes: 3 additions & 7 deletions src/mqtt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def connect(self):
while not self.client.is_connected() and not self.flag.is_set():
try:
self.infoLogger.info(
self.sensor_type +
" sensor establishing connection with MQTT broker!") # TODO alarm vs sensor
self.sensor_type + " sensor establishing connection with MQTT broker!")
self.client.connect(
self.broker_address,
port=self.broker_port,
Expand All @@ -66,15 +65,12 @@ def connect(self):

except Exception as e:
self.errorLogger.error(
self.sensor_type +
" sensor failed to establish connection with MQTT broker!")
print(e)
self.sensor_type + " sensor failed to establish connection with MQTT broker!")

def try_reconnect(self):
while not self.client.is_connected() and not self.flag.is_set():
self.errorLogger.error(
self.sensor_type +
" sensor lost connection to MQTT broker!")
self.sensor_type + " sensor lost connection to MQTT broker!")
self.client.reconnect()
time.sleep(0.2)

Expand Down
24 changes: 10 additions & 14 deletions src/sensor_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ def measure_temperature_periodically(
value = avg_val + data[counter % values_count]
counter += 1
customLogger.error(
"Temperature: " +
data_pattern.format(
"Temperature: " + data_pattern.format(
"{:.2f}".format(value),
str(
time.strftime(
Expand Down Expand Up @@ -460,11 +459,9 @@ def measure_load_randomly(
client.reconnect()
time.sleep(0.1)
try:
customLogger.info("Load: " +
data_pattern.format("{:.2f}".format(data[counter %
values_count]),
str(time.strftime(time_format, time.localtime())),
kg))
customLogger.info("Load: " + data_pattern.format("{:.2f}".format(data[counter % values_count]),
str(time.strftime(time_format, time.localtime())),
kg))
# send data to MQTT broker
client.publish(load_topic, data_pattern.format("{:.2f}".format(data[counter % values_count]), str(
time.strftime(time_format, time.localtime())), kg), qos=qos)
Expand Down Expand Up @@ -532,7 +529,7 @@ def measure_fuel_periodically(
'''
customLogger.debug("Fuel level sensor started!")
customLogger.debug(
"Fuel level sensor conf: period={}s, capacity={}l, consumption={}l/h, efficiency={}, refill={}". format(
"Fuel level sensor conf: period={}s, capacity={}l, consumption={}l/h, efficiency={}, refill={}".format(
period,
capacity,
consumption,
Expand Down Expand Up @@ -606,8 +603,7 @@ def measure_fuel_periodically(
time.sleep(0.1)
try:
customLogger.warning(
"Fuel: " +
data_pattern.format(
"Fuel: " + data_pattern.format(
"{:.2f}".format(value),
str(
time.strftime(
Expand Down Expand Up @@ -828,10 +824,10 @@ def __init__(self):
self.fuel_simulator_initiated = False

def has_started(self):
if (self.can_initiated is True or
self.temp_simulator_initiated is True or
self.load_simulator_initiated is True or
self.fuel_simulator_initiated is True):
if (self.can_initiated is True
or self.temp_simulator_initiated is True
or self.load_simulator_initiated is True
or self.fuel_simulator_initiated is True):
return True
return False

Expand Down

0 comments on commit 243d4a3

Please sign in to comment.