-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_api.py
96 lines (76 loc) · 2.47 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
""" Pioneer AVR testing script. """
# pylint: disable=import-error,broad-except
import asyncio
import logging
import sys
import getopt
from aiopioneer import PioneerAVR
from aiopioneer.const import Zone, TunerBand
_LOGGER = logging.getLogger(__name__)
async def main(argv):
"""Main loop."""
_LOGGER.debug(">> main()")
host = ""
try:
opts, _ = getopt.getopt(argv, "h:", ["host="])
except getopt.GetoptError:
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--host"):
host = arg
if host == "":
_LOGGER.fatal("Host not specified.")
sys.exit(2)
pioneer = PioneerAVR(host)
try:
await pioneer.connect()
except Exception as exc:
print(f"Could not connect to AVR: {repr(exc)}")
return False
if await pioneer.query_device_model() is None:
print("AVR not responding to device model query")
return False
await pioneer.query_device_info()
print(
f"AVR device info: model={pioneer.properties.model}, "
+ f"mac_addr={pioneer.properties.mac_addr}, "
+ f"software_version={pioneer.properties.software_version}"
)
await pioneer.query_zones()
print(f"AVR zones discovered: {pioneer.properties.zones}")
print("Discovering zones")
await pioneer.build_source_dict()
await pioneer.update()
await asyncio.sleep(15)
## Turn on main zone for tests
await pioneer.turn_on(zone=Zone.Z1)
# await pioneer.select_source(source="TUNER", zone=Zone.Z1)
# await pioneer.set_tuner_frequency(band=TunerBand.AM, frequency=580)
await pioneer.set_dsp_settings(phase_control="off", zone=Zone.Z1)
# print("...")
# await pioneer.disconnect()
while True:
for prop, value in vars(pioneer.properties).items():
print(prop, ":", value)
await asyncio.sleep(60)
print("Update ...")
await pioneer.update()
# await pioneer.send_raw_request("?RGD", "RGD", ignore_error=True)
# print("...")
# await asyncio.sleep(5)
# print("...")
# await pioneer.update()
# print("...")
# await asyncio.sleep(5)
# print("...")
await pioneer.shutdown()
return True
if __name__ == "__main__":
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
rc = asyncio.run(main(sys.argv[1:])) ## pylint: disable=invalid-name
exit(0 if rc else 1)