Returns X, Y coordinates containing the closest avilable CIE 1931
    based on the hex_value provided.

def get_xy_from_hex(hex_value):
    '''
    Returns X, Y coordinates containing the closest avilable CIE 1931
    based on the hex_value provided.
    '''
    red, green, blue = struct.unpack('BBB', codecs.decode(hex_value, 'hex'))
    r = ((red + 0.055) / (1.0 + 0.055)) ** 2.4 if (red > 0.04045) else (red / 12.92)  # pragma: noqa
    g = ((green + 0.055) / (1.0 + 0.055)) ** 2.4 if (green > 0.04045) else (green / 12.92)  # pragma: noqa
    b = ((blue + 0.055) / (1.0 + 0.055)) ** 2.4 if (blue > 0.04045) else (blue / 12.92)  # pragma: noqa

    X = r * 0.4360747 + g * 0.3850649 + b * 0.0930804
    Y = r * 0.2225045 + g * 0.7168786 + b * 0.0406169
    Z = r * 0.0139322 + g * 0.0971045 + b * 0.7141733

    if X + Y + Z == 0:
        cx = cy = 0
    else:
        cx = X / (X + Y + Z)
        cy = Y / (X + Y + Z)

    # Check if the given XY value is within the colourreach of our lamps.
    xy_point = XYPoint(cx, cy)
    is_in_reach = in_lamp_reach(xy_point)

    if not is_in_reach:
        xy_point = get_closest_point_to_point(xy_point)

    return xy_point