mqtt_gateways.musiccast package

Module contents

Gateway to Yamaha MusicCast devices.

Submodules

mqtt_gateways.musiccast.musiccast2mqtt module

mqtt_gateways.musiccast.musiccast_interface module

mqtt_gateways.musiccast.musiccast_system module

mqtt_gateways.musiccast.musiccast_comm module

Low-level communication module with the MusicCast system.

Reviewed on 16 May 2018 by Paolo.

mqtt_gateways.musiccast.musiccast_comm.set_socket(listen_port)

Instantiates a socket and binds it to the port provided.

Also initialises the 2 module ‘constants’ MCSOCKET and MCPORT.

Parameters:listen_port (int) – the local port to bind to the socket.
Raises:CommsError – in case of failure to bind the socket to the port.
mqtt_gateways.musiccast.musiccast_comm.get_event()

Checks the socket for events broadcasted by the MusicCast devices.

TODO: check max length of the events and more than one event could arrive at once

The ‘body’ of the event (see below) is in the form: (‘{“main”:{“power”:”on”},”device_id”:”00A0DED57E83”}’, (‘192.168.1.44’, 38507)) or: (‘{“main”:{“volume”:88},”zone2”:{“volume”:0}, “device_id”:”00A0DED3FD57”}’, (‘192.168.1.42’, 46514))

class mqtt_gateways.musiccast.musiccast_comm.musiccastComm(host)

Bases: object

Manages the low-level calls to the MusicCast devices.

Every instance represents a single live connection to a given MusicCast device, represented simply by a host address.

Parameters:host (string) – the HTTP address for the host, as recognisable by the httplib library.
mcrequest(qualifier, mc_command)

Sends a single HTTP request and returns the response.

This method sends the request and read the response step by step in order to catch properly any error in the process. Currently the requests are always with method = ‘GET’ and version = ‘v1’.

Parameters:
  • qualifier (string) – the token in the MusicCast syntax representing either a zone or a source, depending on the type of command sent;
  • mc_command (string) – the command to send at the end of the request; it has to include any extra argument if there are any.
Raises:

commsError – in case of any form of Communication Error with the device.

Returns:

the dictionary equivalent of the JSON structure sent back as a reply

from the device.

Return type:

dictionary

mqtt_gateways.musiccast.musiccast_data module

Data for the MusicCast system.

mqtt_gateways.musiccast.musiccast_data.TRANSFORM_ARG = {'action': (<function <lambda> at 0x7f5cdf1b10c8>, <function <lambda> at 0x7f5cdf1b1140>), 'input': (<function <lambda> at 0x7f5cdf6ec410>, <function <lambda> at 0x7f5cdf6ec938>), 'mute': (<function <lambda> at 0x7f5cdf302b90>, <function <lambda> at 0x7f5cdf302c08>), 'power': (<function <lambda> at 0x7f5cdf302668>, <function <lambda> at 0x7f5cdf3021b8>), 'preset': (<function <lambda> at 0x7f5cdf1b11b8>, <function <lambda> at 0x7f5cdf1b1230>), 'source': (<function <lambda> at 0x7f5cdf6ec230>, <function <lambda> at 0x7f5cdf1b1050>), 'volume': (<function <lambda> at 0x7f5cdf302aa0>, <function <lambda> at 0x7f5cdf302c80>)}

Transforms arguments from internal keyword to MusicCast keyword and back.

The value for each key is a pair of lambdas; the first one transforms its arguments from internal representation to Musiccast, and the second one does the reverse. The lambdas have to be called by a Zone object.

