forked from reo-g/HIKIJOH
-
Notifications
You must be signed in to change notification settings - Fork 1
/
remo_api.py
50 lines (36 loc) · 1.37 KB
/
remo_api.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
import http.client
import os
import json
from prometheus_exporter import set_aircon_metrics
def aircon_on():
# 以下 REMO経由でACをつけるコード
conn = http.client.HTTPSConnection("api.nature.global")
payload = "button=power-on"
headers = {
'accept': "application/json",
'Content-Type': "application/x-www-form-urlencoded",
'Authorization': "Bearer " + os.environ["REMO_TOKEN"]
}
conn.request("POST", "/1/appliances/19c992ee-1bf3-4270-89a3-5f86ab7b9ad7/aircon_settings", payload, headers)
# conn.getresponse()
response = conn.getresponse()
aircon_state = json.loads(response.read().decode())
set_aircon_metrics(aircon_state)
return aircon_state
def aircon_off():
# 以下 REMO経由でACを落とすコード
conn = http.client.HTTPSConnection("api.nature.global")
payload = "button=power-off"
headers = {
'accept': "application/json",
'Content-Type': "application/x-www-form-urlencoded",
'Authorization': "Bearer " + os.environ["REMO_TOKEN"]
}
conn.request("POST", "/1/appliances/19c992ee-1bf3-4270-89a3-5f86ab7b9ad7/aircon_settings", payload, headers)
# conn.getresponse()
response = conn.getresponse()
aircon_state = json.loads(response.read().decode())
set_aircon_metrics(aircon_state)
return aircon_state
if __name__ == "__main__":
aircon_off()