-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.py
172 lines (134 loc) · 7.44 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python
import argparse
import asyncio
import logging
import sys
from pyit600.exceptions import IT600AuthenticationError, IT600ConnectionError
from pyit600.gateway_singleton import IT600GatewaySingleton
def help():
print("pyit600 demo app")
print("syntax: main.py [options]")
print("options:")
print(" --host <gateway_ip> ... network address of your Salus UG600 universal gateway")
print(" --euid <gateway_euid> ... EUID which is specified on the bottom of your gateway")
print(" --debug ... use this if you want to print requests/responses")
print()
print("examples:")
print(" main.py --host 192.168.0.125 --euid 001E5E0D32906128 --debug")
async def my_climate_callback(device_id):
print("Got callback for climate device id: " + device_id)
async def my_sensor_callback(device_id):
print("Got callback for sensor device id: " + device_id)
async def my_switch_callback(device_id):
print("Got callback for switch device id: " + device_id)
async def my_cover_callback(device_id):
print("Got callback for cover device id: " + device_id)
async def main():
logging.basicConfig(level=logging.DEBUG)
parser = argparse.ArgumentParser(description="Commands: mode fan temp")
parser.add_argument(
"--host",
type=str,
dest="host",
help="network address of your Salus UG600 universal gateway",
metavar="HOST",
default=None,
)
parser.add_argument(
"--euid",
type=str,
dest="euid",
help="EUID which is specified on the bottom of your gateway",
metavar="EUID",
default=None,
)
parser.add_argument(
"--debug",
dest="debug",
help="Debug mode which prints requests/responses",
action="store_true",
)
args = parser.parse_args()
if (not args.host) or (not args.euid):
help()
sys.exit(0)
async with IT600GatewaySingleton.get_instance(host=args.host, euid=args.euid, debug=args.debug) as gateway:
try:
await gateway.connect()
except IT600ConnectionError:
print("Connection error: check if you have specified gateway's IP address correctly.", file=sys.stderr)
sys.exit(1)
except IT600AuthenticationError:
print("Authentication error: check if you have specified gateway's EUID correctly.", file=sys.stderr)
sys.exit(2)
await gateway.add_climate_update_callback(my_climate_callback)
await gateway.add_binary_sensor_update_callback(my_sensor_callback)
await gateway.add_switch_update_callback(my_switch_callback)
await gateway.add_cover_update_callback(my_cover_callback)
await gateway.poll_status(send_callback=True)
climate_devices = gateway.get_climate_devices()
if not climate_devices:
print(
"""Warning: no climate devices found. Ensure that you have paired your thermostat(s) with gateway and you can see it in the official Salus app. If it works there, your thermostat might not be supported. If you want to help to get it supported, open GitHub issue and add your thermostat model number and output of this program. Be sure to run this program with --debug option.\n""")
else:
print("All climate devices:")
print(repr(climate_devices))
for climate_device_id in climate_devices:
print(f"Climate device {climate_device_id} status:")
print(repr(climate_devices.get(climate_device_id)))
print(f"Setting heating device {climate_device_id} temperature to 21 degrees celsius")
await gateway.set_climate_device_temperature(climate_device_id, 21)
binary_sensor_devices = gateway.get_binary_sensor_devices()
if not binary_sensor_devices:
print(
"""Warning: no binary sensor devices found. Ensure that you have paired your binary sensor(s) with gateway and you can see it in the official Salus app. If it works there, your sensor might not be supported. If you want to help to get it supported, open GitHub issue and add your binary sensor model number and output of this program. Be sure to run this program with --debug option.\n""")
else:
print("All binary sensor devices:")
print(repr(binary_sensor_devices))
for binary_sensor_device_id in binary_sensor_devices:
print(f"Binary sensor device {binary_sensor_device_id} status:")
device = binary_sensor_devices.get(binary_sensor_device_id)
print(repr(device))
print(f"'{device.name}' is on: {device.is_on}")
switch_devices = gateway.get_switch_devices()
if not switch_devices:
print(
"""Warning: no switch devices found. Ensure that you have paired your switch(es) with gateway and you can see it in the official Salus app. If it works there, your switch might not be supported. If you want to help to get it supported, open GitHub issue and add your switch model number and output of this program. Be sure to run this program with --debug option.\n""")
else:
print("All switch devices:")
print(repr(switch_devices))
for switch_device_id in switch_devices:
print(f"Switch device {switch_device_id} status:")
device = switch_devices.get(switch_device_id)
print(repr(device))
print(f"Toggling device {switch_device_id}")
if device.is_on:
await gateway.turn_off_switch_device(switch_device_id)
else:
await gateway.turn_on_switch_device(switch_device_id)
cover_devices = gateway.get_cover_devices()
if not cover_devices:
print(
"""Warning: no cover devices found. Ensure that you have paired your cover(s) with gateway and you can see it in the official Salus app. If it works there, your cover might not be supported. If you want to help to get it supported, open GitHub issue and add your cover model number and output of this program. Be sure to run this program with --debug option.\n""")
else:
print("All cover devices:")
print(repr(cover_devices))
for sensor_device_id in cover_devices:
print(f"Switch device {sensor_device_id} status:")
device = switch_devices.get(sensor_device_id)
print(repr(device))
print(f"Setting {sensor_device_id} to 25%")
await gateway.set_cover_position(sensor_device_id, 25)
sensor_devices = gateway.get_sensor_devices()
if not sensor_devices:
print(
"""Warning: no sensor devices found. Ensure that you have paired your sensor(s) with gateway and you can see it in the official Salus app. If it works there, your cover might not be supported. If you want to help to get it supported, open GitHub issue and add your sensor model number and output of this program. Be sure to run this program with --debug option.\n""")
else:
print("All sensor devices:")
print(repr(sensor_devices))
for sensor_device_id in sensor_devices:
print(f"Sensor device {sensor_device_id} status:")
device = sensor_devices.get(sensor_device_id)
print(repr(device))
if __name__ == "__main__":
asyncio.run(main())