]> git.basschouten.com Git - openhab-addons.git/blob
c12fc8c10cc1e3f49828b2ae23317e2585865910
[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.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.hue.internal.api.dto.clip1.State.ColorMode;
17
18 /**
19  * Builder for the current state of a hue light.
20  *
21  * @author Dominic Lerbs - Initial contribution
22  * @author Markus Mazurczak - Added possibility to set modelId to "PAR16 50 TW" to test osram workaround
23  * @author Markus Rathgeb - migrated to plain Java test
24  * @author Christoph Weitkamp - Added support for bulbs using CIE XY colormode only
25  */
26 @NonNullByDefault
27 public class HueLightState {
28
29     int brightness = 200;
30     int hue = 50000;
31     int saturation = 0;
32     int colorTemperature = 153;
33     boolean isOn = true;
34     String alert = "none";
35     String effect = "none";
36     String colorMode = "hs";
37     String model = "LCT001";
38     String vendor = "Philips";
39
40     public HueLightState() {
41     }
42
43     public HueLightState(String model, String vendor) {
44         this.model = model;
45         this.vendor = vendor;
46     }
47
48     public HueLightState bri(int brightness) {
49         this.brightness = brightness;
50         return this;
51     }
52
53     public HueLightState hue(int hue) {
54         this.hue = hue;
55         return this;
56     }
57
58     public HueLightState sat(int saturation) {
59         this.saturation = saturation;
60         return this;
61     }
62
63     public HueLightState ct(int colorTemperature) {
64         this.colorTemperature = colorTemperature;
65         return this;
66     }
67
68     public HueLightState on(boolean isOn) {
69         this.isOn = isOn;
70         return this;
71     }
72
73     public HueLightState alert(String alert) {
74         this.alert = alert;
75         return this;
76     }
77
78     public HueLightState effect(String effect) {
79         this.effect = effect;
80         return this;
81     }
82
83     public HueLightState colormode(ColorMode colorMode) {
84         this.colorMode = colorMode.toString();
85         return this;
86     }
87
88     @Override
89     public String toString() {
90         return "" + //
91                 "{\"lights\":" + //
92                 "  {" + //
93                 "    \"1\": {" + //
94                 "      \"state\": {" + //
95                 "        \"on\": " + isOn + "," + //
96                 "        \"bri\": " + brightness + "," + //
97                 "        \"hue\": " + hue + "," + //
98                 "        \"sat\": " + saturation + "," + //
99                 "        \"xy\": [" + //
100                 "          0," + //
101                 "          0" + //
102                 "        ]," + //
103                 "        \"ct\": " + colorTemperature + "," + //
104                 "        \"alert\": \"" + alert + "\"," + //
105                 "        \"effect\": \"" + effect + "\"," + //
106                 "        \"colormode\": \"" + colorMode + "\"," + //
107                 "        \"reachable\": true" + //
108                 "      }," + //
109                 "      \"type\": \"Extended color light\"," + //
110                 "      \"name\": \"Hue Light 1\"," + //
111                 "      \"modelid\": \"" + model + "\"," + //
112                 "      \"manufacturername\": \"" + vendor + "\"," + //
113                 "      \"swversion\": \"65003148\"," + //
114                 "      \"uniqueid\": \"00:17:88:01:00:e1:88:29-0b\"," + //
115                 "      \"pointsymbol\": {" + //
116                 "        \"1\": \"none\"," + //
117                 "        \"2\": \"none\"," + //
118                 "        \"3\": \"none\"," + //
119                 "        \"4\": \"none\"," + //
120                 "        \"5\": \"none\"," + //
121                 "        \"6\": \"none\"," + //
122                 "        \"7\": \"none\"," + //
123                 "        \"8\": \"none\"" + //
124                 "      }" + //
125                 "    }" + //
126                 "  }" + //
127                 "}";
128     }
129 }