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