2 * Copyright (c) 2010-2020 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.deconz.internal.dto;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
21 * The {@link LightState} is send by the websocket connection as well as the Rest API.
22 * It is part of a {@link LightMessage}.
24 * This should be in sync with the supported lights from
25 * https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Supported-Devices.
27 * @author Jan N. Klug - Initial contribution
30 public class LightState {
31 public @Nullable Boolean reachable;
32 public @Nullable Boolean on;
33 public @Nullable Integer bri;
35 public @Nullable String alert;
36 public @Nullable String colormode;
37 public @Nullable String effect;
39 // depending on the type of light
40 public @Nullable Integer hue;
41 public @Nullable Integer sat;
42 public @Nullable Integer ct;
43 public double @Nullable [] xy;
45 public @Nullable Integer transitiontime;
48 * compares two light states and ignore all fields that are null in either state
50 * @param o state to compare with
51 * @return true if equal
53 public boolean equalsIgnoreNull(LightState o) {
54 return equalsIgnoreNull(on, o.on) && equalsIgnoreNull(bri, o.bri) && equalsIgnoreNull(hue, o.hue)
55 && equalsIgnoreNull(sat, o.sat) && ((xy != null && o.xy != null) ? Arrays.equals(xy, o.xy) : true);
59 * clear this light state
75 transitiontime = null;
78 private <T> boolean equalsIgnoreNull(T o1, T o2) {
79 return (o1 != null && o2 != null) ? o1.equals(o2) : true;
83 public String toString() {
84 return "LightState{reachable=" + reachable + ", on=" + on + ", bri=" + bri + ", alert='" + alert + '\''
85 + ", colormode='" + colormode + '\'' + ", effect='" + effect + '\'' + ", hue=" + hue + ", sat=" + sat
86 + ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", transitiontime=" + transitiontime + '}';