def color_rgbww_to_rgb(
    r: int,
    g: int,
    b: int,
    cw: int,
    ww: int,
    min_kelvin: int,
    max_kelvin: int,
) -> tuple[int, int, int]:
    """Convert an rgbww color to an rgb representation."""
    # Calculate color temperature of the white channels
    max_mireds = color_temperature_kelvin_to_mired(min_kelvin)
    min_mireds = color_temperature_kelvin_to_mired(max_kelvin)
    mired_range = max_mireds - min_mireds
    try:
        ct_ratio = ww / (cw + ww)
    except ZeroDivisionError:
        ct_ratio = 0.5
    color_temp_mired = min_mireds + ct_ratio * mired_range
    if color_temp_mired:
        color_temp_kelvin = color_temperature_mired_to_kelvin(color_temp_mired)
    else:
        color_temp_kelvin = 0
    w_r, w_g, w_b = color_temperature_to_rgb(color_temp_kelvin)
    white_level = max(cw, ww) / 255

    # Add the white channels to the rgb channels.
    rgb = (r + w_r * white_level, g + w_g * white_level, b + w_b * white_level)

    # Match the output maximum value to the input. This ensures the
    # output doesn't overflow.
    return match_max_scale((r, g, b, cw, ww), rgb)  # type: ignore[return-value]
Convert an rgbww color to an rgb representation.
webapp/homeassistant_util_color.py