-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_devices.py
More file actions
181 lines (157 loc) · 7.1 KB
/
test_devices.py
File metadata and controls
181 lines (157 loc) · 7.1 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import asyncio
import logging
from heos_mdns import send_heos_command
import json
# Set up logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# Test device configuration
TEST_DEVICE = {
'name': 'Denon Home 150',
'ip': '192.168.41.140',
'did': '3C424E4F8CA96F0546E1', # Device ID
'version': '3.34.425',
'model': 'Denon Home 150',
'network': 'dc2c6e43f901'
}
class HeosCommandTester:
def __init__(self, device_ip):
self.ip = device_ip
async def initialize_device(self):
"""Initialize HEOS device with required setup."""
try:
# Register for change events
await send_heos_command(self.ip, 'system/register_for_change_events', {'enable': 'on'})
return True
except Exception as e:
logger.error(f'Error initializing device: {e}')
return False
async def test_system_commands(self):
"""Test HEOS System Commands"""
print("\n=== Testing System Commands ===")
commands = [
('system/heart_beat', {}),
('system/check_account', {}),
('system/sign_in', {'un': 'YOUR_USERNAME', 'pw': 'YOUR_PASSWORD'}),
('system/sign_out', {}),
('system/register_for_change_events', {'enable': 'on'}),
('system/prettify_json_response', {'enable': 'on'})
]
for cmd, params in commands:
try:
print(f"\nTesting: {cmd}")
result = await send_heos_command(self.ip, cmd, params)
print(f"Result: {json.dumps(result, indent=2)}")
except Exception as e:
logger.error(f'Error testing {cmd}: {e}')
async def test_player_commands(self):
"""Test HEOS Player Commands"""
print("\n=== Testing Player Commands ===")
# Basic playback commands
playback_commands = [
('player/get_players', {}),
('player/get_play_state', {'pid': TEST_DEVICE['did']}),
('player/set_play_state', {'pid': TEST_DEVICE['did'], 'state': 'play'}),
('player/get_now_playing_media', {'pid': TEST_DEVICE['did']}),
('player/get_volume', {'pid': TEST_DEVICE['did']}),
('player/set_volume', {'pid': TEST_DEVICE['did'], 'level': '25'}),
('player/volume_up', {'pid': TEST_DEVICE['did'], 'step': '5'}),
('player/volume_down', {'pid': TEST_DEVICE['did'], 'step': '5'}),
('player/get_mute', {'pid': TEST_DEVICE['did']}),
('player/set_mute', {'pid': TEST_DEVICE['did'], 'state': 'on'}),
('player/toggle_mute', {'pid': TEST_DEVICE['did']}),
('player/get_play_mode', {'pid': TEST_DEVICE['did']}),
('player/set_play_mode', {'pid': TEST_DEVICE['did'], 'repeat': 'on_all', 'shuffle': 'on'})
]
for cmd, params in playback_commands:
try:
print(f"\nTesting: {cmd}")
result = await send_heos_command(self.ip, cmd, params)
print(f"Result: {json.dumps(result, indent=2)}")
await asyncio.sleep(1) # Add delay between commands
except Exception as e:
logger.error(f'Error testing {cmd}: {e}')
async def test_group_commands(self):
"""Test HEOS Group Commands"""
print("\n=== Testing Group Commands ===")
commands = [
('group/get_groups', {}),
('group/get_group_volume', {'gid': '1'}),
('group/set_group_volume', {'gid': '1', 'level': '25'}),
('group/volume_up', {'gid': '1', 'step': '5'}),
('group/volume_down', {'gid': '1', 'step': '5'}),
('group/get_group_mute', {'gid': '1'}),
('group/set_group_mute', {'gid': '1', 'state': 'on'}),
('group/toggle_group_mute', {'gid': '1'})
]
for cmd, params in commands:
try:
print(f"\nTesting: {cmd}")
result = await send_heos_command(self.ip, cmd, params)
print(f"Result: {json.dumps(result, indent=2)}")
except Exception as e:
logger.error(f'Error testing {cmd}: {e}')
async def test_browse_commands(self):
"""Test HEOS Browse Commands"""
print("\n=== Testing Browse Commands ===")
commands = [
('browse/get_music_sources', {}),
('browse/get_source_info', {'sid': '1'}),
('browse/browse', {'sid': '1'}),
('browse/browse_source', {'sid': '1'}),
('browse/play_station', {'pid': TEST_DEVICE['did'], 'sid': '1', 'cid': '1', 'mid': '1'}),
('browse/play_preset', {'pid': TEST_DEVICE['did'], 'preset': '1'}),
('browse/play_input', {'pid': TEST_DEVICE['did'], 'input': 'aux_in_1'}),
('browse/add_to_queue', {'pid': TEST_DEVICE['did'], 'sid': '1', 'cid': '1', 'aid': '1', 'mid': '1'})
]
for cmd, params in commands:
try:
print(f"\nTesting: {cmd}")
result = await send_heos_command(self.ip, cmd, params)
print(f"Result: {json.dumps(result, indent=2)}")
except Exception as e:
logger.error(f'Error testing {cmd}: {e}')
async def test_queue_commands(self):
"""Test HEOS Queue Commands"""
print("\n=== Testing Queue Commands ===")
commands = [
('player/get_queue', {'pid': TEST_DEVICE['did']}),
('player/play_queue', {'pid': TEST_DEVICE['did'], 'qid': '1'}),
('player/remove_from_queue', {'pid': TEST_DEVICE['did'], 'qid': '1'}),
('player/save_queue', {'pid': TEST_DEVICE['did'], 'name': 'My Playlist'}),
('player/clear_queue', {'pid': TEST_DEVICE['did']}),
('player/move_queue_item', {'pid': TEST_DEVICE['did'], 'sqid': '1', 'dqid': '2'}),
('player/play_next', {'pid': TEST_DEVICE['did']}),
('player/play_previous', {'pid': TEST_DEVICE['did']})
]
for cmd, params in commands:
try:
print(f"\nTesting: {cmd}")
result = await send_heos_command(self.ip, cmd, params)
print(f"Result: {json.dumps(result, indent=2)}")
except Exception as e:
logger.error(f'Error testing {cmd}: {e}')
async def main():
"""Main test function"""
tester = HeosCommandTester(TEST_DEVICE['ip'])
# Initialize device
if not await tester.initialize_device():
logger.error("Failed to initialize device")
return
# Run all tests
test_functions = [
tester.test_system_commands,
tester.test_player_commands,
tester.test_group_commands,
tester.test_browse_commands,
tester.test_queue_commands
]
for test_func in test_functions:
try:
await test_func()
await asyncio.sleep(2) # Add delay between test categories
except Exception as e:
logger.error(f'Error in {test_func.__name__}: {e}')
if __name__ == '__main__':
# Run the test suite
asyncio.run(main())