-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_api.py
72 lines (56 loc) · 2.23 KB
/
test_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import asyncio
import aiohttp
import argparse
import sys
import logging
from custom_components.bayrol_cloud.client.bayrol_api import BayrolPoolAPI
# Set up logging
logging.basicConfig(level=logging.DEBUG)
_LOGGER = logging.getLogger(__name__)
async def test_bayrol_api(username: str, password: str):
"""Test Bayrol Pool Access API authentication and data fetching."""
async with aiohttp.ClientSession() as session:
# Initialize API with credentials
api = BayrolPoolAPI(session, username, password)
# Test login
print("\nTesting login...")
if not await api.login():
print("❌ Login failed")
return False
print("✅ Login successful")
# Get list of controllers
print("\nDiscovering controllers...")
controllers = await api.get_controllers()
if not controllers:
print("❌ No controllers found")
return False
print(f"✅ Found {len(controllers)} controller(s)")
# Test data fetch for each controller
for controller in controllers:
print(f"\nTesting controller: {controller['name']} (CID: {controller['cid']})...")
data = await api.get_data(controller['cid'])
if not data:
print("❌ No data found")
continue
print("✅ Data fetch successful")
print("\nCurrent values:")
for key, value in data.items():
print(f" {key}: {value}")
return True
def main():
parser = argparse.ArgumentParser(description='Test Bayrol Pool Access API')
parser.add_argument('--username', required=True, help='Bayrol Pool Access username')
parser.add_argument('--password', required=True, help='Bayrol Pool Access password')
args = parser.parse_args()
print("Testing Bayrol Pool Access API connection...")
print(f"Username: {args.username}")
result = asyncio.run(test_bayrol_api(args.username, args.password))
if not result:
print("\n❌ API test failed")
sys.exit(1)
else:
print("\n✅ API test successful")
sys.exit(0)
if __name__ == "__main__":
main()