forked from bdraco/nexia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (68 loc) · 2.82 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
#!/usr/bin/python3
"""Nexia Climate Device Access"""
import argparse
import code
import readline
import rlcompleter
import aiohttp
import asyncio
import logging
from nexia.const import BRAND_NEXIA
from nexia.home import NexiaHome
parser = argparse.ArgumentParser()
parser.add_argument("--debug", action="store_const", const=True, help="Enable debug.")
parser.add_argument("--brand", type=str, help="Brand (nexia or asair or trane).")
parser.add_argument("--username", type=str, help="Your Nexia username/email address.")
parser.add_argument("--password", type=str, help="Your Nexia password.")
args = parser.parse_args()
brand = args.brand or BRAND_NEXIA
if args.debug:
logging.basicConfig(level=logging.DEBUG)
async def _runner(username, password, brand):
session = aiohttp.ClientSession()
try:
nexia_home = NexiaHome(session, username=username, password=password, brand=brand)
await nexia_home.login()
await nexia_home.update()
finally:
await session.close()
return nexia_home
if args.username and args.password:
nexia_home = asyncio.run(_runner(args.username, args.password, brand))
else:
parser.print_help()
exit()
variables = globals()
print("NexiaThermostat instance can be referenced using t_{id}.<command>.")
print("Room IQ instance can be referenced using i_{id}.<command>.")
print("Zone instance can be referenced using z_{id}.<command>.")
print("List of available thermostats and zones:")
for _thermostat_id in nexia_home.get_thermostat_ids():
thermostat = nexia_home.get_thermostat_by_id(_thermostat_id)
_thermostat_name = thermostat.get_name()
_thermostat_model = thermostat.get_model()
_thermostat_compressor_speed = thermostat.get_current_compressor_speed()
variables[f"t_{_thermostat_id}"] = thermostat
print(
f't_{_thermostat_id} - "{_thermostat_name}" ({_thermostat_model}) [{_thermostat_compressor_speed}]'
)
print(" Room IQs:")
for _room_iq_id in thermostat.get_room_iq_ids():
iq = thermostat.get_room_iq_by_id(_room_iq_id)
_iq_name = iq.get_name()
_iq_weight = iq.get_weight()
_iq_temp = iq.get_temperature()
_iq_hum = iq.get_humidity()
_iq_batt = iq.get_battery_level()
variables[f"i_{_room_iq_id}"] = iq
print(f' i_{_room_iq_id} - "{_iq_name}" ({_iq_weight}) temp={_iq_temp} hum={_iq_hum} batt={_iq_batt}')
print(" Zones:")
for _zone_id in thermostat.get_zone_ids():
zone = thermostat.get_zone_by_id(_zone_id)
_zone_name = zone.get_name()
_zone_status = zone.get_status()
variables[f"z_{_zone_id}"] = zone
print(f' z_{_zone_id} - "{_zone_name}" ({_zone_status})')
readline.set_completer(rlcompleter.Completer(variables).complete)
readline.parse_and_bind("tab: complete")
code.InteractiveConsole(variables).interact()