forked from zhelev/python-afsapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmi_async_tests.py
More file actions
114 lines (78 loc) · 2.82 KB
/
mi_async_tests.py
File metadata and controls
114 lines (78 loc) · 2.82 KB
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
"""Test of the asynchronous Frontier Silicon interface."""
import asyncio
import traceback
import logging
from afsapi import AFSAPI
URL = 'http://192.168.1.3:80/device'
PIN = 1234
TIMEOUT = 2 # in seconds
async def test_reads(api):
power = await api.get_power()
print('Power on: %s' % power)
end_point = await api.get_fsapi_endpoint()
print('Endpoint: %s' % end_point)
friendly_name = await api.get_friendly_name()
print('Friendly name: %s' % friendly_name)
modes = await api.get_modes()
print('Modes: %s' % modes)
mode_list = await api.get_mode_list()
print('Mode List: %s' % mode_list)
equalisers = await api.get_equalisers()
print('Equaliser: %s' % equalisers)
equaliser_list = await api.get_equaliser_list()
print('Equaliser List: %s' % equaliser_list)
mode = await api.get_mode()
print('Mode: %s' % mode)
sleep = await api.get_sleep()
print('Sleep: %s' % sleep)
volume = await api.get_volume()
print('Volume: %s' % volume)
volume_steps = await api.get_volume_steps()
print('Volume steps: % s' % volume_steps)
mute = await api.get_mute()
print('Is muted: %s' % mute)
name = await api.get_play_name()
print('Name: %s' % name)
text = await api.get_play_text()
print('Text: %s' % text)
artist = await api.get_play_artist()
print('Artist: %s' % artist)
album = await api.get_play_album()
print('Album: %s' % album)
graphic = await api.get_play_graphic()
print('Graphic: %s' % graphic)
position = await api.get_play_position()
print('Position: %s' % position)
duration = await api.get_play_duration()
print('Duration: %s' % duration)
status = await api.get_play_status()
print('Status: %s' % status)
async def test_with_read():
async with AFSAPI(URL, PIN, TIMEOUT) as api:
try:
await test_reads(api)
except Exception:
logging.error(traceback.format_exc())
async def test_finally_read():
try:
api = AFSAPI(URL, PIN, TIMEOUT)
await test_reads(api)
except Exception:
logging.error(traceback.format_exc())
finally:
await api.close()
async def test_set_play():
async with AFSAPI(URL, PIN, TIMEOUT) as api:
try:
status = await api.get_play_status()
print(f'Status: {status}')
forward = await api.forward()
print(f'Next succeeded? - {forward}')
await asyncio.sleep(5)
rewind = await api.rewind()
print(f'Prev succeeded? - {rewind}')
except Exception:
logging.error(traceback.format_exc())
asyncio.run(test_with_read())
#asyncio.run(test_finally_read())
#asyncio.run(test_set_play())