]> git.basschouten.com Git - openhab-addons.git/blob
953e54eb0dcd3e450240b3c7257c1e7252f297af
[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.tplinksmarthome.internal.model;
14
15 import org.openhab.core.library.types.DecimalType;
16 import org.openhab.core.library.types.OnOffType;
17 import org.openhab.core.library.types.PercentType;
18
19 /**
20  * Data class for reading the retrieved state of a Smart Home light bulb.
21  * Mostly only getter methods as the values are set by gson based on the retrieved json.
22  *
23  * @author Hilbrand Bouwkamp - Initial contribution
24  */
25 public class LightState extends ErrorResponse {
26
27     private int brightness;
28     private int colorTemp;
29     private int hue;
30     private int ignoreDefault;
31     private String mode;
32     private int onOff;
33     private int saturation;
34
35     public PercentType getBrightness() {
36         return onOff > 0 ? new PercentType(brightness) : PercentType.ZERO;
37     }
38
39     public int getColorTemp() {
40         return colorTemp;
41     }
42
43     public DecimalType getHue() {
44         return new DecimalType(hue);
45     }
46
47     public int getIgnoreDefault() {
48         return ignoreDefault;
49     }
50
51     public String getMode() {
52         return mode;
53     }
54
55     public OnOffType getOnOff() {
56         return OnOffType.from(onOff == 1);
57     }
58
59     public PercentType getSaturation() {
60         return new PercentType(saturation);
61     }
62
63     public void setOnOff(OnOffType onOff) {
64         this.onOff = onOff == OnOffType.ON ? 1 : 0;
65     }
66
67     @Override
68     public String toString() {
69         return "brightness:" + brightness + ", color_temp:" + colorTemp + ", hue:" + hue + ", ignore_default:"
70                 + ignoreDefault + ", mode:" + mode + ", on_off:" + onOff + ", saturation:" + saturation
71                 + super.toString();
72     }
73 }