simulators package

Submodules

simulators.rotel_simulator module

class simulators.rotel_simulator.RA1572(host='0.0.0.0', port=9590)

Bases: object

Simulates a Rotel RA-1572 v2.65 and newer amplifier. Not all functions are implemented.

Command codes are based on the RS232/IP Protocol. Source.

Implemented functions are in the _COMMANDS and _REQUESTS attributes.

BAL_MAX = 15
BAL_MIN = -15
DIM_MAX = 6
DIM_MIN = 0
MSG_PATTERNS = {re.compile('^power(?:_(?P<arg>[a-z0-9\\-+]+))?!$'): 'power', re.compile('^vol(?:_(?P<arg>[a-z0-9\\-+]+))?!$'): 'volume', re.compile('^mute(?:_(?P<arg>[a-z0-9\\-+]+))?!$'): 'mute', re.compile('^rs232_update(?:_(?P<arg>[a-z0-9\\-+]+))?!$'): 'auto_update', re.compile('^(?P<arg>cd)!$'): 'source', re.compile('^(?P<arg>aux)!$'): 'source', re.compile('^(?P<arg>tuner)!$'): 'source', re.compile('^(?P<arg>phono)!$'): 'source', re.compile('^(?P<arg>bal_xlr)!$'): 'source', re.compile('^(?P<arg>coax1)!$'): 'source', re.compile('^(?P<arg>coax2)!$'): 'source', re.compile('^(?P<arg>opt1)!$'): 'source', re.compile('^(?P<arg>opt2)!$'): 'source', re.compile('^(?P<arg>usb)!$'): 'source', re.compile('^(?P<arg>bluetooth)!$'): 'source', re.compile('^(?P<arg>pcusb)!$'): 'source', re.compile('power\\?$'): 'power', re.compile('source\\?$'): 'source', re.compile('volume\\?$'): 'volume', re.compile('mute\\?$'): 'mute', re.compile('bypass\\?$'): 'bypass', re.compile('bass\\?$'): 'bass', re.compile('treble\\?$'): 'treble', re.compile('balance\\?$'): 'balance', re.compile('freq\\?$'): 'freq', re.compile('speaker\\?$'): 'speaker', re.compile('dimmer\\?$'): 'dimmer', re.compile('version\\?$'): 'version', re.compile('model\\?$'): 'model'}

This is a map of the form pattern: attribute. Whichever pattern matches indicates witch attribute to get/set.

Command patterns will match with an arg group. This may be None, e.g. in the case of mute!. Requests match without the arg group.

TONE_MAX = 10
TONE_MIN = 0
VOL_MAX = 96
VOL_MIN = 0
_COMMANDS = {'mute': 'mute', 'power': 'power', 'rs232_update': 'auto_update', 'vol': 'volume'}
_REQUESTS = {'balance': 'balance', 'bass': 'bass', 'bypass': 'bypass', 'dimmer': 'dimmer', 'freq': 'freq', 'model': 'model', 'mute': 'mute', 'power': 'power', 'source': 'source', 'speaker': 'speaker', 'treble': 'treble', 'version': 'version', 'volume': 'volume'}
_SOURCES = ['cd', 'aux', 'tuner', 'phono', 'bal_xlr', 'coax1', 'coax2', 'opt1', 'opt2', 'usb', 'bluetooth', 'pcusb']
auto_update

Whether the amp sends an update when the state changes.

Values are auto or manual.

Return type:str
handle_connection(reader, writer)
handle_message(msg)

Interprets the message received from the client.

There are two types of messages:

  1. Commands, aka setters. They end with a !
  2. Requests, aka getters. They end with a ?

If the command is a getter, the function always returns something or raises an exception. If the command is a setter, the function only returns if auto_update is True and if the function returns something.

The command is matched with a pattern. See the description of MSG_PATTERNS above for how this works.

msg

The message as received from the client.

Type:str
Returns:The reply of the command.
Return type:Optional[str]
Raises:ValueError – If the message is not understood for various reasons (unknown command, wrong termination, etc).
mute
power
source
start()
status()
stop()
volume

Module contents