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.clip1;
15 import org.openhab.binding.hue.internal.api.dto.clip1.State.AlertMode;
16 import org.openhab.binding.hue.internal.api.dto.clip1.State.Effect;
19 * Collection of updates to the state of a light.
21 * @author Q42 - Initial contribution
22 * @author Thomas Höfer - added unique id and changed range check for brightness and saturation
23 * @author Denis Dudnik - moved Jue library source code inside the smarthome Hue binding, minor code cleanup
24 * @author Samuel Leisering - refactor configuration updates
26 public class StateUpdate extends ConfigUpdate {
28 private Integer colorTemperature;
29 private Integer brightness;
34 * @return this object for chaining calls
36 public StateUpdate turnOn() {
43 * @return this object for chaining calls
45 public StateUpdate turnOff() {
50 * Turn light on or off.
52 * @param on on if true, off otherwise
53 * @return this object for chaining calls
55 public StateUpdate setOn(boolean on) {
56 commands.add(new Command("on", on));
61 * Set brightness of light.
62 * Brightness 0 is not the same as off.
64 * @param brightness brightness [1..254]
65 * @return this object for chaining calls
67 public StateUpdate setBrightness(int brightness) {
68 if (brightness < 1 || brightness > 254) {
69 throw new IllegalArgumentException("Brightness out of range");
72 commands.add(new Command("bri", brightness));
73 this.brightness = brightness;
77 public Integer getBrightness() {
78 return this.brightness;
82 * Switch to HS color mode and set hue.
84 * @param hue hue [0..65535]
85 * @return this object for chaining calls
87 public StateUpdate setHue(int hue) {
88 if (hue < 0 || hue > 65535) {
89 throw new IllegalArgumentException("Hue out of range");
92 commands.add(new Command("hue", hue));
97 * Switch to HS color mode and set saturation.
99 * @param saturation saturation [0..254]
100 * @return this object for chaining calls
102 public StateUpdate setSat(int saturation) {
103 if (saturation < 0 || saturation > 254) {
104 throw new IllegalArgumentException("Saturation out of range");
107 commands.add(new Command("sat", saturation));
112 * Switch to XY color mode and set CIE color space coordinates.
114 * @param x x coordinate [0..1]
115 * @param y y coordinate [0..1]
116 * @return this object for chaining calls
118 public StateUpdate setXY(float x, float y) {
119 return setXY(new float[] { x, y });
123 * Switch to XY color mode and set CIE color space coordinates.
125 * @param xy x and y coordinates [0..1, 0..1]
126 * @return this object for chaining calls
128 public StateUpdate setXY(float[] xy) {
129 if (xy.length != 2) {
130 throw new IllegalArgumentException("Invalid coordinate array given");
131 } else if (xy[0] < 0.0f || xy[0] > 1.0f || xy[1] < 0.0f || xy[1] > 1.0f) {
132 throw new IllegalArgumentException("X and/or Y coordinate(s) out of bounds");
135 commands.add(new Command("xy", xy));
140 * Switch to CT color mode and set color temperature in mired.
142 * @param colorTemperature color temperature
143 * @return this object for chaining calls
145 public StateUpdate setColorTemperature(int colorTemperature, ColorTemperature capabilities) {
146 if (colorTemperature < capabilities.min || colorTemperature > capabilities.max) {
147 throw new IllegalArgumentException(String.format("Color temperature %d is out of range [%d..%d]",
148 colorTemperature, capabilities.min, capabilities.max));
151 commands.add(new Command("ct", colorTemperature));
152 this.colorTemperature = colorTemperature;
156 public Integer getColorTemperature() {
157 return this.colorTemperature;
161 * Set the alert mode.
164 * @param mode alert mode
165 * @return this object for chaining calls
167 public StateUpdate setAlert(AlertMode mode) {
168 commands.add(new Command("alert", mode.toString().toLowerCase()));
173 * Set the current effect.
176 * @param effect effect
177 * @return this object for chaining calls
179 public StateUpdate setEffect(Effect effect) {
180 commands.add(new Command("effect", effect.toString().toLowerCase()));
185 * Set the transition time from the current state to the new state.
186 * Time is accurate to 100 milliseconds.
188 * @param timeMillis time in milliseconds [0..6553600]
189 * @return this object for chaining calls
191 public StateUpdate setTransitionTime(long timeMillis) {
192 if (timeMillis < 0 || timeMillis > 6553600) {
193 throw new IllegalArgumentException("Transition time out of range");
196 commands.add(new Command("transitiontime", timeMillis / 100));
201 * Turn sensor flag on or off.
203 * @param flag on if true, off otherwise
204 * @return this object for chaining calls
207 public StateUpdate setFlag(boolean flag) {
208 commands.add(new Command("flag", flag));
213 * Set status of sensor.
215 * @param status status
216 * @return this object for chaining calls
218 public StateUpdate setStatus(int status) {
219 commands.add(new Command("status", status));
224 * Recall the given scene.
226 * @param sceneId Identifier of the scene
227 * @return this object for chaining calls
229 public StateUpdate setScene(String sceneId) {
230 commands.add(new Command("scene", sceneId));