'Handle EnOcean device\'s callback.
This is the callback function called by python-enocan whenever there
is an incoming packet.'

def callback(self, temp):

    from enocean.protocol.packet import RadioPacket
    if isinstance(temp, RadioPacket):
        rxtype = None
        value = None
        if (temp.data[6] == 48):
            rxtype = 'wallswitch'
            value = 1
        elif (temp.data[6] == 32):
            rxtype = 'wallswitch'
            value = 0
        elif (temp.data[4] == 12):
            rxtype = 'power'
            value = (temp.data[3] + (temp.data[2] << 8))
        elif (temp.data[2] == 96):
            rxtype = 'switch_status'
            if (temp.data[3] == 228):
                value = 1
            elif (temp.data[3] == 128):
                value = 0
        elif ((temp.data[0] == 165) and (temp.data[1] == 2)):
            rxtype = 'dimmerstatus'
            value = temp.data[2]
        for device in self.__devices:
            if ((rxtype == 'wallswitch') and (device.stype == 'listener')):
                if (temp.sender == self._combine_hex(device.dev_id)):
                    device.value_changed(value, temp.data[1])
            if ((rxtype == 'power') and (device.stype == 'powersensor')):
                if (temp.sender == self._combine_hex(device.dev_id)):
                    device.value_changed(value)
            if ((rxtype == 'power') and (device.stype == 'switch')):
                if (temp.sender == self._combine_hex(device.dev_id)):
                    if (value > 10):
                        device.value_changed(1)
            if ((rxtype == 'switch_status') and (device.stype == 'switch')):
                if (temp.sender == self._combine_hex(device.dev_id)):
                    device.value_changed(value)
            if ((rxtype == 'dimmerstatus') and (device.stype == 'dimmer')):
                if (temp.sender == self._combine_hex(device.dev_id)):
                    device.value_changed(value)
