From 78c76b219e66c14ef0e9d14b2d3c961e3a6b1ed8 Mon Sep 17 00:00:00 2001 From: Andrew Fiddian-Green Date: Sat, 6 Apr 2024 12:05:16 +0100 Subject: [PATCH] [hue] fix npe (#16619) Signed-off-by: Andrew Fiddian-Green --- .../binding/hue/internal/api/dto/clip2/Power.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Power.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Power.java index 7f6c988d2db83..132c896874b4a 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Power.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Power.java @@ -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; @@ -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() {