-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbulb.py
67 lines (46 loc) · 1.73 KB
/
bulb.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import requests
from dotenv import load_dotenv
import os
load_dotenv()
def set_bulb_color(h, s, v):
ip = os.getenv("raspi_ip")
object_id_bulb = os.getenv("object_id_bulb")
if ip is None:
raise RuntimeError("Undefined environment variable `raspi_ip`")
if object_id_bulb is None:
raise RuntimeError("Undefined environment variable `object_id_bulb`")
url = 'http://' + ip + ":9997/agent/remote/objects/" + object_id_bulb + "/properties/Bulb2_Color"
headers = {
'Content-Type': 'application/json',
'infrastructure-id': 'VAS',
'adapter-id': 'HackathonSampleService'
}
data = "{value:'" + str(h) + "," + str(s) + "," + str(v) + "'}"
r = requests.put(url=url, data=data, headers=headers)
def flash_bulb_color():
"""
Flashes the current color. Set the color with `set_bulb_color`.
"""
ip = os.getenv("raspi_ip")
object_id_bulb = os.getenv("object_id_bulb")
if ip is None:
raise RuntimeError("Undefined environment variable `raspi_ip`")
if object_id_bulb is None:
raise RuntimeError("Undefined environment variable `object_id_bulb`")
url = 'http://' + ip + ":9997/agent/remote/objects/" + object_id_bulb + "/properties/Bulb2_Alert"
headers = {
'Content-Type': 'application/json',
'infrastructure-id': 'VAS',
'adapter-id': 'HackathonSampleService'
}
data = "{value:'LSELECT'}"
r = requests.put(url=url, data=data, headers=headers)
def bulb_set_disabled_status():
set_bulb_color(0.6*255, 0, 0)
def bulb_set_parcel_status():
set_bulb_color(0.6*255, 100, 50)
flash_bulb_color()
def bulb_set_security_status():
set_bulb_color(0, 100, 10)
flash_bulb_color()