]> git.basschouten.com Git - openhab-addons.git/blob
28096ec08fb18d2ee21b5ebdf0b7e1c5592a70e3
[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.somneo.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.library.types.PercentType;
19 import org.openhab.core.types.State;
20 import org.openhab.core.types.UnDefType;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * This class represents the light state from the API.
26  *
27  * @author Michael Myrcik - Initial contribution
28  */
29 @NonNullByDefault
30 public class LightData {
31
32     /**
33      * Brightness range from 0 to 25.
34      */
35     @SerializedName("ltlvl")
36     private @Nullable Integer mainLightLevel;
37
38     @SerializedName("onoff")
39     private @Nullable Boolean mainLight;
40
41     @SuppressWarnings("unused")
42     @SerializedName("tempy")
43     private @Nullable Boolean previewLight;
44
45     @SerializedName("ngtlt")
46     private @Nullable Boolean nightLight;
47
48     public int getMainLightLevel() {
49         final Integer mainLightLevel = this.mainLightLevel;
50         if (mainLightLevel == null) {
51             return 0;
52         }
53         return mainLightLevel * 4;
54     }
55
56     public void setMainLightLevel(int mainLightLevel) {
57         this.mainLightLevel = mainLightLevel / 4;
58     }
59
60     public State getMainLightState() {
61         final Boolean mainLight = this.mainLight;
62         final Integer mainLightLevel = this.mainLightLevel;
63         if (mainLight == null) {
64             return UnDefType.NULL;
65         }
66         if (mainLightLevel == null) {
67             return UnDefType.NULL;
68         }
69         if (mainLight) {
70             return new PercentType(mainLightLevel * 4);
71         }
72         return OnOffType.OFF;
73     }
74
75     public void setMainLight(boolean mainLight) {
76         this.mainLight = mainLight;
77     }
78
79     public void setPreviewLight(boolean previewLight) {
80         this.previewLight = previewLight;
81     }
82
83     public State getNightLightState() {
84         final Boolean nightLight = this.nightLight;
85         if (nightLight == null) {
86             return UnDefType.NULL;
87         }
88         return OnOffType.from(nightLight);
89     }
90
91     public void setNightLight(@Nullable Boolean nightLight) {
92         this.nightLight = nightLight;
93     }
94 }