Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lastnpe EEA to 2.4.0 #16875

Merged
merged 23 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private enum Type {
private final String defaultValue;
private final Optional<String> mappedTo;
private final Type type;
private Optional<String> value;
private @Nullable String value;

private OptionalConfigurationElement(String defaultValue) {
this(Type.OTHER, defaultValue, null);
Expand All @@ -389,19 +389,19 @@ private OptionalConfigurationElement(Type type, String defaultValue, @Nullable S
this.type = type;
this.defaultValue = defaultValue;
this.mappedTo = Optional.ofNullable(mappedTo);
value = Optional.empty();
}

private String getValue() {
return value.orElse(defaultValue);
String value = this.value;
return value != null ? value : this.defaultValue;
}

private void setValue(String value) {
this.value = Optional.of(value);
private void setValue(@Nullable String value) {
this.value = value;
}

private void clearValue() {
this.value = Optional.empty();
this.value = null;
}

private Optional<String> mappedTo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public JSScriptFileWatcher(final @Reference(target = WatchService.CONFIG_WATCHER

@Override
protected Optional<String> getScriptType(Path scriptFilePath) {
String scriptType = super.getScriptType(scriptFilePath).orElse(null);
if (!scriptFilePath.startsWith(getWatchPath().resolve("node_modules")) && ("js".equals(scriptType))) {
return Optional.of(scriptType);
Optional<String> scriptType = super.getScriptType(scriptFilePath);
if (scriptType.isPresent() && !scriptFilePath.startsWith(getWatchPath().resolve("node_modules"))
&& ("js".equals(scriptType.get()))) {
return scriptType;
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public JythonScriptFileWatcher(

@Override
protected Optional<String> getScriptType(Path scriptFilePath) {
String scriptType = super.getScriptType(scriptFilePath).orElse(null);
if (!scriptFilePath.startsWith(getWatchPath().resolve("lib")) && ("py".equals(scriptType))) {
return Optional.of(scriptType);
Optional<String> scriptType = super.getScriptType(scriptFilePath);
if (scriptType.isPresent() && !scriptFilePath.startsWith(getWatchPath().resolve("lib"))
&& ("py".equals(scriptType.get()))) {
return scriptType;
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public int getStationId() {
*
* @return {AirQualityJsonTime}
*/
public Optional<AirQualityTime> getTime() {
return Optional.ofNullable(time);
public @Nullable AirQualityTime getTime() {
return time;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openhab.binding.airquality.internal.api.Pollutant;
import org.openhab.binding.airquality.internal.api.Pollutant.SensitiveGroup;
import org.openhab.binding.airquality.internal.api.dto.AirQualityData;
import org.openhab.binding.airquality.internal.api.dto.AirQualityTime;
import org.openhab.binding.airquality.internal.config.AirQualityConfiguration;
import org.openhab.binding.airquality.internal.config.SensitiveGroupConfiguration;
import org.openhab.core.config.core.Configuration;
Expand Down Expand Up @@ -261,10 +262,10 @@ private State getValue(String channelId, @Nullable String groupId, AirQualityDat
double hum = data.getIaqiValue("h");
return hum != -1 ? new QuantityType<>(hum, Units.PERCENT) : UnDefType.NULL;
case TIMESTAMP:
return data.getTime()
.map(time -> (State) new DateTimeType(
time.getObservationTime().withZoneSameLocal(timeZoneProvider.getTimeZone())))
.orElse(UnDefType.NULL);
AirQualityTime time = data.getTime();
return time != null
? new DateTimeType(time.getObservationTime().withZoneSameLocal(timeZoneProvider.getTimeZone()))
: UnDefType.NULL;
case DOMINENT:
return new StringType(data.getDominentPol());
case DEW_POINT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ private void readConfigs() {
Map<String, String> configMap = OBJECT_MAPPER.readValue(configJson,
new TypeReference<HashMap<String, String>>() {
});
this.username = Optional.ofNullable(configMap.get("username")).orElse("");
this.password = Optional.ofNullable(configMap.get("password")).orElse("");
this.macAddress = Optional.ofNullable(configMap.get("macAddress")).orElse("");
this.username = configMap.getOrDefault("username", "");
this.password = configMap.getOrDefault("password", "");
this.macAddress = configMap.getOrDefault("macAddress", "");
logger.debug("Processed configJson as {} {} {}", this.username, this.password, this.macAddress);
} catch (IOException ex) {
logger.debug("IOException when reading configJson from file {}", ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -122,7 +121,8 @@ private Map<String, String> getAvailableTvChannelListFromTv() throws IOException
private String getCurrentTvChannel() throws IOException {
TvChannelDTO tvChannelDTO = OBJECT_MAPPER.readValue(connectionManager.doHttpsGet(TV_CHANNEL_PATH),
TvChannelDTO.class);
return Optional.ofNullable(tvChannelDTO.getChannel()).map(ChannelDTO::getName).orElse("NA");
ChannelDTO channel = tvChannelDTO.getChannel();
return channel != null ? channel.getName() : "NA";
}

private void switchTvChannel(Command command) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public void onComplete(Result result) {
String rBody = getContentAsString();
logger.trace("({}) requestCompleted '{}'", uid, rBody);
// Handle result
handleHttpSuccessResponse(rBody, command);
if (rBody != null) {
handleHttpSuccessResponse(rBody, command);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public void onFailure(@NonNullByDefault({}) Response response, @NonNullByDefault
public void onComplete(@NonNullByDefault({}) Result result) {
String content = getContentAsString();
logger.debug("{} response complete: {}", result.getRequest().getMethod(), content);
callback.execute(result.getResponse().getStatus(), content);
if (content != null) {
callback.execute(result.getResponse().getStatus(), content);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -358,7 +357,7 @@ public List<Device> getDevices() throws InterruptedException {
Type collectionType = new TypeToken<ArrayList<Device>>() {
}.getType();
List<Device> nullableDevices = GsonUtils.DEFAULT_GSON_INSTANCE.fromJson(content, collectionType);
return Optional.ofNullable(nullableDevices).orElse(Collections.emptyList());
return nullableDevices != null ? nullableDevices : Collections.emptyList();
} catch (TimeoutException | ExecutionException e) {
logger.debug("Request devices failed because of {}!", e.getMessage(), e);
return Collections.emptyList();
Expand Down Expand Up @@ -391,7 +390,7 @@ public List<UserDefinedState> getUserStates() throws InterruptedException {
}.getType();
List<UserDefinedState> nullableUserStates = GsonUtils.DEFAULT_GSON_INSTANCE.fromJson(content,
collectionType);
return Optional.ofNullable(nullableUserStates).orElse(Collections.emptyList());
return nullableUserStates != null ? nullableUserStates : Collections.emptyList();
} catch (TimeoutException | ExecutionException e) {
logger.debug("Request user-defined states failed because of {}!", e.getMessage(), e);
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void onComplete(@Nullable Result result) {
* @param content Content of the response
*/
private void onLongPollComplete(BoschHttpClient httpClient, String subscriptionId, @Nullable Result result,
String content) {
@Nullable String content) {
// Check if thing is still online
if (this.aborted) {
logger.debug("Canceling long polling for subscription id {} because it was aborted", subscriptionId);
Expand Down Expand Up @@ -211,7 +211,7 @@ private void onLongPollComplete(BoschHttpClient httpClient, String subscriptionI
* @param subscriptionId Id of subscription the response is for
* @param content Content of the response
*/
private void handleLongPollResponse(BoschHttpClient httpClient, String subscriptionId, String content) {
private void handleLongPollResponse(BoschHttpClient httpClient, String subscriptionId, @Nullable String content) {
logger.debug("Long poll response: {}", content);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -214,7 +215,8 @@ protected void addDevices(List<Device> devices, List<Room> rooms) {
}

protected String getRoomNameForDevice(Device device, List<Room> rooms) {
return rooms.stream().filter(room -> room.id.equals(device.roomId)).findAny().map(r -> r.name).orElse("");
return Objects.requireNonNull(
lsiepel marked this conversation as resolved.
Show resolved Hide resolved
rooms.stream().filter(room -> room.id.equals(device.roomId)).findAny().map(r -> r.name).orElse(""));
}

protected void addDevice(Device device, String roomName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.net.SocketTimeoutException;
import java.net.URI;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -154,7 +155,8 @@ public void onComplete(Result result) {
f.completeExceptionally(new CoronaStatsPollingException("Request failed", e));
}
} else if (response.getStatus() != 200) {
f.completeExceptionally(new CoronaStatsPollingException(getContentAsString()));
f.completeExceptionally(
new CoronaStatsPollingException(Objects.requireNonNull(getContentAsString())));
} else {
try {
CoronaStats coronaStatsJSON = gson.fromJson(getContentAsString(), CoronaStats.class);
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.Optional;

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 = Optional.ofNullable(responseMap.get("mac")).orElse("");
info.ret = Optional.ofNullable(responseMap.get("ret")).orElse("");
info.ssid = Optional.ofNullable(responseMap.get("ssid")).orElse("");
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 @@ -14,6 +14,7 @@

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

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -59,23 +60,23 @@ public static ControlInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

ControlInfo info = new ControlInfo();
info.ret = Optional.ofNullable(responseMap.get("ret")).orElse("");
info.ret = responseMap.getOrDefault("ret", "");
info.power = "1".equals(responseMap.get("pow"));
info.mode = Optional.ofNullable(responseMap.get("mode")).flatMap(value -> InfoParser.parseInt(value))
.map(value -> Mode.fromValue(value)).orElse(Mode.AUTO);
info.mode = Objects.requireNonNull(Optional.ofNullable(responseMap.get("mode"))
.flatMap(value -> InfoParser.parseInt(value)).map(value -> Mode.fromValue(value)).orElse(Mode.AUTO));
// Normalize AUTO1 and AUTO7 to AUTO
if (info.mode == Mode.AUTO1 || info.mode == Mode.AUTO7) {
info.autoModeValue = info.mode.getValue();
info.mode = Mode.AUTO;
}
info.temp = Optional.ofNullable(responseMap.get("stemp")).flatMap(value -> InfoParser.parseDouble(value));
info.fanSpeed = Optional.ofNullable(responseMap.get("f_rate")).map(value -> FanSpeed.fromValue(value))
.orElse(FanSpeed.AUTO);
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)
if (response.contains("f_dir=")) {
info.fanMovement = Optional.ofNullable(responseMap.get("f_dir"))
.flatMap(value -> InfoParser.parseInt(value)).map(value -> FanMovement.fromValue(value))
.orElse(FanMovement.STOPPED);
info.fanMovement = Objects.requireNonNull(
Optional.ofNullable(responseMap.get("f_dir")).flatMap(value -> InfoParser.parseInt(value))
.map(value -> FanMovement.fromValue(value)).orElse(FanMovement.STOPPED));
} else {
info.separatedDirectionParams = true;
String ud = responseMap.get("f_dir_ud");
Expand All @@ -89,8 +90,8 @@ public static ControlInfo parse(String response) {

info.targetHumidity = Optional.ofNullable(responseMap.get("shum")).flatMap(value -> InfoParser.parseInt(value));

info.advancedMode = Optional.ofNullable(responseMap.get("adv")).map(value -> AdvancedMode.fromValue(value))
.orElse(AdvancedMode.UNKNOWN);
info.advancedMode = Objects.requireNonNull(Optional.ofNullable(responseMap.get("adv"))
.map(value -> AdvancedMode.fromValue(value)).orElse(AdvancedMode.UNKNOWN));
return info;
}

Expand All @@ -110,7 +111,7 @@ public Map<String, String> getParamString() {
params.put("f_dir", Integer.toString(fanMovement.getValue()));
}
params.put("stemp", temp.orElse(20.0).toString());
params.put("shum", targetHumidity.map(value -> value.toString()).orElse(""));
params.put("shum", Objects.requireNonNull(targetHumidity.map(value -> value.toString()).orElse("")));

return params;
}
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.Optional;

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 = Optional.ofNullable(responseMap.get("mac")).orElse("");
info.ret = Optional.ofNullable(responseMap.get("ret")).orElse("");
info.ssid = Optional.ofNullable(responseMap.get("ssid")).orElse("");
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 @@ -14,6 +14,7 @@

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

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -54,18 +55,20 @@ public static AirbaseControlInfo parse(String response) {
Map<String, String> responseMap = InfoParser.parse(response);

AirbaseControlInfo info = new AirbaseControlInfo();
info.ret = Optional.ofNullable(responseMap.get("ret")).orElse("");
info.ret = responseMap.getOrDefault("ret", "");
info.power = "1".equals(responseMap.get("pow"));
info.mode = Optional.ofNullable(responseMap.get("mode")).flatMap(value -> InfoParser.parseInt(value))
.map(value -> AirbaseMode.fromValue(value)).orElse(AirbaseMode.AUTO);
info.mode = Objects.requireNonNull(
Optional.ofNullable(responseMap.get("mode")).flatMap(value -> InfoParser.parseInt(value))
.map(value -> AirbaseMode.fromValue(value)).orElse(AirbaseMode.AUTO));
info.temp = Optional.ofNullable(responseMap.get("stemp")).flatMap(value -> InfoParser.parseDouble(value));
int fRate = Optional.ofNullable(responseMap.get("f_rate")).flatMap(value -> InfoParser.parseInt(value))
.orElse(1);
boolean fAuto = "1".equals(responseMap.getOrDefault("f_auto", "0"));
boolean fAirside = "1".equals(responseMap.getOrDefault("f_airside", "0"));
info.fanSpeed = AirbaseFanSpeed.fromValue(fRate, fAuto, fAirside);
info.fanMovement = Optional.ofNullable(responseMap.get("f_dir")).flatMap(value -> InfoParser.parseInt(value))
.map(value -> AirbaseFanMovement.fromValue(value)).orElse(AirbaseFanMovement.STOPPED);
info.fanMovement = Objects.requireNonNull(
Optional.ofNullable(responseMap.get("f_dir")).flatMap(value -> InfoParser.parseInt(value))
.map(value -> AirbaseFanMovement.fromValue(value)).orElse(AirbaseFanMovement.STOPPED));
info.targetHumidity = Optional.ofNullable(responseMap.get("shum")).flatMap(value -> InfoParser.parseInt(value));
return info;
}
Expand All @@ -79,7 +82,7 @@ public Map<String, String> getParamString() {
params.put("f_airside", fanSpeed.getAirside() ? "1" : "0");
params.put("f_dir", Integer.toString(fanMovement.getValue()));
params.put("stemp", temp.orElse(20.0).toString());
params.put("shum", targetHumidity.map(value -> value.toString()).orElse(""));
params.put("shum", Objects.requireNonNull(targetHumidity.map(value -> value.toString()).orElse("")));

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

AirbaseModelInfo info = new AirbaseModelInfo();
info.ret = Optional.ofNullable(responseMap.get("ret")).orElse("");
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
Loading
Loading