restart scheduler brightness whenever stop start
This commit is contained in:
parent
150aa672ec
commit
aa7a20d8f5
200
server.py
200
server.py
@ -312,6 +312,99 @@ def index():
|
||||
|
||||
|
||||
|
||||
def scheduled_brightness():
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
f = open('csv/scheduler.json','r')
|
||||
schedules = json.load(f)
|
||||
f.close()
|
||||
except:
|
||||
schedules = {"shutdown": {"hour": "00", "minute": "00", "enabled": False}, "reboot":{"hour": "00", "minute": "00", "enabled": False}, "timezone": "GMT", "brightness1":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness2":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness3":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness4":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}}
|
||||
|
||||
timezone_brightness = schedules['timezone']
|
||||
|
||||
brightness1_hour = schedules['brightness1']['hour']
|
||||
brightness1_minute = schedules['brightness1']['minute']
|
||||
brightness1_bright = schedules['brightness1']['bright']
|
||||
brightness1_enabled = schedules['brightness1']['enabled']
|
||||
|
||||
brightness2_hour = schedules['brightness2']['hour']
|
||||
brightness2_minute = schedules['brightness2']['minute']
|
||||
brightness2_bright = schedules['brightness2']['bright']
|
||||
brightness2_enabled = schedules['brightness2']['enabled']
|
||||
|
||||
brightness3_hour = schedules['brightness3']['hour']
|
||||
brightness3_minute = schedules['brightness3']['minute']
|
||||
brightness3_bright = schedules['brightness3']['bright']
|
||||
brightness3_enabled = schedules['brightness3']['enabled']
|
||||
|
||||
brightness4_hour = schedules['brightness4']['hour']
|
||||
brightness4_minute = schedules['brightness4']['minute']
|
||||
brightness4_bright = schedules['brightness4']['bright']
|
||||
brightness4_enabled = schedules['brightness4']['enabled']
|
||||
|
||||
try:
|
||||
if brightness1_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness1_hour+':'+brightness1_minute:
|
||||
brightness = max(min(int(brightness1_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if brightness2_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness2_hour+':'+brightness2_minute:
|
||||
brightness = max(min(int(brightness2_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if brightness3_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness3_hour+':'+brightness3_minute:
|
||||
brightness = max(min(int(brightness3_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if brightness4_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness4_hour+':'+brightness4_minute:
|
||||
brightness = max(min(int(brightness4_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
time.sleep(20)
|
||||
except:
|
||||
pass
|
||||
|
||||
scheduled_b = Process(target=scheduled_brightness)
|
||||
scheduled_b.start()
|
||||
|
||||
|
||||
|
||||
def save_displaying(input_settings):
|
||||
|
||||
global professional
|
||||
@ -363,7 +456,13 @@ def start():
|
||||
ticker_stopped = False
|
||||
|
||||
#api_caller.sendline('A')
|
||||
|
||||
|
||||
global scheduled_b
|
||||
if scheduled_b.is_alive():
|
||||
scheduled_b.terminate()
|
||||
scheduled_b = Process(target=scheduled_brightness)
|
||||
scheduled_b.start()
|
||||
|
||||
ticker.sendline('K')
|
||||
|
||||
ticker.sendline('A')
|
||||
@ -400,7 +499,10 @@ def stop():
|
||||
#api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
|
||||
#api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 database_caller.py")
|
||||
displaying_screensaver = False
|
||||
|
||||
|
||||
|
||||
scheduled_b.terminate()
|
||||
|
||||
return index()
|
||||
|
||||
@app.route("/update", methods=['PUT','POST'])
|
||||
@ -872,7 +974,7 @@ def screensaver():
|
||||
else: #default in case user hasnt set one yet
|
||||
screensaver_p = DummyProcess()
|
||||
|
||||
|
||||
scheduled_b.terminate()
|
||||
displaying_screensaver = True
|
||||
return index()
|
||||
|
||||
@ -1233,98 +1335,6 @@ def saveSchedulerSettings():
|
||||
|
||||
|
||||
|
||||
def scheduled_brightness():
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
f = open('csv/scheduler.json','r')
|
||||
schedules = json.load(f)
|
||||
f.close()
|
||||
except:
|
||||
schedules = {"shutdown": {"hour": "00", "minute": "00", "enabled": False}, "reboot":{"hour": "00", "minute": "00", "enabled": False}, "timezone": "GMT", "brightness1":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness2":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness3":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness4":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}}
|
||||
|
||||
timezone_brightness = schedules['timezone']
|
||||
|
||||
brightness1_hour = schedules['brightness1']['hour']
|
||||
brightness1_minute = schedules['brightness1']['minute']
|
||||
brightness1_bright = schedules['brightness1']['bright']
|
||||
brightness1_enabled = schedules['brightness1']['enabled']
|
||||
|
||||
brightness2_hour = schedules['brightness2']['hour']
|
||||
brightness2_minute = schedules['brightness2']['minute']
|
||||
brightness2_bright = schedules['brightness2']['bright']
|
||||
brightness2_enabled = schedules['brightness2']['enabled']
|
||||
|
||||
brightness3_hour = schedules['brightness3']['hour']
|
||||
brightness3_minute = schedules['brightness3']['minute']
|
||||
brightness3_bright = schedules['brightness3']['bright']
|
||||
brightness3_enabled = schedules['brightness3']['enabled']
|
||||
|
||||
brightness4_hour = schedules['brightness4']['hour']
|
||||
brightness4_minute = schedules['brightness4']['minute']
|
||||
brightness4_bright = schedules['brightness4']['bright']
|
||||
brightness4_enabled = schedules['brightness4']['enabled']
|
||||
|
||||
try:
|
||||
if brightness1_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness1_hour+':'+brightness1_minute:
|
||||
brightness = max(min(int(brightness1_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if brightness2_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness2_hour+':'+brightness2_minute:
|
||||
brightness = max(min(int(brightness2_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if brightness3_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness3_hour+':'+brightness3_minute:
|
||||
brightness = max(min(int(brightness3_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
if brightness4_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness4_hour+':'+brightness4_minute:
|
||||
brightness = max(min(int(brightness4_bright), 10), 1)
|
||||
ticker.sendline(str(brightness-1))
|
||||
f = open('csv/general_settings.json', 'r')
|
||||
general_settings = json.load(f)
|
||||
f.close()
|
||||
general_settings['brightness'] = int(brightness)
|
||||
f = open('csv/general_settings.json', 'w')
|
||||
json.dump(general_settings, f)
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
time.sleep(20)
|
||||
except:
|
||||
pass
|
||||
|
||||
scheduled_b = Process(target=scheduled_brightness)
|
||||
scheduled_b.start()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user