mqtt_gateways.musiccast.musiccast_data.ACTIONS = {'CD_BACK': <function <lambda> at 0x7f5cdf1b1a28>, 'CD_FORWARD': <function <lambda> at 0x7f5cdf1b1aa0>, 'CD_PAUSE': <function <lambda> at 0x7f5cdf1b1b18>, 'CD_PLAY': <function <lambda> at 0x7f5cdf1b1b90>, 'CD_STOP': <function <lambda> at 0x7f5cdf1b1c08>, 'GET_INPUTS': <function <lambda> at 0x7f5cdf1b1668>, 'GET_SOURCES': <function <lambda> at 0x7f5cdf1b1758>, 'MUTE_OFF': <function <lambda> at 0x7f5cdf1b1578>, 'MUTE_ON': <function <lambda> at 0x7f5cdf1b1500>, 'MUTE_TOGGLE': <function <lambda> at 0x7f5cdf1b15f0>, 'NETRADIO_PRESET': <function <lambda> at 0x7f5cdf1b1e60>, 'POWER_OFF': <function <lambda> at 0x7f5cdf1b12a8>, 'POWER_ON': <function <lambda> at 0x7f5cdf1b1320>, 'SET_INPUT': <function <lambda> at 0x7f5cdf1b16e0>, 'SET_SOURCE': <function <lambda> at 0x7f5cdf1b17d0>, 'SET_VOLUME': <function <lambda> at 0x7f5cdf1b1398>, 'SOURCE_CD': <function <lambda> at 0x7f5cdf1b1848>, 'SOURCE_NETRADIO': <function <lambda> at 0x7f5cdf1b18c0>, 'SOURCE_SPOTIFY': <function <lambda> at 0x7f5cdf1b19b0>, 'SOURCE_TUNER': <function <lambda> at 0x7f5cdf1b1938>, 'SPOTIFY_BACK': <function <lambda> at 0x7f5cdf1b1cf8>, 'SPOTIFY_FORWARD': <function <lambda> at 0x7f5cdf1b1d70>, 'SPOTIFY_PLAYPAUSE': <function <lambda> at 0x7f5cdf1b1c80>, 'TUNER_PRESET': <function <lambda> at 0x7f5cdf1b1de8>, 'VOLUME_DOWN': <function <lambda> at 0x7f5cdf1b1488>, 'VOLUME_UP': <function <lambda> at 0x7f5cdf1b1410>}

The dictionary with all the data to process the various commands.

It has to be called from an instance of the class Zone.

mqtt_gateways.musiccast.musiccast_data.EVENTS = {'cd': {'play_info_updated': <function <lambda> at 0x7f5cdf1b2758>, 'play_time': <function <lambda> at 0x7f5cdf1b26e0>, 'device_status': None}, 'clock': {'settings_updated': None}, 'device_id': None, 'dist': {'dist_info_updated': None}, 'main': {'power': <function <lambda> at 0x7f5cdf1b1ed8>, 'mute': <function <lambda> at 0x7f5cdf1b20c8>, 'status_updated': <function <lambda> at 0x7f5cdf1b2140>, 'volume': <function <lambda> at 0x7f5cdf1b2050>, 'input': <function <lambda> at 0x7f5cdf1b1f50>, 'signal_info_updated': None}, 'netusb': {'trial_time_left': None, 'play_error': None, 'list_info_updated': None, 'trial_status': None, 'preset_control': None, 'recent_info_updated': None, 'preset_info_updated': <function <lambda> at 0x7f5cdf1b25f0>, 'play_info_updated': <function <lambda> at 0x7f5cdf1b2668>, 'multiple_play_errors': None, 'account_updated': None, 'play_time': <function <lambda> at 0x7f5cdf1b2578>, 'play_message': <function <lambda> at 0x7f5cdf1b2500>}, 'system': {'speaker_settings_updated': None, 'stereo_pair_info_updated': None, 'name_text_updated': None, 'location_info_updated': None, 'tag_updated': None, 'bluetooth_info_updated': None, 'func_status_updated': None}, 'tuner': {'play_info_updated': <function <lambda> at 0x7f5cdf1b2410>, 'preset_info_updated': <function <lambda> at 0x7f5cdf1b2488>}, 'zone2': {'power': <function <lambda> at 0x7f5cdf1b21b8>, 'mute': <function <lambda> at 0x7f5cdf1b2320>, 'status_updated': <function <lambda> at 0x7f5cdf1b2398>, 'volume': <function <lambda> at 0x7f5cdf1b22a8>, 'input': <function <lambda> at 0x7f5cdf1b2230>, 'signal_info_updated': None}, 'zone3': {}, 'zone4': {}}

Dictionary to decode incoming events.