def __init__(self, pahoMessage, messageEncoderModules): result = NOTIFY_RE.match(pahoMessage.topic) if result: self.type = result.group(1) self.id = result.group(2) self.format = 'json' if self.format in messageEncoderModules: message = messageEncoderModules[self.format].decode(pahoMessage) self.timestamp = message.timestamp self.data = message.data else: raise MissingMessageDecoderException(self.format) else: raise InvalidEventException("Received notification on invalid topic: %s" % (pahoMessage.topic))
def __init__(self, pahoMessage, messageEncoderModules): result = Command._TOPIC_REGEX.match(pahoMessage.topic) if result: self.commandId = result.group(1) self.format = result.group(2) if self.format in messageEncoderModules: message = messageEncoderModules[self.format].decode( pahoMessage) self.timestamp = message.timestamp self.data = message.data else: raise MissingMessageDecoderException(self.format) else: raise InvalidEventException( "Received command on invalid topic: %s" % (pahoMessage.topic))
def __init__(self, pahoMessage, messageEncoderModules): result = DEVICE_EVENT_RE.match(pahoMessage.topic) if result: self.typeId = result.group(1) self.deviceId = result.group(2) self.device = self.typeId + ":" + self.deviceId self.eventId = result.group(3) self.format = result.group(4) self.payload = pahoMessage.payload if self.format in messageEncoderModules: message = messageEncoderModules[self.format].decode(pahoMessage) self.timestamp = message.timestamp self.data = message.data else: raise MissingMessageDecoderException(self.format) else: raise InvalidEventException("Received device event on invalid topic: %s" % (pahoMessage.topic))