aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-04-11 12:05:33 +0200
committerMattias Andrée <maandree@operamail.com>2014-04-11 12:05:33 +0200
commit7b7205df5214f70131ef89bfee3d4c90cc64e2be (patch)
tree03c092fcca43def9c6a53c76ab224f9324a260dc
parentfix bugs (diff)
downloadnightshift-7b7205df5214f70131ef89bfee3d4c90cc64e2be.tar.gz
nightshift-7b7205df5214f70131ef89bfee3d4c90cc64e2be.tar.bz2
nightshift-7b7205df5214f70131ef89bfee3d4c90cc64e2be.tar.xz
split generate_status_message from use_client
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rwxr-xr-xsrc/nightshift.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/nightshift.py b/src/nightshift.py
index ba873ec..b3d8a91 100755
--- a/src/nightshift.py
+++ b/src/nightshift.py
@@ -322,6 +322,26 @@ def read_status(proc, sock):
sock.shutdown(socket.SHUT_RDWR)
+def generate_status_message():
+ '''
+ Generate message to send to the client to inform about the status
+
+ @return :str Status message
+ '''
+ message = 'Current brightness: %f\n' % red_brightness
+ message += 'Daytime brightness: %f\n' % red_brightnesses[0]
+ message += 'Night brightness: %f\n' % red_brightnesses[1]
+ message += 'Current temperature: %f\n' % red_temperature
+ message += 'Daytime temperature: %f\n' % red_temperatures[0]
+ message += 'Night temperature: %f\n' % red_temperatures[1]
+ message += 'Dayness: %f\n' % red_period
+ message += 'Latitude: %f\n' % red_location[0]
+ message += 'Longitude: %f\n' % red_location[1]
+ message += 'Enabled: %s\n' % ('yes' if red_status else 'no')
+ message += 'Running: %s\n' % ('yes' if red_running else 'no')
+ return message
+
+
def use_client(sock, proc):
'''
Communication with client
@@ -344,17 +364,7 @@ def use_client(sock, proc):
message, buf = buf[0], '\n'.join(buf[1:])
if message == 'status':
red_condition.acquire()
- message = 'Current brightness: %f\n' % red_brightness
- message += 'Daytime brightness: %f\n' % red_brightnesses[0]
- message += 'Night brightness: %f\n' % red_brightnesses[1]
- message += 'Current temperature: %f\n' % red_temperature
- message += 'Daytime temperature: %f\n' % red_temperatures[0]
- message += 'Night temperature: %f\n' % red_temperatures[1]
- message += 'Dayness: %f\n' % red_period
- message += 'Latitude: %f\n' % red_location[0]
- message += 'Longitude: %f\n' % red_location[1]
- message += 'Enabled: %s\n' % ('yes' if red_status else 'no')
- message += 'Running: %s\n' % ('yes' if red_running else 'no')
+ message = generate_status_message()
sock.sendall((message + '\n').encode('utf-8'))
red_condition.release()
elif message == 'toggle':