Commit dab76903 authored by Tom Kunze's avatar Tom Kunze
Browse files

server: Check provided temperatures for validity

Temperatures should be floats otherwise fail.
parent 3c98ba91
......@@ -321,13 +321,17 @@ def _get_temperatures():
if room.temp_hosts == '':
temperatures[room.name] = 'N/A'
else:
temps = []
for thost in room.temp_hosts.split(','):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect((thost + '.cs.fau.de', 16842))
temps.append(s.recv(1024).decode().strip())
temperatures[room.name] = '/'.join(temps)
try:
temps = []
for thost in room.temp_hosts.split(','):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect((thost + '.cs.fau.de', 16842))
temps.append(round(float(s.recv(1024).decode().strip()), 1))
temperatures[room.name] = '/'.join([str(x) for x in temps])
except Exception as e:
temperatures[room.name] = 'N/A'
cache.set('temp_' + room.name, temperatures[room.name], 10)
return temperatures
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment