-
Notifications
You must be signed in to change notification settings - Fork 6
/
async_tests.py
144 lines (102 loc) · 4.19 KB
/
async_tests.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
"""Test of the asynchronous Frontier Silicon interface."""
import asyncio
import traceback
import logging
from afsapi import AFSAPI
URL = "http://192.168.1.183:80/device"
PIN = 1234
TIMEOUT = 2 # in seconds
async def test_sys() -> None:
"""Test sys functions."""
try:
afsapi = await AFSAPI.create(URL, PIN, TIMEOUT)
print(f"Set power succeeded? - {await afsapi.set_power(True)}")
print(f"Power on: {await afsapi.get_power()}")
print(f"Friendly name: {await afsapi.get_friendly_name()}")
for mode in await afsapi.get_modes():
print(f"Available Mode: {mode}")
print(f"Current Mode: {await afsapi.get_mode()}")
for equaliser in await afsapi.get_equalisers():
print(f"Equaliser: {equaliser}")
print(f"EQ Preset: {await afsapi.get_eq_preset()}")
for preset in await afsapi.get_presets():
print(f"Preset: {preset}")
print(f"Set power succeeded? - {await afsapi.set_power(False)}")
print(f"Set sleep succeeded? - {await afsapi.set_sleep(10)}")
print(f"Sleep: {await afsapi.get_sleep()}")
print(f"Get power {await afsapi.get_power()}")
except Exception:
logging.error(traceback.format_exc())
async def test_volume() -> None:
"""Test volume functions."""
try:
afsapi = await AFSAPI.create(URL, PIN, TIMEOUT)
set_power = await afsapi.set_power(True)
print("Set power succeeded? - %s" % set_power)
power = await afsapi.get_power()
print("Power on: %s" % power)
volume = await afsapi.get_volume()
print("Volume: %s" % volume)
set_volume = await afsapi.set_volume(3)
print("Set volume succeeded? - %s" % set_volume)
volume_steps = await afsapi.get_volume_steps()
print("Volume steps: % s" % volume_steps)
mute = await afsapi.get_mute()
print("Is muted: %s" % mute)
power = await afsapi.set_power(False)
print("Set power succeeded? - %s" % set_power)
power = await afsapi.get_power()
print("Power on: %s" % power)
except Exception:
logging.error(traceback.format_exc())
async def test_info() -> None:
"""Test info functions."""
try:
afsapi = await AFSAPI.create(URL, PIN, TIMEOUT)
set_power = await afsapi.set_power(True)
print("Set power succeeded? - %s" % set_power)
power = await afsapi.get_power()
print("Power on: %s" % power)
print(f"Radio ID: {await afsapi.get_radio_id()}")
print(f"Version: {await afsapi.get_version()}")
print(f"MAC: {await afsapi.get_mac()}")
print(f"RSSI: {await afsapi.get_rssi()} dBm")
name = await afsapi.get_play_name()
print("Name: %s" % name)
text = await afsapi.get_play_text()
print("Text: %s" % text)
artist = await afsapi.get_play_artist()
print("Artist: %s" % artist)
album = await afsapi.get_play_album()
print("Album: %s" % album)
graphic = await afsapi.get_play_graphic()
print("Graphic: %s" % graphic)
duration = await afsapi.get_play_duration()
print("Duration: %s" % duration)
# power = await afsapi.set_power(False)
# print('Set power succeeded? - %s' % set_power)
# power = await afsapi.get_power()
# print('Power on: %s' % power)
except Exception:
logging.error(traceback.format_exc())
async def test_play() -> None:
"""Test play functions."""
try:
afsapi = await AFSAPI.create(URL, PIN, TIMEOUT)
status = await afsapi.get_play_status()
print("Status: %s" % status)
start_play = await afsapi.play()
print("Start play succeeded? - %s" % start_play)
await asyncio.sleep(1)
forward = await afsapi.forward()
print("Next succeeded? - %s" % forward)
await asyncio.sleep(1)
rewind = await afsapi.rewind()
print("Prev succeeded? - %s" % rewind)
except Exception:
logging.error(traceback.format_exc())
loop = asyncio.new_event_loop()
loop.run_until_complete(test_sys())
loop.run_until_complete(test_volume())
loop.run_until_complete(test_play())
loop.run_until_complete(test_info())