Skip to content

Commit 5e0e9ce

Browse files
authored
Update lastnpe EEA to 2.4.0 (openhab#16875)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
1 parent 7296b38 commit 5e0e9ce

File tree

127 files changed

+584
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+584
-411
lines changed

bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private enum Type {
379379
private final String defaultValue;
380380
private final Optional<String> mappedTo;
381381
private final Type type;
382-
private Optional<String> value;
382+
private @Nullable String value;
383383

384384
private OptionalConfigurationElement(String defaultValue) {
385385
this(Type.OTHER, defaultValue, null);
@@ -389,19 +389,19 @@ private OptionalConfigurationElement(Type type, String defaultValue, @Nullable S
389389
this.type = type;
390390
this.defaultValue = defaultValue;
391391
this.mappedTo = Optional.ofNullable(mappedTo);
392-
value = Optional.empty();
393392
}
394393

395394
private String getValue() {
396-
return value.orElse(defaultValue);
395+
String value = this.value;
396+
return value != null ? value : this.defaultValue;
397397
}
398398

399-
private void setValue(String value) {
400-
this.value = Optional.of(value);
399+
private void setValue(@Nullable String value) {
400+
this.value = value;
401401
}
402402

403403
private void clearValue() {
404-
this.value = Optional.empty();
404+
this.value = null;
405405
}
406406

407407
private Optional<String> mappedTo() {

bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/fs/watch/JSScriptFileWatcher.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public JSScriptFileWatcher(final @Reference(target = WatchService.CONFIG_WATCHER
4848

4949
@Override
5050
protected Optional<String> getScriptType(Path scriptFilePath) {
51-
String scriptType = super.getScriptType(scriptFilePath).orElse(null);
52-
if (!scriptFilePath.startsWith(getWatchPath().resolve("node_modules")) && ("js".equals(scriptType))) {
53-
return Optional.of(scriptType);
51+
Optional<String> scriptType = super.getScriptType(scriptFilePath);
52+
if (scriptType.isPresent() && !scriptFilePath.startsWith(getWatchPath().resolve("node_modules"))
53+
&& ("js".equals(scriptType.get()))) {
54+
return scriptType;
5455
}
5556
return Optional.empty();
5657
}

bundles/org.openhab.automation.jythonscripting/src/main/java/org/openhab/automation/jythonscripting/internal/watch/JythonScriptFileWatcher.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public JythonScriptFileWatcher(
4848

4949
@Override
5050
protected Optional<String> getScriptType(Path scriptFilePath) {
51-
String scriptType = super.getScriptType(scriptFilePath).orElse(null);
52-
if (!scriptFilePath.startsWith(getWatchPath().resolve("lib")) && ("py".equals(scriptType))) {
53-
return Optional.of(scriptType);
51+
Optional<String> scriptType = super.getScriptType(scriptFilePath);
52+
if (scriptType.isPresent() && !scriptFilePath.startsWith(getWatchPath().resolve("lib"))
53+
&& ("py".equals(scriptType.get()))) {
54+
return scriptType;
5455
}
5556
return Optional.empty();
5657
}

bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/api/dto/AirQualityData.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public int getStationId() {
6262
*
6363
* @return {AirQualityJsonTime}
6464
*/
65-
public Optional<AirQualityTime> getTime() {
66-
return Optional.ofNullable(time);
65+
public @Nullable AirQualityTime getTime() {
66+
return time;
6767
}
6868

6969
/**

bundles/org.openhab.binding.airquality/src/main/java/org/openhab/binding/airquality/internal/handler/AirQualityStationHandler.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.openhab.binding.airquality.internal.api.Pollutant;
3636
import org.openhab.binding.airquality.internal.api.Pollutant.SensitiveGroup;
3737
import org.openhab.binding.airquality.internal.api.dto.AirQualityData;
38+
import org.openhab.binding.airquality.internal.api.dto.AirQualityTime;
3839
import org.openhab.binding.airquality.internal.config.AirQualityConfiguration;
3940
import org.openhab.binding.airquality.internal.config.SensitiveGroupConfiguration;
4041
import org.openhab.core.config.core.Configuration;
@@ -261,10 +262,10 @@ private State getValue(String channelId, @Nullable String groupId, AirQualityDat
261262
double hum = data.getIaqiValue("h");
262263
return hum != -1 ? new QuantityType<>(hum, Units.PERCENT) : UnDefType.NULL;
263264
case TIMESTAMP:
264-
return data.getTime()
265-
.map(time -> (State) new DateTimeType(
266-
time.getObservationTime().withZoneSameLocal(timeZoneProvider.getTimeZone())))
267-
.orElse(UnDefType.NULL);
265+
AirQualityTime time = data.getTime();
266+
return time != null
267+
? new DateTimeType(time.getObservationTime().withZoneSameLocal(timeZoneProvider.getTimeZone()))
268+
: UnDefType.NULL;
268269
case DOMINENT:
269270
return new StringType(data.getDominentPol());
270271
case DEW_POINT:

bundles/org.openhab.binding.androidtv/src/main/java/org/openhab/binding/androidtv/internal/protocol/philipstv/PhilipsTVConnectionManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ private void readConfigs() {
230230
Map<String, String> configMap = OBJECT_MAPPER.readValue(configJson,
231231
new TypeReference<HashMap<String, String>>() {
232232
});
233-
this.username = Optional.ofNullable(configMap.get("username")).orElse("");
234-
this.password = Optional.ofNullable(configMap.get("password")).orElse("");
235-
this.macAddress = Optional.ofNullable(configMap.get("macAddress")).orElse("");
233+
this.username = configMap.getOrDefault("username", "");
234+
this.password = configMap.getOrDefault("password", "");
235+
this.macAddress = configMap.getOrDefault("macAddress", "");
236236
logger.debug("Processed configJson as {} {} {}", this.username, this.password, this.macAddress);
237237
} catch (IOException ex) {
238238
logger.debug("IOException when reading configJson from file {}", ex.getMessage());

bundles/org.openhab.binding.androidtv/src/main/java/org/openhab/binding/androidtv/internal/protocol/philipstv/service/TvChannelService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.IOException;
2020
import java.util.Map;
21-
import java.util.Optional;
2221
import java.util.concurrent.ConcurrentMap;
2322
import java.util.function.Function;
2423
import java.util.stream.Collectors;
@@ -122,7 +121,8 @@ private Map<String, String> getAvailableTvChannelListFromTv() throws IOException
122121
private String getCurrentTvChannel() throws IOException {
123122
TvChannelDTO tvChannelDTO = OBJECT_MAPPER.readValue(connectionManager.doHttpsGet(TV_CHANNEL_PATH),
124123
TvChannelDTO.class);
125-
return Optional.ofNullable(tvChannelDTO.getChannel()).map(ChannelDTO::getName).orElse("NA");
124+
ChannelDTO channel = tvChannelDTO.getChannel();
125+
return channel != null ? channel.getName() : "NA";
126126
}
127127

128128
private void switchTvChannel(Command command) throws IOException {

bundles/org.openhab.binding.argoclima/src/main/java/org/openhab/binding/argoclima/internal/configuration/ArgoClimaConfigurationBase.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,10 @@ public final String validate() {
373373
validateInternal();
374374
return "";
375375
} catch (Exception e) {
376-
var msg = Optional.ofNullable(e.getLocalizedMessage());
376+
var msg = e.getLocalizedMessage();
377377
var cause = Optional.ofNullable(e.getCause());
378-
return msg.orElse("Unknown exception, message is null") // The message theoretically can be null
379-
// (Exception's i-face) but in practice never is, so
380-
// keeping cryptic non-i18nized text instead of
381-
// throwing
382-
.concat(cause.map(c -> "\n\t[" + c.getClass().getSimpleName() + "]").orElse(""));
378+
return Objects.requireNonNullElse(msg, "Unknown exception, message is null").concat(
379+
Objects.requireNonNull(cause.map(c -> "\n\t[" + c.getClass().getSimpleName() + "]").orElse("")));
383380
}
384381
}
385382
}

bundles/org.openhab.binding.argoclima/src/main/java/org/openhab/binding/argoclima/internal/device/api/ArgoClimaRemoteDevice.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.nio.charset.StandardCharsets;
1919
import java.text.MessageFormat;
2020
import java.util.Objects;
21-
import java.util.Optional;
2221
import java.util.SortedMap;
2322
import java.util.function.Consumer;
2423
import java.util.regex.Pattern;
@@ -142,8 +141,8 @@ protected DeviceStatus extractDeviceStatusFromResponse(String apiResponse) throw
142141

143142
// Group names must match regex above
144143
var properties = new DeviceProperties(Objects.requireNonNull(matcher.group("localIP")),
145-
Objects.requireNonNull(matcher.group("lastSeen")), Optional.of(
146-
getWebUiUrl(Objects.requireNonNull(this.oemServerHostname.getHostName()), this.oemServerPort)));
144+
Objects.requireNonNull(matcher.group("lastSeen")),
145+
getWebUiUrl(Objects.requireNonNull(this.oemServerHostname.getHostName()), this.oemServerPort));
147146

148147
return new DeviceStatus(Objects.requireNonNull(matcher.group("commands")), properties, i18nProvider);
149148
}

bundles/org.openhab.binding.argoclima/src/main/java/org/openhab/binding/argoclima/internal/device/api/DeviceStatus.java

+91-45
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import java.time.format.DateTimeFormatter;
2121
import java.time.format.FormatStyle;
2222
import java.util.Collections;
23-
import java.util.Optional;
23+
import java.util.Objects;
2424
import java.util.SortedMap;
2525
import java.util.TreeMap;
2626

2727
import org.eclipse.jdt.annotation.NonNullByDefault;
28+
import org.eclipse.jdt.annotation.Nullable;
2829
import org.openhab.binding.argoclima.internal.ArgoClimaBindingConstants;
2930
import org.openhab.binding.argoclima.internal.ArgoClimaTranslationProvider;
3031
import org.openhab.binding.argoclima.internal.configuration.ArgoClimaConfigurationRemote;
@@ -53,17 +54,29 @@ class DeviceStatus {
5354
*/
5455
static class DeviceProperties {
5556
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceProperties.class);
56-
private final Optional<String> localIP;
57-
private final Optional<OffsetDateTime> lastSeen;
58-
private final Optional<URL> vendorUiUrl;
59-
private Optional<String> cpuId = Optional.empty();
60-
private Optional<String> webUiUsername = Optional.empty();
61-
private Optional<String> webUiPassword = Optional.empty();
62-
private Optional<String> unitFWVersion = Optional.empty();
63-
private Optional<String> wifiFWVersion = Optional.empty();
64-
private Optional<String> wifiSSID = Optional.empty();
65-
private Optional<String> wifiPassword = Optional.empty();
66-
private Optional<String> localTime = Optional.empty();
57+
58+
private OffsetDateTime lastSeen = OffsetDateTime.MIN;
59+
60+
@Nullable
61+
private final String localIP;
62+
@Nullable
63+
private final URL vendorUiUrl;
64+
@Nullable
65+
private String cpuId;
66+
@Nullable
67+
private String webUiUsername;
68+
@Nullable
69+
private String webUiPassword;
70+
@Nullable
71+
private String unitFWVersion;
72+
@Nullable
73+
private String wifiFWVersion;
74+
@Nullable
75+
private String wifiSSID;
76+
@Nullable
77+
private String wifiPassword;
78+
@Nullable
79+
private String localTime;
6780

6881
/**
6982
* C-tor (from remote server query response)
@@ -72,8 +85,8 @@ static class DeviceProperties {
7285
* @param lastSeenStr The ISO-8601-formatted date/time of last update (or empty string if N/A)
7386
* @param vendorUiAddress The optional full URL to vendor's web UI
7487
*/
75-
public DeviceProperties(String localIP, String lastSeenStr, Optional<URL> vendorUiAddress) {
76-
this.localIP = localIP.isEmpty() ? Optional.empty() : Optional.of(localIP);
88+
public DeviceProperties(String localIP, String lastSeenStr, URL vendorUiAddress) {
89+
this.localIP = !localIP.isBlank() ? localIP : null;
7790
this.vendorUiUrl = vendorUiAddress;
7891
this.lastSeen = dateFromISOString(lastSeenStr, "LastSeen");
7992
}
@@ -84,9 +97,9 @@ public DeviceProperties(String localIP, String lastSeenStr, Optional<URL> vendor
8497
* @param lastSeen The date/time of last update (when the response got received)
8598
*/
8699
public DeviceProperties(OffsetDateTime lastSeen) {
87-
this.localIP = Optional.empty();
88-
this.lastSeen = Optional.of(lastSeen);
89-
this.vendorUiUrl = Optional.empty();
100+
this.localIP = null;
101+
this.lastSeen = lastSeen;
102+
this.vendorUiUrl = null;
90103
}
91104

92105
/**
@@ -96,31 +109,32 @@ public DeviceProperties(OffsetDateTime lastSeen) {
96109
* @param properties The intercepted device-side request (most rich with properties)
97110
*/
98111
public DeviceProperties(OffsetDateTime lastSeen, DeviceSideUpdateDTO properties) {
99-
this.localIP = Optional.of(properties.setup.localIP.orElse(properties.deviceIp));
100-
this.lastSeen = Optional.of(lastSeen);
101-
this.vendorUiUrl = Optional.of(ArgoClimaRemoteDevice.getWebUiUrl(properties.remoteServerId, 80));
102-
this.cpuId = Optional.of(properties.cpuId);
103-
this.webUiUsername = Optional.of(properties.setup.username.orElse(properties.username));
104-
this.webUiPassword = properties.setup.password;
105-
this.unitFWVersion = Optional.of(properties.setup.unitVersionInstalled.orElse(properties.unitFirmware));
106-
this.wifiFWVersion = Optional.of(properties.setup.wifiVersionInstalled.orElse(properties.wifiFirmware));
107-
this.wifiSSID = properties.setup.wifiSSID;
108-
this.wifiPassword = properties.setup.wifiPassword;
109-
this.localTime = properties.setup.localTime;
112+
this.localIP = Objects.requireNonNull(properties.setup.localIP.orElse(properties.deviceIp));
113+
this.lastSeen = lastSeen;
114+
this.vendorUiUrl = ArgoClimaRemoteDevice.getWebUiUrl(properties.remoteServerId, 80);
115+
this.cpuId = properties.cpuId;
116+
this.webUiUsername = properties.setup.username.orElse(properties.username);
117+
this.webUiPassword = properties.setup.password.get();
118+
this.unitFWVersion = Objects
119+
.requireNonNull(properties.setup.unitVersionInstalled.orElse(properties.unitFirmware));
120+
this.wifiFWVersion = properties.setup.wifiVersionInstalled.orElse(properties.wifiFirmware);
121+
this.wifiSSID = properties.setup.wifiSSID.get();
122+
this.wifiPassword = properties.setup.wifiPassword.get();
123+
this.localTime = properties.setup.localTime.get();
110124
}
111125

112-
private static Optional<OffsetDateTime> dateFromISOString(String isoDateTime, String contextualName) {
126+
private static OffsetDateTime dateFromISOString(String isoDateTime, String contextualName) {
113127
if (isoDateTime.isEmpty()) {
114-
return Optional.empty();
128+
return OffsetDateTime.MIN;
115129
}
116130

117131
try {
118-
return Optional.of(OffsetDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(isoDateTime)));
132+
return OffsetDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(isoDateTime));
119133
} catch (DateTimeException ex) {
120134
// Swallowing exception (no need to handle - proceed as if the date was never provided)
121135
LOGGER.debug("Failed to parse [{}] timestamp: {}. Exception: {}", contextualName, isoDateTime,
122136
ex.getMessage());
123-
return Optional.empty();
137+
return OffsetDateTime.MIN;
124138
}
125139
}
126140

@@ -135,7 +149,7 @@ private static String dateTimeToStringLocal(OffsetDateTime toConvert, TimeZonePr
135149
* @return Time elapsed since last device-side update
136150
*/
137151
Duration getLastSeenDelta() {
138-
return Duration.between(lastSeen.orElse(OffsetDateTime.MIN).toInstant(), Instant.now());
152+
return Duration.between(lastSeen.toInstant(), Instant.now());
139153
}
140154

141155
/**
@@ -147,18 +161,50 @@ Duration getLastSeenDelta() {
147161
SortedMap<String, String> asPropertiesRaw(TimeZoneProvider timeZoneProvider) {
148162
var result = new TreeMap<String, String>();
149163

150-
this.lastSeen.map((value) -> result.put(ArgoClimaBindingConstants.PROPERTY_LAST_SEEN,
151-
dateTimeToStringLocal(value, timeZoneProvider)));
152-
this.localIP.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_IP_ADDRESS, value));
153-
this.vendorUiUrl.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI, value.toString()));
154-
this.cpuId.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_CPU_ID, value));
155-
this.webUiUsername.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_USERNAME, value));
156-
this.webUiPassword.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_PASSWORD, value));
157-
this.unitFWVersion.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_UNIT_FW, value));
158-
this.wifiFWVersion.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_FW, value));
159-
this.wifiSSID.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_SSID, value));
160-
this.wifiPassword.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_PASSWORD, value));
161-
this.localTime.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_TIME, value));
164+
String localIP = this.localIP;
165+
String cpuId = this.cpuId;
166+
URL vendorUiUrl = this.vendorUiUrl;
167+
String webUiUsername = this.webUiUsername;
168+
String webUiPassword = this.webUiPassword;
169+
String unitFWVersion = this.unitFWVersion;
170+
String wifiFWVersion = this.wifiFWVersion;
171+
String wifiSSID = this.wifiSSID;
172+
String wifiPassword = this.wifiPassword;
173+
String localTime = this.localTime;
174+
175+
result.put(ArgoClimaBindingConstants.PROPERTY_LAST_SEEN,
176+
dateTimeToStringLocal(this.lastSeen, timeZoneProvider));
177+
178+
if (localIP != null) {
179+
result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_IP_ADDRESS, localIP);
180+
}
181+
if (cpuId != null) {
182+
result.put(ArgoClimaBindingConstants.PROPERTY_CPU_ID, cpuId);
183+
}
184+
if (vendorUiUrl != null) {
185+
result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI, vendorUiUrl.toString());
186+
}
187+
if (webUiUsername != null) {
188+
result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_USERNAME, webUiUsername);
189+
}
190+
if (webUiPassword != null) {
191+
result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_PASSWORD, webUiPassword);
192+
}
193+
if (unitFWVersion != null) {
194+
result.put(ArgoClimaBindingConstants.PROPERTY_UNIT_FW, unitFWVersion);
195+
}
196+
if (wifiFWVersion != null) {
197+
result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_FW, wifiFWVersion);
198+
}
199+
if (wifiSSID != null) {
200+
result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_SSID, wifiSSID);
201+
}
202+
if (wifiPassword != null) {
203+
result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_PASSWORD, wifiPassword);
204+
}
205+
if (localTime != null) {
206+
result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_TIME, localTime);
207+
}
162208
return Collections.unmodifiableSortedMap(result);
163209
}
164210
}

bundles/org.openhab.binding.argoclima/src/main/java/org/openhab/binding/argoclima/internal/device/api/protocol/elements/ArgoApiElementBase.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.time.Duration;
1616
import java.time.Instant;
17+
import java.util.Objects;
1718
import java.util.Optional;
1819

1920
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -413,8 +414,9 @@ public final boolean hasInFlightCommand() {
413414

414415
private final String getInFlightCommandsRawValueOrDefault() {
415416
final String valueNotAvailablePlaceholder = "N/A";
416-
return inFlightCommand.map(c -> c.deviceCommandToSend.orElse(valueNotAvailablePlaceholder))
417-
.orElse(valueNotAvailablePlaceholder);
417+
return Objects
418+
.requireNonNull(inFlightCommand.map(c -> c.deviceCommandToSend.orElse(valueNotAvailablePlaceholder))
419+
.orElse(valueNotAvailablePlaceholder));
418420
}
419421

420422
/////////////

bundles/org.openhab.binding.argoclima/src/main/java/org/openhab/binding/argoclima/internal/device/api/protocol/elements/OnOffParam.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.openhab.binding.argoclima.internal.device.api.protocol.elements;
1414

1515
import java.security.InvalidParameterException;
16+
import java.util.Objects;
1617
import java.util.Optional;
1718

1819
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -44,7 +45,7 @@ public OnOffParam(IArgoSettingProvider settingsProvider) {
4445
}
4546

4647
private static State valueToState(Optional<Boolean> value) {
47-
return value.<State> map(v -> OnOffType.from(v)).orElse(UnDefType.UNDEF);
48+
return Objects.requireNonNull(value.<State> map(v -> OnOffType.from(v)).orElse(UnDefType.UNDEF));
4849
}
4950

5051
@Override

0 commit comments

Comments
 (0)