2 * Copyright (c) 2010-2022 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.binding.tradfri.internal.model;
15 import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.DEVICE_BATTERY_LEVEL;
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;
22 import com.google.gson.JsonElement;
25 * The {@link TradfriWirelessDeviceData} class is a Java wrapper for the raw JSON data about wireless device state.
27 * @author Christoph Weitkamp - Initial contribution
30 public abstract class TradfriWirelessDeviceData extends TradfriDeviceData {
32 public TradfriWirelessDeviceData(String attributesNodeName) {
33 super(attributesNodeName);
36 public TradfriWirelessDeviceData(String attributesNodeName, JsonElement json) {
37 super(attributesNodeName, json);
40 public @Nullable DecimalType getBatteryLevel() {
41 if (generalInfo.get(DEVICE_BATTERY_LEVEL) != null) {
42 return new DecimalType(generalInfo.get(DEVICE_BATTERY_LEVEL).getAsInt());
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;