Skip to content

Commit

Permalink
[hue] fix npe (openhab#16619)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
  • Loading branch information
andrewfg authored and joni1993 committed Oct 15, 2024
1 parent 504c75b commit 78c76b2
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.hue.internal.api.dto.clip2;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hue.internal.api.dto.clip2.enums.BatteryStateType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
Expand All @@ -27,15 +28,18 @@
*/
@NonNullByDefault
public class Power {
private @NonNullByDefault({}) @SerializedName("battery_state") String batteryState;
private @Nullable @SerializedName("battery_state") String batteryState;
private @SerializedName("battery_level") int batteryLevel;

public BatteryStateType getBatteryState() {
try {
return BatteryStateType.valueOf(batteryState.toUpperCase());
} catch (IllegalArgumentException e) {
return BatteryStateType.CRITICAL;
String batteryState = this.batteryState;
if (batteryState != null) {
try {
return BatteryStateType.valueOf(batteryState.toUpperCase());
} catch (IllegalArgumentException e) {
}
}
return BatteryStateType.CRITICAL;
}

public int getBatteryLevel() {
Expand Down

0 comments on commit 78c76b2

Please sign in to comment.