-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #732 from thorrak/dev
Update Master with Dev
- Loading branch information
Showing
10 changed files
with
149 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/python | ||
# Copyright 2012 BrewPi | ||
# This file is part of BrewPi. | ||
|
||
import datetime | ||
# BrewPi is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
|
@@ -36,6 +36,17 @@ | |
from scriptlibs import expandLogMessage | ||
from scriptlibs.backgroundserial import BackGroundSerial | ||
|
||
import sentry_sdk | ||
sentry_sdk.init( | ||
"http://[email protected]:9000/13", | ||
|
||
# Set traces_sample_rate to 1.0 to capture 100% | ||
# of transactions for performance monitoring. | ||
# We recommend adjusting this value in production. | ||
traces_sample_rate=0.0 | ||
) | ||
|
||
|
||
# Settings will be read from controller, initialize with same defaults as controller | ||
# This is mainly to show what's expected. Will all be overwritten on the first update from the controller | ||
|
||
|
@@ -668,30 +679,33 @@ def trigger_refresh(read_values=False): | |
logMessage("Error receiving mode from controller - restarting") | ||
sys.exit(1) | ||
if cs['mode'] == 'p': | ||
new_temp = config_obj.get_profile_temp() | ||
|
||
if new_temp is None: # If we had an error loading a temperature (from dbConfig) disable temp control | ||
cs['mode'] = 'o' | ||
bg_ser.writeln("j{mode:\"o\"}") | ||
logMessage("Notification: Error in profile mode - turning off temp control") | ||
# raise socket.timeout # go to serial communication to update controller | ||
elif round(new_temp, 2) != cs['beerSet']: | ||
try: | ||
new_temp = float(new_temp) | ||
cs['beerSet'] = round(new_temp, 2) | ||
except ValueError: | ||
logMessage("Cannot convert temperature '" + new_temp + "' to float") | ||
continue | ||
# if temperature has to be updated send settings to controller | ||
bg_ser.writeln("j{beerSet:" + json.dumps(cs['beerSet']) + "}") | ||
|
||
if config_obj.is_past_end_of_profile(): | ||
bg_ser.writeln("j{mode:\"b\", beerSet:" + json.dumps(cs['beerSet']) + "}") | ||
cs['mode'] = 'b' | ||
refresh_and_check(config_obj, run) # Reload dbConfig from the database | ||
config_obj.reset_profile() | ||
logMessage("Notification: Beer temperature set to constant " + str(cs['beerSet']) + | ||
" degrees at end of profile") | ||
# Limit profile updates to once every 30 seconds (prevents hammering the database) | ||
if datetime.datetime.now() > (config_obj.last_profile_temp_check + datetime.timedelta(seconds=30)): | ||
config_obj.last_profile_temp_check = datetime.datetime.now() # Update the last check time | ||
new_temp = config_obj.get_profile_temp() | ||
|
||
if new_temp is None: # If we had an error loading a temperature (from dbConfig) disable temp control | ||
cs['mode'] = 'o' | ||
bg_ser.writeln("j{mode:\"o\"}") | ||
logMessage("Notification: Error in profile mode - turning off temp control") | ||
# raise socket.timeout # go to serial communication to update controller | ||
elif round(new_temp, 2) != cs['beerSet']: | ||
try: | ||
new_temp = float(new_temp) | ||
cs['beerSet'] = round(new_temp, 2) | ||
except ValueError: | ||
logMessage("Cannot convert temperature '" + new_temp + "' to float") | ||
continue | ||
# if temperature has to be updated send settings to controller | ||
bg_ser.writeln("j{beerSet:" + json.dumps(cs['beerSet']) + "}") | ||
|
||
if config_obj.is_past_end_of_profile(): | ||
bg_ser.writeln("j{mode:\"b\", beerSet:" + json.dumps(cs['beerSet']) + "}") | ||
cs['mode'] = 'b' | ||
refresh_and_check(config_obj, run) # Reload dbConfig from the database | ||
config_obj.reset_profile() | ||
logMessage("Notification: Beer temperature set to constant " + str(cs['beerSet']) + | ||
" degrees at end of profile") | ||
|
||
except socket.error as e: | ||
logMessage("Socket error(%d): %s" % (e.errno, e.strerror)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,19 @@ | |
from fermentrack_config_loader import FermentrackBrewPiScriptConfig, get_active_brewpi_devices | ||
from brewpi import BrewPiScript | ||
|
||
import sentry_sdk | ||
sentry_sdk.init( | ||
"http://[email protected]:9000/13", | ||
|
||
# Set traces_sample_rate to 1.0 to capture 100% | ||
# of transactions for performance monitoring. | ||
# We recommend adjusting this value in production. | ||
traces_sample_rate=0.0 | ||
) | ||
|
||
if __name__ == '__main__': | ||
process_list = {} | ||
config_list = {} | ||
|
||
while 1: | ||
# Clean out dead processes from the process list | ||
|
@@ -22,6 +32,7 @@ | |
for this_process in processes_to_delete: | ||
# Do this as step 2 since we can't change the process list mid-iteration | ||
# print(f"Deleting process for BrewPiDevice #{this_process}") | ||
process_list[this_process].join(10) # Join the completed process | ||
del process_list[this_process] | ||
|
||
active_device_ids = get_active_brewpi_devices() | ||
|
@@ -31,13 +42,15 @@ | |
if this_id not in process_list: | ||
# The process hasn't been spawned. Spawn it. | ||
# print(f"Launching process for BrewPiDevice #{this_id}") | ||
if this_id in config_list: | ||
config_list.pop(this_id) | ||
try: | ||
brewpi_config = FermentrackBrewPiScriptConfig(brewpi_device_id=this_id) | ||
brewpi_config.load_from_fermentrack(False) | ||
config_list[this_id] = FermentrackBrewPiScriptConfig(brewpi_device_id=this_id) | ||
config_list[this_id].load_from_fermentrack(False) | ||
process_list[this_id] = Process(target=BrewPiScript, args=(config_list[this_id], )) | ||
process_list[this_id].start() | ||
time.sleep(10) # Give each controller 10 seconds to start up | ||
except StopIteration: | ||
pass | ||
else: | ||
process_list[this_id] = Process(target=BrewPiScript, args=(brewpi_config, )) | ||
process_list[this_id].start() | ||
|
||
time.sleep(5) | ||
time.sleep(5) # Wait 5 seconds in each loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters