]> git.basschouten.com Git - openhab-addons.git/blob
cfcdd4f70db239533ce9ea91b9f85ba9b5bca0b1
[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.deconz.internal.dto;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * The {@link LightState} is send by the websocket connection as well as the Rest API.
22  * It is part of a {@link LightMessage}.
23  *
24  * This should be in sync with the supported lights from
25  * https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Supported-Devices.
26  *
27  * @author Jan N. Klug - Initial contribution
28  */
29 @NonNullByDefault
30 public class LightState {
31     public @Nullable Boolean reachable;
32     public @Nullable Boolean on;
33     public @Nullable Integer bri;
34
35     public @Nullable String alert;
36     public @Nullable String colormode;
37     public @Nullable String effect;
38     public @Nullable Integer effectSpeed;
39
40     // depending on the type of light
41     public @Nullable Integer hue;
42     public @Nullable Integer sat;
43     public @Nullable Integer ct;
44     public double @Nullable [] xy;
45
46     public @Nullable Integer transitiontime;
47
48     /**
49      * compares two light states and ignore all fields that are null in either state
50      *
51      * @param o state to compare with
52      * @return true if equal
53      */
54     public boolean equalsIgnoreNull(LightState o) {
55         return equalsIgnoreNull(on, o.on) && equalsIgnoreNull(bri, o.bri) && equalsIgnoreNull(hue, o.hue)
56                 && equalsIgnoreNull(sat, o.sat) && ((xy != null && o.xy != null) ? Arrays.equals(xy, o.xy) : true);
57     }
58
59     /**
60      * clear this light state
61      */
62     public void clear() {
63         reachable = null;
64         on = null;
65         bri = null;
66
67         alert = null;
68         colormode = null;
69         effect = null;
70         effectSpeed = null;
71
72         hue = null;
73         sat = null;
74         ct = null;
75         xy = null;
76
77         transitiontime = null;
78     }
79
80     private <T> boolean equalsIgnoreNull(T o1, T o2) {
81         return (o1 != null && o2 != null) ? o1.equals(o2) : true;
82     }
83
84     @Override
85     public String toString() {
86         return "LightState{" + "reachable=" + reachable + ", on=" + on + ", bri=" + bri + ", alert='" + alert + '\''
87                 + ", colormode='" + colormode + '\'' + ", effect='" + effect + '\'' + ", effectSpeed=" + effectSpeed
88                 + ", hue=" + hue + ", sat=" + sat + ", ct=" + ct + ", xy=" + Arrays.toString(xy) + ", transitiontime="
89                 + transitiontime + '}';
90     }
91 }