# Path: myDevices/utils/logger.py
# def debug(message):
#     outerFrame = getouterframes(currentframe())[1][0]
#     (args, _, _, values) = getargvalues(outerFrame)
#     argsValue = ''
#     
#     for i in args:
#         if i is 'self':
#             continue
#         argsValue += "(%s=%s)" % (i, str(values[i]))
#     
#     stack = extract_stack()
#     (filename, line, procname, text) = stack[-2]
#     LOGGER.debug(str(filename) + ' ' + str(procname) + str(argsValue) + ':' + str(line) + '> '  + str(message))
# 
# def error(message, *args, **kwargs):
#     if checkFlood(message):
#         return
#     LOGGER.error(message, *args, **kwargs)
# 
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)
# 
# def info(message):
#     # if checkFlood(message):
#     #     return
#     LOGGER.info(message)
# 
# def logJson(message, category = ''):
#     if debugEnabled() == False:
#         return
#     if checkFlood(message):
#         return
#     try:
#         if category not in jsonData:
#             jsonData[category] = []
#         if len(jsonData[category]) > MAX_JSON_ITEMS_PER_CATEGORY:
#             del jsonData[category][0]
#         #2016-03-23 03:53:16 - myDevices - INFO -
#         message = str(datetime.today()) + ' - myDevices - INFO - ' + message
#         jsonData[category].append(message)
#         rotatorJson()
#     except Exception as ex:
#         exception("logJson failed")
# 
# def warn(message):
#     if checkFlood(message):
#         return
#     LOGGER.warn(message)


import time
import paho.mqtt.client as mqtt
from json import loads, decoder
from ssl import PROTOCOL_TLSv1_2
from myDevices.utils.logger import debug, error, exception, info, logJson, warn
        payload is an optional list of payload data items.
        channel is an optional list containing channel and suffix data.
        """
        if not payload:
            command['payload'] = command.pop('value')
            channel = command['channel'].split('/')[-1].split(';')
        else:
            if len(payload) > 1:
                command['cmdId'] = payload[0]
                command['payload'] = payload[1]
            else:
                command['payload'] = payload[0]
        command['channel'] = channel[0]
        if len(channel) > 1:
            command['suffix'] = channel[1]

    def message_callback(self, client, userdata, msg):
        """The callback for when a message is received from the server.

        client is the client instance for this callback.
        userdata is the private user data as set in Client() or userdata_set().
        msg is the received message.
        """
        try:
            message = {}
            if msg.topic[-len(COMMAND_JSON_TOPIC):] == COMMAND_JSON_TOPIC:
                message = loads(msg.payload.decode())
                self.transform_command(message)
            else:
                self.transform_command(message, msg.payload.decode().split(','), msg.topic.split('/')[-1].split(';'))

# Path: myDevices/utils/logger.py
# def debug(message):
#     outerFrame = getouterframes(currentframe())[1][0]
#     (args, _, _, values) = getargvalues(outerFrame)
#     argsValue = ''
#     
#     for i in args:
#         if i is 'self':
#             continue
#         argsValue += "(%s=%s)" % (i, str(values[i]))
#     
#     stack = extract_stack()
#     (filename, line, procname, text) = stack[-2]
#     LOGGER.debug(str(filename) + ' ' + str(procname) + str(argsValue) + ':' + str(line) + '> '  + str(message))
# 
# def error(message, *args, **kwargs):
#     if checkFlood(message):
#         return
#     LOGGER.error(message, *args, **kwargs)
# 
# def exception(message):
#     if checkFlood(message):
#         return
#     LOGGER.exception(message)
# 
# def info(message):
#     # if checkFlood(message):
#     #     return
#     LOGGER.info(message)
# 
# def logJson(message, category = ''):
#     if debugEnabled() == False:
#         return
#     if checkFlood(message):
#         return
#     try:
#         if category not in jsonData:
#             jsonData[category] = []
#         if len(jsonData[category]) > MAX_JSON_ITEMS_PER_CATEGORY:
#             del jsonData[category][0]
#         #2016-03-23 03:53:16 - myDevices - INFO -
#         message = str(datetime.today()) + ' - myDevices - INFO - ' + message
#         jsonData[category].append(message)
#         rotatorJson()
#     except Exception as ex:
#         exception("logJson failed")
# 
# def warn(message):
#     if checkFlood(message):
#         return
#     LOGGER.warn(message)


# Path: myDevices/cloud/cayennemqtt.py
import time
import paho.mqtt.client as mqtt
from json import loads, decoder
from ssl import PROTOCOL_TLSv1_2
from myDevices.utils.logger import debug, error, exception, info, logJson, warn

        payload is an optional list of payload data items.
        channel is an optional list containing channel and suffix data.
        """
        if not payload:
            command['payload'] = command.pop('value')
            channel = command['channel'].split('/')[-1].split(';')
        else:
            if len(payload) > 1:
                command['cmdId'] = payload[0]
                command['payload'] = payload[1]
            else:
                command['payload'] = payload[0]
        command['channel'] = channel[0]
        if len(channel) > 1:
            command['suffix'] = channel[1]

    def message_callback(self, client, userdata, msg):
        """The callback for when a message is received from the server.

        client is the client instance for this callback.
        userdata is the private user data as set in Client() or userdata_set().
        msg is the received message.
        """
        try:
            message = {}
            if msg.topic[-len(COMMAND_JSON_TOPIC):] == COMMAND_JSON_TOPIC:
                message = loads(msg.payload.decode())
                self.transform_command(message)
            else:
                self.transform_command(message, msg.payload.decode().split(','), msg.topic.split('/')[-1].split(';'))

            debug('message_callback: {}'.format(message))