-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·86 lines (75 loc) · 4.19 KB
/
example.py
File metadata and controls
executable file
·86 lines (75 loc) · 4.19 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from LegrandBiticinoAPI import LegrandBiticinoAPI
import pprint as pp
import datetime
API = LegrandBiticinoAPI()
# Test the API using and echo endpoint as per documentation
# https://portal.developer.legrand.com/docs/services/echo-api/operations/create-resource
out = API.echo()
if out['status_code'] == 200:
print("It works fine!")
else:
raise SystemExit("ERROR: " + str(out['status_code']))
# Plants - Operation used to retrieve all the plants associated to a user.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Plants
plants = API.get_plants()
plantId = plants['text']['plants'][0]['id']
print("plantId = " + str(plantId))
# Topology - Operation used to retrieve the complete topology of a plant.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Topology
modules = API.get_topology(plantId)
moduleId = modules['text']['plant']['modules'][0]['id']
print("moduleId = " + str(moduleId))
# Chronothermostat Measures - Operation used to retrieve the measured temperature and humidity detected by a chronothermostat.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Chronothermostat-Measures
out = API.get_chronothermostat_measures(plantId, moduleId)
if out['status_code'] == 200:
print('Chronothermostat measures = ')
pp.pprint(out['text'])
else:
raise SystemExit("ERROR -> " + str(out))
# Chronothermostat ProgramList - Operation used to retrieve the list of programs managed by a chronothermostat.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Chronothermostat-ProgramList
out = API.get_chronothermostat_programlist(plantId, moduleId)
if out['status_code'] == 200:
print('Chronothermostat programlist = ')
pp.pprint(out['text'])
else:
raise SystemExit("ERROR -> " + str(out))
# Get Chronothermostat Status - Operation used to retrieve the complete status of a chronothermostat.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Get-Chronothermostat-Status
status = API.get_chronothermostat_status(plantId, moduleId)
if out['status_code'] == 200:
print('Chronothermostat status = ')
pp.pprint(status['text'])
else:
raise SystemExit("ERROR -> " + str(status))
# As example, we want to set to AUTOMATIC if a temeprature is manually defined
if status['text']['chronothermostats'][0]['mode'] != 'AUTOMATIC':
print("setPoint = " + status['text']['chronothermostats'][0]['setPoint']['value'] + "\n")
data = {
"function": "heating", "mode": "AUTOMATIC",
"setPoint": { "value": "18.20000", "unit": "C" },
"programs": [ { "number": 1 }],
"activationTime": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
}
# Set Chronothermostat Status - Operation used to set the status of a chronothermostat.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Set-Chronothermostat-Status
out = API.set_chronothermostat_status(plantId, moduleId, data)
print(str(out) + "\n")
# Get subscriptions to C2C notifications - Operation used to get subscriptions of a user to get Cloud2Cloud notifications of a plant.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Get-subscriptions-to-C2C-notifications
subscriptions = API.get_subscriptions_C2C_notifications()
if subscriptions['status_code'] == 204:
print("No subscription associated with this user")
elif subscriptions['status_code'] == 200:
pp.pprint(subscriptions['text'])
# Subscribe to C2C notifications - Operation used to subscribe a user to get Cloud2Cloud notifications of a plant.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Subscribe-to-C2C-notifications
data = {"EndPointUrl": "http://www.example.com"}
out = API.set_subscribe_C2C_notifications(plantId, data)
print(str(out['status_code']) + " " + out['text'])
# Delete subscription to C2C notifications - Operation used to delete the subscription of a user to get Cloud2Cloud notifications of a plant.
# https://portal.developer.legrand.com/docs/services/smartherV2/operations/Delete-subscription-to-C2C-notifications
subscriptionId = '123'
out = API.delete_subscribe_C2C_notifications(plantId, subscriptionId)
print(str(out['status_code']) + " " + out['text'])