]> git.basschouten.com Git - openhab-addons.git/blob
b218e57fb732b749cecb5a6e7114bd07d786e884
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hue.internal.dto.clip2;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.util.ColorUtil.Gamut;
20
21 /**
22  * DTO for colour gamut of a light.
23  *
24  * @author Andrew Fiddian-Green - Initial contribution
25  */
26 @NonNullByDefault
27 public class Gamut2 {
28     private @Nullable PairXy red;
29     private @Nullable PairXy green;
30     private @Nullable PairXy blue;
31
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());
38         }
39         return null;
40     }
41
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());
46         return this;
47     }
48
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]);
58         }
59         return null;
60     }
61 }