some deletes and refs
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
<span>
|
||||
<form action="/on"><button type="submit">Relay On</button></form>
|
||||
<form action="/off"><button type="submit">Relay Off</button></form>
|
||||
<form action="/toggle"><button type="submit">Toggle Relay</button></form>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ name = "Test Sensor"
|
||||
|
||||
humidity_limit_path = 'humidity_limit'
|
||||
sensor_log_path = 'sensors.log'
|
||||
|
||||
log_file: io.TextIOWrapper
|
||||
log_cursor_file: io.TextIOWrapper
|
||||
|
||||
@@ -47,8 +48,12 @@ def write_log():
|
||||
|
||||
log_values(log_file)
|
||||
|
||||
pos = log_file.tell()
|
||||
update_cursor_file(pos)
|
||||
|
||||
def update_cursor_file(pos):
|
||||
log_cursor_file.seek(0,0)
|
||||
log_cursor_file.write(str(log_file.tell()))
|
||||
log_cursor_file.write(str(pos))
|
||||
|
||||
def log_values(file):
|
||||
global temp, humidity
|
||||
@@ -75,11 +80,10 @@ def update(_):
|
||||
write_log()
|
||||
|
||||
def update_relay():
|
||||
if humidity > humidity_limit:
|
||||
if high_humidity():
|
||||
relay_on()
|
||||
return
|
||||
|
||||
relay_off()
|
||||
else:
|
||||
relay_off()
|
||||
|
||||
def high_humidity() -> bool:
|
||||
return humidity >= humidity_limit
|
||||
@@ -107,13 +111,6 @@ def serve_root(_):
|
||||
|
||||
send_response(server, index)
|
||||
|
||||
def toggle_relay(_):
|
||||
global relay
|
||||
val = relay.value()
|
||||
relay.value(not val)
|
||||
|
||||
redirect_root()
|
||||
|
||||
def handle_relay_off(_):
|
||||
relay_off()
|
||||
redirect_root()
|
||||
@@ -160,7 +157,6 @@ def read_limit() -> int:
|
||||
return int(file.readline())
|
||||
|
||||
def init():
|
||||
init_clock()
|
||||
init_log()
|
||||
init_settings()
|
||||
init_timer()
|
||||
@@ -179,18 +175,14 @@ def init_log():
|
||||
|
||||
cursor = 0
|
||||
cursor_content = log_cursor_file.readline()
|
||||
print(cursor_content)
|
||||
|
||||
try:
|
||||
cursor = int(cursor_content)
|
||||
except:
|
||||
cursor = 0
|
||||
|
||||
print(cursor)
|
||||
log_file.seek(cursor, 0)
|
||||
|
||||
def init_clock():
|
||||
ntptime.settime()
|
||||
|
||||
def init_settings():
|
||||
global humidity_limit
|
||||
|
||||
@@ -208,7 +200,6 @@ def init_timer():
|
||||
def init_webserver():
|
||||
load_index_template()
|
||||
server.add_route('/', serve_root)
|
||||
server.add_route('/toggle', toggle_relay)
|
||||
server.add_route('/off', handle_relay_off)
|
||||
server.add_route('/on', handle_relay_on)
|
||||
server.add_route('/set_limit', set_humidity_limit, method="POST")
|
||||
@@ -217,8 +208,8 @@ def init_webserver():
|
||||
|
||||
def load_index_template():
|
||||
global index_template
|
||||
with open('index.html') as index_html:
|
||||
index_template = ''.join(index_html.readlines())
|
||||
with open('index.html') as index_html_file:
|
||||
index_template = ''.join(index_html_file.readlines())
|
||||
|
||||
def main():
|
||||
global server
|
||||
|
||||
Reference in New Issue
Block a user