2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hue.internal.api.dto.clip2;
15 import java.util.Objects;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.util.ColorUtil.Gamut;
22 * DTO for colour gamut of a light.
24 * @author Andrew Fiddian-Green - Initial contribution
28 private @Nullable PairXy red;
29 private @Nullable PairXy green;
30 private @Nullable PairXy blue;
32 public @Nullable Gamut getGamut() {
33 PairXy red = this.red;
34 PairXy green = this.green;
35 PairXy blue = this.blue;
36 if (Objects.nonNull(red) && Objects.nonNull(green) && Objects.nonNull(blue)) {
37 return new Gamut(red.getXY(), green.getXY(), blue.getXY());
42 public Gamut2 setGamut(Gamut gamut) {
43 red = new PairXy().setXY(gamut.r());
44 green = new PairXy().setXY(gamut.g());
45 blue = new PairXy().setXY(gamut.b());
49 public @Nullable String toPropertyValue() {
50 PairXy red = this.red;
51 PairXy green = this.green;
52 PairXy blue = this.blue;
53 if (Objects.nonNull(red) && Objects.nonNull(green) && Objects.nonNull(blue)) {
54 double[] r = red.getXY();
55 double[] g = green.getXY();
56 double[] b = blue.getXY();
57 return String.format("(%.3f,%.3f) (%.3f,%.3f) (%.3f,%.3f)", r[0], r[1], g[0], g[1], b[0], b[1]);