]> git.basschouten.com Git - openhab-addons.git/blob
5c6735b2d5e1983e7856322a43027c00c0fae600
[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.io.hueemulation.internal.dto;
14
15 import org.openhab.core.library.types.PercentType;
16
17 /**
18  * Hue API state object
19  *
20  * @author Dan Cunningham - Initial contribution
21  * @author David Graeff - "extended color light bulbs" support
22  *
23  */
24 public class HueStateBulb extends HueStatePlug {
25     // https://github.com/openhab/openhab-addons/issues/2881
26     // Apparently the maximum brightness is 254
27     public static final int MAX_BRI = 254;
28     public int bri = 0;
29
30     /** white color temperature, 154 (cold) - 500 (warm) */
31     public static final int MAX_CT = 500;
32     public int ct = 500;
33
34     protected HueStateBulb() {
35     }
36
37     public HueStateBulb(boolean on) {
38         super(on);
39         this.bri = on ? MAX_BRI : 1;
40     }
41
42     /**
43      * Create a hue state with the given brightness percentage
44      *
45      * @param brightness Brightness percentage
46      * @param on On value
47      */
48     public HueStateBulb(PercentType brightness, boolean on) {
49         super(on);
50         this.bri = Math.max(1, (int) (brightness.intValue() * MAX_BRI / 100.0 + 0.5));
51     }
52
53     public PercentType toBrightnessType() {
54         int bri = this.bri * 100 / MAX_BRI;
55
56         if (!this.on) {
57             bri = 0;
58         }
59         return new PercentType(bri);
60     }
61
62     @Override
63     public String toString() {
64         return "on: " + on + ", brightness: " + bri + ", reachable: " + reachable;
65     }
66 }