]> git.basschouten.com Git - openhab-addons.git/blob
f2ee975738c89df78a12a75456ecad86a7a96441
[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.lifx.internal.dto;
14
15 import org.openhab.core.library.types.OnOffType;
16
17 /**
18  * Represents light power states (on or off).
19  *
20  * @author Tim Buckley - Initial contribution
21  * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
22  * @author Wouter Born - Added OnOffType conversion methods
23  */
24 public enum PowerState {
25
26     ON(0xFFFF),
27     OFF(0x0000);
28
29     private final int value;
30
31     private PowerState(int value) {
32         this.value = value;
33     }
34
35     /**
36      * Gets the integer value of this power state.
37      *
38      * @return the integer value
39      */
40     public int getValue() {
41         return value;
42     }
43
44     public static PowerState fromValue(int value) {
45         // a response can have a power level between 0 and 65535 when the light
46         // has just been switched ON or OFF
47         return value == OFF.value ? OFF : ON;
48     }
49
50     public static PowerState fromOnOffType(OnOffType onOff) {
51         return onOff == OnOffType.ON ? ON : OFF;
52     }
53
54     public OnOffType toOnOffType() {
55         return OnOffType.from(this == ON);
56     }
57 }