]> git.basschouten.com Git - openhab-addons.git/blob
9f36fc713c2b9461b001284e22e2e25747e65dc4
[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.tradfri.internal.model;
14
15 import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.DEVICE_BATTERY_LEVEL;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.library.types.DecimalType;
20 import org.openhab.core.library.types.OnOffType;
21
22 import com.google.gson.JsonElement;
23
24 /**
25  * The {@link TradfriWirelessDeviceData} class is a Java wrapper for the raw JSON data about wireless device state.
26  *
27  * @author Christoph Weitkamp - Initial contribution
28  */
29 @NonNullByDefault
30 public abstract class TradfriWirelessDeviceData extends TradfriDeviceData {
31
32     public TradfriWirelessDeviceData(String attributesNodeName) {
33         super(attributesNodeName);
34     }
35
36     public TradfriWirelessDeviceData(String attributesNodeName, JsonElement json) {
37         super(attributesNodeName, json);
38     }
39
40     public @Nullable DecimalType getBatteryLevel() {
41         if (generalInfo.get(DEVICE_BATTERY_LEVEL) != null) {
42             return new DecimalType(generalInfo.get(DEVICE_BATTERY_LEVEL).getAsInt());
43         } else {
44             return null;
45         }
46     }
47
48     public @Nullable OnOffType getBatteryLow() {
49         if (generalInfo.get(DEVICE_BATTERY_LEVEL) != null) {
50             return generalInfo.get(DEVICE_BATTERY_LEVEL).getAsInt() <= 10 ? OnOffType.ON : OnOffType.OFF;
51         } else {
52             return null;
53         }
54     }
55 }