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.tplinksmarthome.internal.model;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.OnOffType;
20 import com.google.gson.annotations.Expose;
21 import com.google.gson.annotations.SerializedName;
24 * Data class for setting the TP-Link Smart Light Strip state and retrieving the result.
26 * @author Hilbrand Bouwkamp - Initial contribution
28 public class SetLightState implements HasErrorResponse {
30 private static final int GROUPS_INDEX_HUE = 2;
31 private static final int GROUPS_INDEX_SATURATION = 3;
32 private static final int GROUPS_INDEX_BRIGHTNESS = 4;
33 private static final int GROUPS_INDEX_COLOR_TEMPERATURE = 5;
35 public static class ColorTemperature extends LightOnOff {
36 @Expose(deserialize = false)
37 private int colorTemp;
38 @Expose(deserialize = false)
40 @Expose(deserialize = false)
41 private int saturation = 0;
43 public void setColorTemp(final int colorTemperature) {
44 this.colorTemp = colorTemperature;
48 public static class Color extends Brightness {
49 @Expose(deserialize = false)
50 private int colorTemp;
51 @Expose(deserialize = false)
53 @Expose(deserialize = false)
54 private int saturation;
56 public void setHue(final int hue) {
60 public void setSaturation(final int saturation) {
61 this.saturation = saturation;
65 public static class Brightness extends LightOnOff {
66 @Expose(deserialize = false)
67 private int brightness;
69 public void setBrightness(final int brightness) {
70 this.brightness = brightness;
74 public static class LightOnOff extends ErrorResponse {
77 @Expose(serialize = false)
79 @Expose(deserialize = false)
80 private int transition;
82 * groups contain status: [[0,31,0,0,73,5275]]
83 * [?,?,hue,saturation,brightness,color_temp]
85 @Expose(serialize = false)
86 protected int[][] groups;
88 public OnOffType getOnOff() {
89 return OnOffType.from(onOff == 1);
92 public void setOnOff(final OnOffType onOff) {
93 this.onOff = onOff == OnOffType.ON ? 1 : 0;
96 public void setTransition(final int transition) {
97 this.transition = transition;
100 public int getHue() {
101 return groups[0][GROUPS_INDEX_HUE];
104 public int getSaturation() {
105 return groups[0][GROUPS_INDEX_SATURATION];
108 public int getBrightness() {
109 return groups[0][GROUPS_INDEX_BRIGHTNESS];
112 public int getColorTemperature() {
113 return groups[0][GROUPS_INDEX_COLOR_TEMPERATURE];
116 public int[][] getGroups() {
121 public String toString() {
122 return "onOff:" + onOff + ", mode:" + mode + ", transition:" + transition + ", groups:"
123 + Arrays.toString(groups);
127 public static class Context {
129 private String source = "12345668-1234-1234-1234-123456789012";
131 public String getSource() {
135 public void setSource(final String source) {
136 this.source = source;
140 public static class LightingStrip {
142 private LightOnOff setLightState;
145 public String toString() {
146 return "setLightState:{" + setLightState + "}";
151 @SerializedName("smartlife.iot.lightStrip")
153 private final LightingStrip strip = new LightingStrip();
155 @Expose(deserialize = false)
156 private Context context;
158 public void setLightState(final LightOnOff lightState) {
159 strip.setLightState = lightState;
162 public void setContext(final Context context) {
163 this.context = context;
167 public ErrorResponse getErrorResponse() {
168 return strip.setLightState;
172 public String toString() {
173 return "SetLightState {strip:{" + strip + "}";