Skip to content

Commit

Permalink
Merge pull request #2 from jimtng/daikin-last-npe
Browse files Browse the repository at this point in the history
simplify daikin
  • Loading branch information
lsiepel authored Jun 23, 2024
2 parents 6faf6ea + abae099 commit 38f0fd0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.slf4j.Logger;
Expand Down Expand Up @@ -43,9 +42,9 @@ public static BasicInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

BasicInfo info = new BasicInfo();
info.mac = Objects.requireNonNullElse(responseMap.get("mac"), "");
info.ret = Objects.requireNonNullElse(responseMap.get("ret"), "");
info.ssid = Objects.requireNonNullElse(responseMap.get("ssid"), "");
info.mac = responseMap.getOrDefault("mac", "");
info.ret = responseMap.getOrDefault("ret", "");
info.ssid = responseMap.getOrDefault("ssid", "");
return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static ControlInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

ControlInfo info = new ControlInfo();
info.ret = Objects.requireNonNull(Optional.ofNullable(responseMap.get("ret")).orElse(""));
info.ret = responseMap.getOrDefault("ret", "");
info.power = "1".equals(responseMap.get("pow"));
info.mode = Objects.requireNonNull(Optional.ofNullable(responseMap.get("mode"))
.flatMap(value -> InfoParser.parseInt(value)).map(value -> Mode.fromValue(value)).orElse(Mode.AUTO));
Expand All @@ -69,8 +69,7 @@ public static ControlInfo parse(String response) {
info.autoModeValue = info.mode.getValue();
info.mode = Mode.AUTO;
}
info.temp = Objects.requireNonNull(
Optional.ofNullable(responseMap.get("stemp")).flatMap(value -> InfoParser.parseDouble(value)));
info.temp = Optional.ofNullable(responseMap.get("stemp")).flatMap(value -> InfoParser.parseDouble(value));
info.fanSpeed = Objects.requireNonNull(Optional.ofNullable(responseMap.get("f_rate"))
.map(value -> FanSpeed.fromValue(value)).orElse(FanSpeed.AUTO));
// determine if device has combined direction (f_dir) or separated directions (f_dir_ud/f_dir_lr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.daikin.internal.api.InfoParser;
Expand Down Expand Up @@ -44,9 +43,9 @@ public static AirbaseBasicInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

AirbaseBasicInfo info = new AirbaseBasicInfo();
info.mac = Objects.requireNonNullElse(responseMap.get("mac"), "");
info.ret = Objects.requireNonNullElse(responseMap.get("ret"), "");
info.ssid = Objects.requireNonNullElse(responseMap.get("ssid"), "");
info.mac = responseMap.getOrDefault("mac", "");
info.ret = responseMap.getOrDefault("ret", "");
info.ssid = responseMap.getOrDefault("ssid", "");
return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static AirbaseControlInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

AirbaseControlInfo info = new AirbaseControlInfo();
info.ret = Objects.requireNonNullElse(responseMap.get("ret"), "");
info.ret = responseMap.getOrDefault("ret", "");
info.power = "1".equals(responseMap.get("pow"));
info.mode = Objects.requireNonNull(
Optional.ofNullable(responseMap.get("mode")).flatMap(value -> InfoParser.parseInt(value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -49,7 +48,7 @@ public static AirbaseModelInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

AirbaseModelInfo info = new AirbaseModelInfo();
info.ret = Objects.requireNonNullElse(responseMap.get("ret"), "");
info.ret = responseMap.getOrDefault("ret", "");
info.zonespresent = Optional.ofNullable(responseMap.get("en_zone")).flatMap(value -> InfoParser.parseInt(value))
.orElse(0);
info.commonzone = Optional.ofNullable(responseMap.get("en_common_zone"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -46,8 +45,8 @@ public static AirbaseZoneInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

AirbaseZoneInfo info = new AirbaseZoneInfo();
info.zonenames = Objects.requireNonNullElse(responseMap.get("zone_name"), "");
String zoneinfo = Objects.requireNonNullElse(responseMap.get("zone_onoff"), "");
info.zonenames = responseMap.getOrDefault("zone_name", "");
String zoneinfo = responseMap.getOrDefault("zone_onoff", "");

String[] zones = zoneinfo.split(";");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -135,7 +134,7 @@ private boolean receivePacketAndDiscover(DatagramSocket socket) {
Map<String, String> parsedData = InfoParser.parse(data);
Boolean secure = "1".equals(parsedData.get("en_secure"));
String thingId = Objects.requireNonNullElse(parsedData.get("ssid"), host.replace(".", "_"));
String mac = Optional.ofNullable(parsedData.get("mac")).orElse("");
String mac = parsedData.getOrDefault("mac", "");
String uuid = mac.isEmpty() ? UUID.randomUUID().toString()
: UUID.nameUUIDFromBytes(mac.getBytes()).toString();

Expand Down

0 comments on commit 38f0fd0

Please sign in to comment.