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.somneo.internal.model;
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;
22 import com.google.gson.annotations.SerializedName;
25 * This class represents the light state from the API.
27 * @author Michael Myrcik - Initial contribution
30 public class LightData {
33 * Brightness range from 0 to 25.
35 @SerializedName("ltlvl")
36 private @Nullable Integer mainLightLevel;
38 @SerializedName("onoff")
39 private @Nullable Boolean mainLight;
41 @SuppressWarnings("unused")
42 @SerializedName("tempy")
43 private @Nullable Boolean previewLight;
45 @SerializedName("ngtlt")
46 private @Nullable Boolean nightLight;
48 public int getMainLightLevel() {
49 final Integer mainLightLevel = this.mainLightLevel;
50 if (mainLightLevel == null) {
53 return mainLightLevel * 4;
56 public void setMainLightLevel(int mainLightLevel) {
57 this.mainLightLevel = mainLightLevel / 4;
60 public State getMainLightState() {
61 final Boolean mainLight = this.mainLight;
62 final Integer mainLightLevel = this.mainLightLevel;
63 if (mainLight == null) {
64 return UnDefType.NULL;
66 if (mainLightLevel == null) {
67 return UnDefType.NULL;
70 return new PercentType(mainLightLevel * 4);
75 public void setMainLight(boolean mainLight) {
76 this.mainLight = mainLight;
79 public void setPreviewLight(boolean previewLight) {
80 this.previewLight = previewLight;
83 public State getNightLightState() {
84 final Boolean nightLight = this.nightLight;
85 if (nightLight == null) {
86 return UnDefType.NULL;
88 return OnOffType.from(nightLight);
91 public void setNightLight(@Nullable Boolean nightLight) {
92 this.nightLight = nightLight;