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.binding.hue.internal.api.dto.clip2;
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;
21 import com.google.gson.annotations.SerializedName;
24 * DTO for CLIP 2 power state.
26 * @author Andrew Fiddian-Green - Initial contribution
30 private @NonNullByDefault({}) @SerializedName("battery_state") String batteryState;
31 private @SerializedName("battery_level") int batteryLevel;
33 public BatteryStateType getBatteryState() {
35 return BatteryStateType.valueOf(batteryState.toUpperCase());
36 } catch (IllegalArgumentException e) {
37 return BatteryStateType.CRITICAL;
41 public int getBatteryLevel() {
45 public State getBatteryLowState() {
46 return OnOffType.from(getBatteryState() != BatteryStateType.NORMAL);
49 public State getBatteryLevelState() {
50 return new DecimalType(getBatteryLevel());