def process_result(self, commandName, command, result): if len(result['output']) == 0: return resultBuf = result['output'].encode() results = [] while len(resultBuf) > 0: try: (_, _, responseLen, _) = OnkyoAVR.ISCP_HEADER.unpack( resultBuf[:OnkyoAVR.ISCP_HEADER.size]) # strip first 2 chars last 3 chars for \x1a\r\n results.append(resultBuf[OnkyoAVR.ISCP_HEADER.size + len(OnkyoAVR.DESTINATION_UNIT_TYPE ):OnkyoAVR.ISCP_HEADER.size + responseLen - 3].decode()) resultBuf = resultBuf[OnkyoAVR.ISCP_HEADER.size + responseLen:] except: self.logger.error( "Error processing buffer. " "Possibly incomplete buffer. Increase receive buffer size") break result['output'] = utils.get_last_output(command, results, self.paramParser.value_sets, OnkyoAVR.SEARCH_SUFFIX) super(OnkyoAVR, self).process_result(commandName, command, result)
def process_result(self, commandName, command, result): if len(result) == 0: return if commandName.startswith('current_volume'): output = utils.get_last_output(command, result['output'], self.paramParser.value_sets, DenonAVR.SEARCH_SUFFIX) if output is None: return if len(output) > 2: output = output[:2] + '.5' else: output = output + '.0' output = float(output) else: output = self.paramParser.translate_param(command, utils.get_last_output(command, result['output'], self.paramParser.value_sets, DenonAVR.SEARCH_SUFFIX)) if output: result['result'] = output
def test_last_output_suffix(self): config = UtilsTester.config['last_output'] output = utils.get_last_output(config['commands']['suffixCommand'], ['cmd123'], {}, 'n') self.assertEqual(output, '123')
def test_last_output_values_multi_line(self): config = UtilsTester.config['last_output'] output = utils.get_last_output(config['commands']['valueCommand'], ['cmd123', 'cmdkey1'], config['values'], '') self.assertEqual(output, 'key1')
def test_last_output_hex_multi_line(self): config = UtilsTester.config['last_output'] output = utils.get_last_output(config['commands']['hexCommand'], ['cmdbaba', 'cmdcaca'], {}, '') self.assertEqual(output, 'caca')
def test_last_output_float_multi_line(self): config = UtilsTester.config['last_output'] output = utils.get_last_output(config['commands']['floatCommand'], ['cmd123', 'cmd234'], {}, '') self.assertEqual(output, '234')
def test_last_output_number_multi_prefix(self): config = UtilsTester.config['last_output'] output = utils.get_last_output(config['commands']['intCommand'], ['cmd123', 'cmdn234'], {}, '') self.assertEqual(output, '123')