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.io.hueemulation.internal.dto;
15 import org.openhab.core.library.types.PercentType;
18 * Hue API state object
20 * @author Dan Cunningham - Initial contribution
21 * @author David Graeff - "extended color light bulbs" support
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;
30 /** white color temperature, 154 (cold) - 500 (warm) */
31 public static final int MAX_CT = 500;
34 protected HueStateBulb() {
37 public HueStateBulb(boolean on) {
39 this.bri = on ? MAX_BRI : 1;
43 * Create a hue state with the given brightness percentage
45 * @param brightness Brightness percentage
48 public HueStateBulb(PercentType brightness, boolean on) {
50 this.bri = Math.max(1, (int) (brightness.intValue() * MAX_BRI / 100.0 + 0.5));
53 public PercentType toBrightnessType() {
54 int bri = this.bri * 100 / MAX_BRI;
59 return new PercentType(bri);
63 public String toString() {
64 return "on: " + on + ", brightness: " + bri + ", reachable: " + reachable;