예제 #1
0
 def executeBridgeCommand(self, command):
     start_time = time.time()
     command_name = command.command_name
     self.logger.debug('Running executeBridgeCommand with %s' % command)
     if command.command_name == 'add_device_encryption_key':
         if command.params.has_key(
                 'device_address') and command.params.has_key(
                     'encryption_key'):
             device_address = command.params['device_address']
             encryption_key_base64 = command.params['encryption_key']
             encryption_key_bin = base64.b64decode(encryption_key_base64)
             encryption_key_seq = struct.unpack('BBBBBBBBBBBBBBBB',
                                                encryption_key_bin)
             self.device.TCAddOrUpdateKey(
                 byte_tuple.convertToEui64(device_address),
                 encryption_key_seq)
             return 0
         raise TypeError, "BridgeCommand 'add_device_encryption_key' takes two arguments, 'device_address' and 'encryption_key'"
     elif command.command_name == 'set_cloud_log_level':
         lm = customlogger.LoggerManager()
         level = command.param_value_for_key('level')
         if isinstance(level, int):
             level = command.params['level']
             if level < 10:
                 level = 10
             elif level > 50:
                 level = 50
         if isinstance(level, str) or isinstance(level, unicode):
             level = level.lower()
             log_level = logging.WARNING
             if level == 'debug':
                 log_level = logging.DEBUG
             elif level == 'info':
                 log_level = logging.INFO
             elif level == 'warning':
                 log_level = logging.WARNING
             elif level == 'error':
                 log_level = logging.ERROR
             elif level == 'critical':
                 log_level = logging.CRITICAL
             self.logger.debug('Setting cloud logging level to %d' %
                               log_level)
             result = lm.setCloudLoggingLevel(log_level)
             return result
         raise TypeError, "BridgeCommand 'set_cloud_log_level' takes a 'level' argument of type string"
     elif command.command_name == 'leave':
         result = self.device.emberLeaveNetwork()
         return result
     if command.command_name == 'form':
         channels = command.param_value_for_key('channels')
         if not isinstance(channels, list):
             channels = [11, 14, 15, 19, 20, 24, 25]
         result = self.device.scanForUnusedPanId(channels)
         return result
     if command.command_name == 'pjoin':
         duration = command.param_value_for_key('duration')
         if isinstance(duration, str) or isinstance(
                 duration, int) or isinstance(duration, unicode):
             self.device.emberPermitJoining(int(duration))
         else:
             self.device.emberPermitJoining(255)
     else:
         if command.command_name == 'restart':
             self.logger.warning("Issuing 'restart' flag!")
             self.should_restart = True
             return 0
         else:
             if command.command_name == 'reboot':
                 self.logger.warning("Issuing 'reboot' flag!")
                 self.should_reboot = True
                 return 0
             self.logger.error("Unknown BridgeCommand name '%s'" %
                               command.command_name)
             return 1
 def bridge_address(self, value):
     if isinstance(value, tuple) or value == None:
         self._bridge_address = value
     else:
         self._bridge_address = byte_tuple.convertToEui64(value)
 def executeBridgeCommand(self, command):
     start_time = time.time()
     command_name = command.command_name
     self.logger.debug('Running executeBridgeCommand with %s' % command)
     if command.command_name == 'add_device_encryption_key':
         if command.params.has_key('device_address') and command.params.has_key('encryption_key'):
             device_address = command.params['device_address']
             encryption_key_base64 = command.params['encryption_key']
             encryption_key_bin = base64.b64decode(encryption_key_base64)
             encryption_key_seq = struct.unpack('BBBBBBBBBBBBBBBB', encryption_key_bin)
             self.device.TCAddOrUpdateKey(byte_tuple.convertToEui64(device_address), encryption_key_seq)
             return 0
         raise TypeError, "BridgeCommand 'add_device_encryption_key' takes two arguments, 'device_address' and 'encryption_key'"
     elif command.command_name == 'set_cloud_log_level':
         lm = customlogger.LoggerManager()
         level = command.param_value_for_key('level')
         if isinstance(level, int):
             level = command.params['level']
             if level < 10:
                 level = 10
             elif level > 50:
                 level = 50
         if isinstance(level, str) or isinstance(level, unicode):
             level = level.lower()
             log_level = logging.WARNING
             if level == 'debug':
                 log_level = logging.DEBUG
             elif level == 'info':
                 log_level = logging.INFO
             elif level == 'warning':
                 log_level = logging.WARNING
             elif level == 'error':
                 log_level = logging.ERROR
             elif level == 'critical':
                 log_level = logging.CRITICAL
             self.logger.debug('Setting cloud logging level to %d' % log_level)
             result = lm.setCloudLoggingLevel(log_level)
             return result
         raise TypeError, "BridgeCommand 'set_cloud_log_level' takes a 'level' argument of type string"
     elif command.command_name == 'leave':
         result = self.device.emberLeaveNetwork()
         return result
     if command.command_name == 'form':
         channels = command.param_value_for_key('channels')
         if not isinstance(channels, list):
             channels = [11,
              14,
              15,
              19,
              20,
              24,
              25]
         result = self.device.scanForUnusedPanId(channels)
         return result
     if command.command_name == 'pjoin':
         duration = command.param_value_for_key('duration')
         if isinstance(duration, str) or isinstance(duration, int) or isinstance(duration, unicode):
             self.device.emberPermitJoining(int(duration))
         else:
             self.device.emberPermitJoining(255)
     else:
         if command.command_name == 'restart':
             self.logger.warning("Issuing 'restart' flag!")
             self.should_restart = True
             return 0
         else:
             if command.command_name == 'reboot':
                 self.logger.warning("Issuing 'reboot' flag!")
                 self.should_reboot = True
                 return 0
             self.logger.error("Unknown BridgeCommand name '%s'" % command.command_name)
             return 1