Esempio n. 1
0
 def setVolumeLevel(self, volumeLevel):
     if self.PowerState() == 1:
         with eISCP(self.Host) as receiver:
             response = receiver.raw("MVL%s" % str(hex(volumeLevel))[2:])
             print("Response from setting volume level is: %s" % str(response))
             print(hex(volumeLevel))
             print("Volume level set to %s" % volumeLevel)
Esempio n. 2
0
 def PowerState(self):
     with eISCP(self.Host) as receiver:
         response = receiver.raw("PWRQSTN")
         if response == "PWR00":            
             return 0
         else:            
             return 1
Esempio n. 3
0
 def VolumeLevel(self):
     if self.PowerState() == 1:
         with eISCP(self.Host) as receiver:
             response = receiver.raw("MVLQSTN")
             decimalVolume = int(response[3:], 16)
             return decimalVolume
     else:
         return 0
Esempio n. 4
0
 def setPowerState(self, state):
     with eISCP(self.Host) as receiver:
         print("Setting Onkyo Power State to %s" % state)
         receiver.raw("PWR0%s" % state)
         
         time.sleep(5) # Give the receiver some time to wake up
         if state == 1:
             # Only change default volume if the current setting is Spotify/Network
             selectedInput = receiver.raw("SLIQSTN")
             print("Current selected input is %s" % selectedInput)
             if selectedInput == "SLI2B":    
                 print("Setting default volume level")
                 if(self.VolumeLevel() > self.DefaultMusicVolume):
                     self.setVolumeLevel(self.DefaultMusicVolume) #On start set the volume level to default        
Esempio n. 5
0
def messageHandler(internalid, content):
    if 'command' in content:
        avr = eISCP(
            str.split(internalid, ':', 2)[0],
            int(str.split(internalid, ':', 2)[1]))
        command = ''
        try:
            if content['command'] == 'on':
                command = 'system-power:on'
                avr.command(command)
            if content['command'] == 'off':
                command = 'system-power:standby'
                avr.command(command)
            if content['command'] == 'mute':
                command = 'audio-muting:on'
                avr.command(command)
            if content['command'] == 'unmute':
                command = 'audio-muting:off'
                avr.command(command)
            if content['command'] == 'mutetoggle':
                command = 'audio-muting:toggle'
                avr.command(command)
            if content['command'] == 'vol+':
                command = 'master-volume:level-up'
                avr.command(command)
            if content['command'] == 'vol-':
                command = 'master-volume:level-down'
                avr.command(command)
            if content['command'] == 'setlevel':
                if 'level' in content:
                    level = int(content['level'])
                    command = 'MVL%x' % level
                    # print "sending raw", command
                    avr.send_raw(command)
            if content['command'] == 'setinput':
                if 'input' in content:
                    command = 'input-selector:%s' % content['input']
                    avr.command(command)
        except ValueError, e:
            print e
Esempio n. 6
0
def messageHandler(internalid, content):
	if 'command' in content:
		avr = eISCP(str.split(internalid,':',2)[0], int(str.split(internalid,':',2)[1]))
		command = ''
		try:
			if content['command'] == 'on':
				command = 'system-power:on'
				avr.command(command)
			if content['command'] == 'off':
				command = 'system-power:standby'
				avr.command(command)
			if content['command'] == 'mute':
				command = 'audio-muting:on'
				avr.command(command)
			if content['command'] == 'unmute':
				command = 'audio-muting:off'
				avr.command(command)
			if content['command'] == 'mutetoggle':
				command = 'audio-muting:toggle'
				avr.command(command)
			if content['command'] == 'vol+':
				command = 'master-volume:level-up'
				avr.command(command)
			if content['command'] == 'vol-':
				command = 'master-volume:level-down'
				avr.command(command)
			if content['command'] == 'setlevel':
				if 'level' in content:
					level = int(content['level'])
					command = 'MVL%x' % level
					# print "sending raw", command
					avr.send_raw(command)
			if content['command'] == 'setinput':
				if 'input' in content:
					command = 'input-selector:%s' % content['input']
					avr.command(command)
		except ValueError, e:
			print e
