def onMQTTMsg(client,userdate,msg): print('MQTTMsg: ####' ) payload = msg.payload.decode("utf-8") topic = msg.topic.split('/') print(topic, payload) server = juice.connect('euterpe3', 9090) players = juice.get_players(server) for player in players: print(player) if player['name'] == topic[-1]: juice.pause(server, player['id']) break; server.close()
def test_multiple_players(self): with patch('juice.players.get_player_count', return_value=3), \ patch('juice.players.get_player_name', side_effect=['Lounge','Kitchen','Dining Room']), \ patch('juice.players.get_player_id', side_effect=['00:12:34:56:78:90','01:12:34:56:78:90', '02:12:34:56:78:90']): self.assertEqual([{ 'index': 0, 'name': 'Lounge', 'id': '00:12:34:56:78:90' }, { 'index': 1, 'name': 'Kitchen', 'id': '01:12:34:56:78:90' }, { 'index': 2, 'name': 'Dining Room', 'id': '02:12:34:56:78:90' }], get_players(None))
def players(): server = connect(app.config['SERVER']) players = get_players(server) server.close() return jsonify(players)
'album': track.get('album', None), 'album_id': track.get('album_id', None), 'artist': track.get('artist', None), 'artist_id': track.get('artist_id', None), 'title': player.get('current_title', None), 'volume': player['volume'], 'playlist': player['playlist'], 'playlist_cur_index': player.get('playlist_cur_index', None) } last_status[player['name']] = status client.publish('squeezebox/players/' + player['name'], json.dumps(status), retain=True, qos=1) client.publish('squeezebox/display/' + player['name'], '{}\t{}\t{}'.format(track.get('title','---'), track.get('artist','---'), track.get('album','---')).encode('ascii','ignore'), retain=True, qos=1) if __name__ == '__main__': client = mqtt.Client('juice-bridge') client.connect('euterpe3') client.on_message = onMQTTMsg #client.on_log = lambda client,ussrdata,level,buf: print("log:",level,buf) client.loop_start() client.subscribe("squeezebox/command/#") server = juice.connect('euterpe3', 9090) players = juice.get_players(server) for player in players: server.write(msg_format.player_status(player['id'], subscribe=0, start=0, page_size=9999).encode('ascii')) juice.loop_start(server, onSBMsg)
def test_no_players(self): with patch('juice.players.get_player_count', return_value=0): self.assertEqual([], get_players(None))