From 0c5729d7c501e541429ef23eb1d7115f5aaebc3e Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 30 Apr 2019 23:56:55 +0100 Subject: [PATCH] added checking for phone --- alarm.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/alarm.py b/alarm.py index beb4ab8..583c300 100644 --- a/alarm.py +++ b/alarm.py @@ -3,10 +3,27 @@ import spotframework.net.network as networkclass import os +def checkPhone(): + + response = os.system("ping -c 1 -w5 " + os.environ['PHONEIP'] + " > /dev/null 2>&1") + print('checking for phone') + if response == 0: + return True + else: + return False + if __name__ == '__main__': network = networkclass.network(userclass.User()) - network.play(os.environ['SPOTALARMURI'], network.getDeviceID(os.environ['SPOTALARMDEVICENAME'])) + found = False - network.setShuffle(True) - network.next() + for i in range(0, 36): + if checkPhone(): + found = True + break + + if found: + network.play(os.environ['SPOTALARMURI'], network.getDeviceID(os.environ['SPOTALARMDEVICENAME'])) + + network.setShuffle(True) + network.next()