def _compute_checksum(packet):
    """Computes the checksum byte of a packet.

    Packet must not contain a checksum already

    Args:
        packet (list):
            List of bytes for a packet.
            packet must not contain a checksum
            as the last element

    Returns:
        The computed checksum byte.
    """
    # checksum is the sum of the bytes
    # from device id to the end of the data
    # mod (%) 256 and bit negated (~) (1's compliment)
    # and (&) with 0xFF to make sure it is a byte.
    return ~(sum(packet[2:]) % 0x100) & 0xFF