]> git.basschouten.com Git - openhab-addons.git/blob
1d99ee7fd1ca58dfed5e7c22afacbbb0a30b796d
[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     String vendor = "Philips";
37
38     public HueLightState() {
39     }
40
41     public HueLightState(String model, String vendor) {
42         this.model = model;
43         this.vendor = vendor;
44     }
45
46     public HueLightState bri(int brightness) {
47         this.brightness = brightness;
48         return this;
49     }
50
51     public HueLightState hue(int hue) {
52         this.hue = hue;
53         return this;
54     }
55
56     public HueLightState sat(int saturation) {
57         this.saturation = saturation;
58         return this;
59     }
60
61     public HueLightState ct(int colorTemperature) {
62         this.colorTemperature = colorTemperature;
63         return this;
64     }
65
66     public HueLightState on(boolean isOn) {
67         this.isOn = isOn;
68         return this;
69     }
70
71     public HueLightState alert(String alert) {
72         this.alert = alert;
73         return this;
74     }
75
76     public HueLightState effect(String effect) {
77         this.effect = effect;
78         return this;
79     }
80
81     public HueLightState colormode(ColorMode colorMode) {
82         this.colorMode = colorMode.toString();
83         return this;
84     }
85
86     @Override
87     public String toString() {
88         return "" + //
89                 "{\"lights\":" + //
90                 "  {" + //
91                 "    \"1\": {" + //
92                 "      \"state\": {" + //
93                 "        \"on\": " + isOn + "," + //
94                 "        \"bri\": " + brightness + "," + //
95                 "        \"hue\": " + hue + "," + //
96                 "        \"sat\": " + saturation + "," + //
97                 "        \"xy\": [" + //
98                 "          0," + //
99                 "          0" + //
100                 "        ]," + //
101                 "        \"ct\": " + colorTemperature + "," + //
102                 "        \"alert\": \"" + alert + "\"," + //
103                 "        \"effect\": \"" + effect + "\"," + //
104                 "        \"colormode\": \"" + colorMode + "\"," + //
105                 "        \"reachable\": true" + //
106                 "      }," + //
107                 "      \"type\": \"Extended color light\"," + //
108                 "      \"name\": \"Hue Light 1\"," + //
109                 "      \"modelid\": \"" + model + "\"," + //
110                 "      \"manufacturername\": \"" + vendor + "\"," + //
111                 "      \"swversion\": \"65003148\"," + //
112                 "      \"uniqueid\": \"00:17:88:01:00:e1:88:29-0b\"," + //
113                 "      \"pointsymbol\": {" + //
114                 "        \"1\": \"none\"," + //
115                 "        \"2\": \"none\"," + //
116                 "        \"3\": \"none\"," + //
117                 "        \"4\": \"none\"," + //
118                 "        \"5\": \"none\"," + //
119                 "        \"6\": \"none\"," + //
120                 "        \"7\": \"none\"," + //
121                 "        \"8\": \"none\"" + //
122                 "      }" + //
123                 "    }" + //
124                 "  }" + //
125                 "}";
126     }
127 }