Esempio n. 7
0
def main(argv=sys.argv):
    basename = os.path.basename(argv[0])
    options = docopt.docopt(__doc__, help=True)

    # List commands
    if options['--discover']:
        for receiver in eISCP.discover(timeout=1):
            print '%s %s:%s' % (receiver.info['model_name'], receiver.host,
                                receiver.port)
        return

    # List available commands
    if options['--help-commands']:
        # List the zones
        if not options['<zone>']:
            print 'Available zones:'
            for zone in commands.COMMANDS:
                print '  %s' % zone
            print 'Use %s --help-commands <zone> to see a list of '\
                  'commands for that zone.' % basename
            return
        # List the commands
        selected_zone = options['<zone>']
        if not selected_zone in commands.COMMANDS:
            print 'No such zone: %s' % selected_zone
            return 1
        if not options['<command>']:
            print 'Available commands for this zone:'
            for _, command in commands.COMMANDS[selected_zone].items():
                print '  %s - %s' % (command['name'], command['description'])
            print 'Use %s --help-commands %s <command> to see a list '\
                  'of possible values.' % (basename, selected_zone)
            return
        # List values
        selected_command = options['<command>'][0]
        selected_command = commands.COMMAND_MAPPINGS[selected_zone].get(
            selected_command, selected_command)
        if not selected_command in commands.COMMANDS[selected_zone]:
            print 'No such command in zone: %s' % selected_command
            return 1
        print 'Possible values for this command:'
        cmddata = commands.COMMANDS[selected_zone][selected_command]
        for range, value in cmddata['values'].items():
            print '  %s - %s' % (value['name'], value['description'])
        return

    # Determine the receivers the command should run on
    if options['--host']:
        receivers = [eISCP(options['--host'], int(options['--port']))]
    else:
        receivers = eISCP.discover(timeout=1)
        if not options['--all']:
            if options['--name']:
                receivers = [
                    r for r in receivers
                    if options['--name'] in r.info['model_name']
                ]
            else:
                receivers = receivers[:1]
        if not receivers:
            print 'No receivers found.'
            return 1

    # List of commands to execute - deal with special shortcut case
    to_execute = options['<command>']

    # Execute commands
    for receiver in receivers:
        with receiver:
            for command in to_execute:
                if command.isupper() and command.isalnum():
                    iscp_command = command
                    raw_response = True
                else:
                    try:
                        iscp_command = command_to_iscp(command)
                    except ValueError, e:
                        print 'Error:', e
                        return 2
                    raw_response = False

                print '%s: %s' % (receiver, iscp_command)
                response = receiver.raw(iscp_command)
                if not raw_response:
                    response = iscp_to_command(response)
                print response
Esempio n. 8
0
def main(argv=sys.argv):
    basename = os.path.basename(argv[0])
    options = docopt.docopt(__doc__, help=True)

    # List commands
    if options['--discover']:
        for receiver in eISCP.discover(timeout=1):
            print "%s %s:%s" % (
                receiver.info['model_name'], receiver.host, receiver.port)
        return

    # List available commands
    if options['--help-commands']:
        # List the zones
        if not options['<zone>']:
            print "Available zones:"
            for zone in commands.COMMANDS:
                print "  %s" % zone
            print "Use %s --help-commands <zone> to see a list of "\
                  "commands for that zone." % basename
            return
        # List the commands
        selected_zone = options['<zone>']
        if not selected_zone in commands.COMMANDS:
            print 'No such zone: %s' % selected_zone
            return 1
        if not options['<command>']:
            print 'Available commands for this zone:'
            for _, command in commands.COMMANDS[selected_zone].items():
                print "  %s - %s" % (command['name'], command['description'])
            print "Use %s --help-commands %s <command> to see a list "\
                  "of possible values." % (basename, selected_zone)
            return
        # List values
        selected_command = options['<command>'][0]
        selected_command = commands.COMMAND_MAPPINGS[selected_zone].get(
            selected_command, selected_command)
        if not selected_command in commands.COMMANDS[selected_zone]:
            print 'No such command in zone: %s' % selected_command
            return 1
        print 'Possible values for this command:'
        cmddata = commands.COMMANDS[selected_zone][selected_command]
        for range, value in cmddata['values'].items():
            print "  %s - %s" % (value['name'], value['description'])
        return

    # Determine the receivers the command should run on
    if options['--host']:
        receivers = [eISCP(options['--host'], int(options['--port']))]
    else:
        receivers = eISCP.discover(timeout=1)
        if not options['--all']:
            if options['--name']:
                receivers = [r for r in receivers
                             if options['--name'] in r.info['model_name']]
            else:
                receivers = receivers[:1]
        if not receivers:
            print "No receivers found."
            return 1

    # List of commands to execute - deal with special shortcut case
    to_execute = options['<command>']

    # Execute commands
    for receiver in receivers:
        with receiver:
            for command in to_execute:
                if command.isupper() and command.isalnum():
                    iscp_command = command
                    raw_response = True
                else:
                    try:
                        iscp_command = command_to_iscp(command)
                    except ValueError, e:
                        print "Error:", e
                        return 2
                    raw_response = False

                print '%s: %s' % (receiver, iscp_command)
                response = receiver.raw(iscp_command)
                if not raw_response:
                    response = iscp_to_command(response)
                print response