forked from bdraco/nexia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_mobile_phones.py
50 lines (40 loc) · 1.39 KB
/
delete_mobile_phones.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
#!/usr/bin/python3
"""Nexia Climate Device Access"""
import argparse
import asyncio
import pprint
import aiohttp
from nexia.const import BRAND_NEXIA
from nexia.home import NexiaHome
async def _runner(username, password, brand):
session = aiohttp.ClientSession()
try:
nexia_home = NexiaHome(
session, username=username, password=password, brand=brand
)
await nexia_home.login()
count = 0
for phone_id in await nexia_home.get_phone_ids():
count += 1
if count < 5:
continue
print("Delete phone id: ", phone_id)
response = await nexia_home.session.delete(
"https://www.mynexia.com/mobile/phones/" + str(phone_id),
headers=nexia_home._api_key_headers(),
)
pprint.pprint(response)
finally:
await session.close()
return nexia_home
parser = argparse.ArgumentParser()
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.username and args.password:
nexia_home = asyncio.run(_runner(args.username, args.password, brand))
else:
parser.print_help()
exit()