def validate_packet(self, data):
<EOL>expected_length = data[<NUM_LIT:0>] + <NUM_LIT:1><EOL>if len(data) != expected_length:<EOL><INDENT>raise InvalidPacketLength(<EOL>"<STR_LIT>"<EOL>% (expected_length, len(data))<EOL>)<EOL><DEDENT>if expected_length < <NUM_LIT:4>:<EOL><INDENT>raise MalformedPacket(<EOL>"<STR_LIT>"<EOL>% (len(data))<EOL>)<EOL><DEDENT>packet_type = data[<NUM_LIT:1>]<EOL>if self.PACKET_TYPES and packet_type not in self.PACKET_TYPES:<EOL><INDENT>types = "<STR_LIT:U+002C>".join("<STR_LIT>".format(pt) for pt in self.PACKET_TYPES)<EOL>raise UnknownPacketType(<EOL>"<STR_LIT>"<EOL>% (types, packet_type)<EOL>)<EOL><DEDENT>sub_type = data[<NUM_LIT:2>]<EOL>if self.PACKET_SUBTYPES and sub_type not in self.PACKET_SUBTYPES:<EOL><INDENT>types ="<STR_LIT:U+002C>".join("<STR_LIT>".format(pt) for pt in self.PACKET_SUBTYPES)<EOL>raise UnknownPacketSubtype(<EOL>"<STR_LIT>"<EOL>% (types, sub_type))<EOL><DEDENT>return True<EOL>
Validate a packet against this packet handler and determine if it
        meets the requirements. This is done by checking the following
        conditions are true.

        - The length of the packet is equal to the first byte.
        - The second byte is in the set of defined PACKET_TYPES for this class.
        - The third byte is in the set of this class defined PACKET_SUBTYPES.

        If one or more of these conditions isn't met then we have a packet that
        isn't valid or at least isn't understood by this handler.

        :param data: bytearray to be verified
        :type data: bytearray


        :raises: :py:class:`rfxcom.exceptions.InvalidPacketLength`: If the
            number of bytes in the packet doesn't match the expected length.

        :raises: :py:class:`rfxcom.exceptions.UnknownPacketType`: If the packet
            type is unknown to this packet handler

        :raises: :py:class:`rfxcom.exceptions.UnknownPacketSubtype`: If the
            packet sub type is unknown to this packet handler

        :return: true is returned if validation passes.
        :rtype: boolean