]> git.basschouten.com Git - openhab-addons.git/blob
8622acfc9e25c839c14c71da4d5004fff1a28691
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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     public @Nullable Integer ontime;
40
41     // depending on the type of light
42     public @Nullable Integer hue;
43     public @Nullable Integer sat;
44     public @Nullable Integer ct;
45     public double @Nullable [] xy;
46
47     // for window covering
48     public @Nullable Boolean open;
49     public @Nullable Boolean stop;
50     public @Nullable Integer lift;
51
52     public @Nullable Integer transitiontime;
53
54     /**
55      * compares two light states and ignore all fields that are null in either state
56      *
57      * @param o state to compare with
58      * @return true if equal
59      */
60     public boolean equalsIgnoreNull(LightState o) {
61         return equalsIgnoreNull(on, o.on) && equalsIgnoreNull(bri, o.bri) && equalsIgnoreNull(hue, o.hue)
62                 && equalsIgnoreNull(sat, o.sat) && ((xy != null && o.xy != null) ? Arrays.equals(xy, o.xy) : true);
63     }
64
65     /**
66      * clear this light state
67      */
68     public void clear() {
69         reachable = null;
70         on = null;
71         bri = null;
72
73         alert = null;
74         colormode = null;
75         effect = null;
76         effectSpeed = null;
77         ontime = null;
78
79         hue = null;
80         sat = null;
81         ct = null;
82         xy = null;
83
84         transitiontime = null;
85     }
86
87     private <T> boolean equalsIgnoreNull(T o1, T o2) {
88         return (o1 != null && o2 != null) ? o1.equals(o2) : true;
89     }
90
91     @Override
92     public String toString() {
93         return "LightState{" + "reachable=" + reachable + ", on=" + on + ", bri=" + bri + ", alert='" + alert + '\''
94                 + ", colormode='" + colormode + '\'' + ", effect='" + effect + '\'' + ", effectSpeed=" + effectSpeed
95                 + ", ontime=" + ontime + ", hue=" + hue + ", sat=" + sat + ", ct=" + ct + ", xy=" + Arrays.toString(xy)
96                 + ", transitiontime=" + transitiontime + '}';
97     }
98 }