-
Notifications
You must be signed in to change notification settings - Fork 0
/
adrian.py
34 lines (28 loc) · 872 Bytes
/
adrian.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import IOT
import random
import time
IOT.initialize()
def isAdrianAround():
return len(IOT.selectWithName("Nexus 5-A")) == 1
def adrianDis():
return int(IOT.selectWithName("Nexus 5-A")[0]._rssi)
def notify(devices):
for device in devices:
if "speaker" in device._type:
device.speak("Adrian is around you!!!")
if "lights" in device._type:
device.setLights("true", str(random.randint(0, 255)), str(random.randint(0, 255)), str(random.randint(0, 255)))
def notifyMe(urgent):
if urgent:
notify(IOT.selectAll())
else:
notify(IOT.selectNearest())
while True:
if isAdrianAround():
print("Adrian is around ", adrianDis())
if isAdrianAround() and adrianDis() > -75:
if adrianDis() > -65:
notifyMe(True)
else:
notifyMe(False)
time.sleep(2)