]> git.basschouten.com Git - openhab-addons.git/blob
7f6c988d2db83d83e2e82ac318ae24bb073f5da4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.hue.internal.api.dto.clip2;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.hue.internal.api.dto.clip2.enums.BatteryStateType;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.types.State;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * DTO for CLIP 2 power state.
25  *
26  * @author Andrew Fiddian-Green - Initial contribution
27  */
28 @NonNullByDefault
29 public class Power {
30     private @NonNullByDefault({}) @SerializedName("battery_state") String batteryState;
31     private @SerializedName("battery_level") int batteryLevel;
32
33     public BatteryStateType getBatteryState() {
34         try {
35             return BatteryStateType.valueOf(batteryState.toUpperCase());
36         } catch (IllegalArgumentException e) {
37             return BatteryStateType.CRITICAL;
38         }
39     }
40
41     public int getBatteryLevel() {
42         return batteryLevel;
43     }
44
45     public State getBatteryLowState() {
46         return OnOffType.from(getBatteryState() != BatteryStateType.NORMAL);
47     }
48
49     public State getBatteryLevelState() {
50         return new DecimalType(getBatteryLevel());
51     }
52 }