mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 07:02:02 +01:00
Update lastnpe EEA to 2.4.0 (#16875)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
parent
7296b38b51
commit
5e0e9ce51e
@ -379,7 +379,7 @@ public class JRubyScriptEngineConfiguration {
|
||||
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);
|
||||
@ -389,19 +389,19 @@ public class JRubyScriptEngineConfiguration {
|
||||
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() {
|
||||
|
@ -48,9 +48,10 @@ public class JSScriptFileWatcher extends AbstractScriptFileWatcher {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
@ -48,9 +48,10 @@ public class JythonScriptFileWatcher extends AbstractScriptFileWatcher {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ public class AirQualityData extends ResponseRoot {
|
||||
*
|
||||
* @return {AirQualityJsonTime}
|
||||
*/
|
||||
public Optional<AirQualityTime> getTime() {
|
||||
return Optional.ofNullable(time);
|
||||
public @Nullable AirQualityTime getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,6 +35,7 @@ import org.openhab.binding.airquality.internal.api.Index;
|
||||
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;
|
||||
@ -261,10 +262,10 @@ public class AirQualityStationHandler extends BaseThingHandler {
|
||||
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:
|
||||
|
@ -230,9 +230,9 @@ public class PhilipsTVConnectionManager implements DiscoveryListener {
|
||||
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());
|
||||
|
@ -18,7 +18,6 @@ import static org.openhab.binding.androidtv.internal.protocol.philipstv.PhilipsT
|
||||
|
||||
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;
|
||||
@ -122,7 +121,8 @@ public class TvChannelService implements PhilipsTVService {
|
||||
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 {
|
||||
|
@ -373,13 +373,10 @@ public abstract class ArgoClimaConfigurationBase extends Configuration implement
|
||||
validateInternal();
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
var msg = Optional.ofNullable(e.getLocalizedMessage());
|
||||
var msg = e.getLocalizedMessage();
|
||||
var cause = Optional.ofNullable(e.getCause());
|
||||
return msg.orElse("Unknown exception, message is null") // The message theoretically can be null
|
||||
// (Exception's i-face) but in practice never is, so
|
||||
// keeping cryptic non-i18nized text instead of
|
||||
// throwing
|
||||
.concat(cause.map(c -> "\n\t[" + c.getClass().getSimpleName() + "]").orElse(""));
|
||||
return Objects.requireNonNullElse(msg, "Unknown exception, message is null").concat(
|
||||
Objects.requireNonNull(cause.map(c -> "\n\t[" + c.getClass().getSimpleName() + "]").orElse("")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.SortedMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
@ -142,8 +141,8 @@ public class ArgoClimaRemoteDevice extends ArgoClimaDeviceApiBase {
|
||||
|
||||
// Group names must match regex above
|
||||
var properties = new DeviceProperties(Objects.requireNonNull(matcher.group("localIP")),
|
||||
Objects.requireNonNull(matcher.group("lastSeen")), Optional.of(
|
||||
getWebUiUrl(Objects.requireNonNull(this.oemServerHostname.getHostName()), this.oemServerPort)));
|
||||
Objects.requireNonNull(matcher.group("lastSeen")),
|
||||
getWebUiUrl(Objects.requireNonNull(this.oemServerHostname.getHostName()), this.oemServerPort));
|
||||
|
||||
return new DeviceStatus(Objects.requireNonNull(matcher.group("commands")), properties, i18nProvider);
|
||||
}
|
||||
|
@ -20,11 +20,12 @@ import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.argoclima.internal.ArgoClimaBindingConstants;
|
||||
import org.openhab.binding.argoclima.internal.ArgoClimaTranslationProvider;
|
||||
import org.openhab.binding.argoclima.internal.configuration.ArgoClimaConfigurationRemote;
|
||||
@ -53,17 +54,29 @@ class DeviceStatus {
|
||||
*/
|
||||
static class DeviceProperties {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceProperties.class);
|
||||
private final Optional<String> localIP;
|
||||
private final Optional<OffsetDateTime> lastSeen;
|
||||
private final Optional<URL> vendorUiUrl;
|
||||
private Optional<String> cpuId = Optional.empty();
|
||||
private Optional<String> webUiUsername = Optional.empty();
|
||||
private Optional<String> webUiPassword = Optional.empty();
|
||||
private Optional<String> unitFWVersion = Optional.empty();
|
||||
private Optional<String> wifiFWVersion = Optional.empty();
|
||||
private Optional<String> wifiSSID = Optional.empty();
|
||||
private Optional<String> wifiPassword = Optional.empty();
|
||||
private Optional<String> localTime = Optional.empty();
|
||||
|
||||
private OffsetDateTime lastSeen = OffsetDateTime.MIN;
|
||||
|
||||
@Nullable
|
||||
private final String localIP;
|
||||
@Nullable
|
||||
private final URL vendorUiUrl;
|
||||
@Nullable
|
||||
private String cpuId;
|
||||
@Nullable
|
||||
private String webUiUsername;
|
||||
@Nullable
|
||||
private String webUiPassword;
|
||||
@Nullable
|
||||
private String unitFWVersion;
|
||||
@Nullable
|
||||
private String wifiFWVersion;
|
||||
@Nullable
|
||||
private String wifiSSID;
|
||||
@Nullable
|
||||
private String wifiPassword;
|
||||
@Nullable
|
||||
private String localTime;
|
||||
|
||||
/**
|
||||
* C-tor (from remote server query response)
|
||||
@ -72,8 +85,8 @@ class DeviceStatus {
|
||||
* @param lastSeenStr The ISO-8601-formatted date/time of last update (or empty string if N/A)
|
||||
* @param vendorUiAddress The optional full URL to vendor's web UI
|
||||
*/
|
||||
public DeviceProperties(String localIP, String lastSeenStr, Optional<URL> vendorUiAddress) {
|
||||
this.localIP = localIP.isEmpty() ? Optional.empty() : Optional.of(localIP);
|
||||
public DeviceProperties(String localIP, String lastSeenStr, URL vendorUiAddress) {
|
||||
this.localIP = !localIP.isBlank() ? localIP : null;
|
||||
this.vendorUiUrl = vendorUiAddress;
|
||||
this.lastSeen = dateFromISOString(lastSeenStr, "LastSeen");
|
||||
}
|
||||
@ -84,9 +97,9 @@ class DeviceStatus {
|
||||
* @param lastSeen The date/time of last update (when the response got received)
|
||||
*/
|
||||
public DeviceProperties(OffsetDateTime lastSeen) {
|
||||
this.localIP = Optional.empty();
|
||||
this.lastSeen = Optional.of(lastSeen);
|
||||
this.vendorUiUrl = Optional.empty();
|
||||
this.localIP = null;
|
||||
this.lastSeen = lastSeen;
|
||||
this.vendorUiUrl = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,31 +109,32 @@ class DeviceStatus {
|
||||
* @param properties The intercepted device-side request (most rich with properties)
|
||||
*/
|
||||
public DeviceProperties(OffsetDateTime lastSeen, DeviceSideUpdateDTO properties) {
|
||||
this.localIP = Optional.of(properties.setup.localIP.orElse(properties.deviceIp));
|
||||
this.lastSeen = Optional.of(lastSeen);
|
||||
this.vendorUiUrl = Optional.of(ArgoClimaRemoteDevice.getWebUiUrl(properties.remoteServerId, 80));
|
||||
this.cpuId = Optional.of(properties.cpuId);
|
||||
this.webUiUsername = Optional.of(properties.setup.username.orElse(properties.username));
|
||||
this.webUiPassword = properties.setup.password;
|
||||
this.unitFWVersion = Optional.of(properties.setup.unitVersionInstalled.orElse(properties.unitFirmware));
|
||||
this.wifiFWVersion = Optional.of(properties.setup.wifiVersionInstalled.orElse(properties.wifiFirmware));
|
||||
this.wifiSSID = properties.setup.wifiSSID;
|
||||
this.wifiPassword = properties.setup.wifiPassword;
|
||||
this.localTime = properties.setup.localTime;
|
||||
this.localIP = Objects.requireNonNull(properties.setup.localIP.orElse(properties.deviceIp));
|
||||
this.lastSeen = lastSeen;
|
||||
this.vendorUiUrl = ArgoClimaRemoteDevice.getWebUiUrl(properties.remoteServerId, 80);
|
||||
this.cpuId = properties.cpuId;
|
||||
this.webUiUsername = properties.setup.username.orElse(properties.username);
|
||||
this.webUiPassword = properties.setup.password.get();
|
||||
this.unitFWVersion = Objects
|
||||
.requireNonNull(properties.setup.unitVersionInstalled.orElse(properties.unitFirmware));
|
||||
this.wifiFWVersion = properties.setup.wifiVersionInstalled.orElse(properties.wifiFirmware);
|
||||
this.wifiSSID = properties.setup.wifiSSID.get();
|
||||
this.wifiPassword = properties.setup.wifiPassword.get();
|
||||
this.localTime = properties.setup.localTime.get();
|
||||
}
|
||||
|
||||
private static Optional<OffsetDateTime> dateFromISOString(String isoDateTime, String contextualName) {
|
||||
private static OffsetDateTime dateFromISOString(String isoDateTime, String contextualName) {
|
||||
if (isoDateTime.isEmpty()) {
|
||||
return Optional.empty();
|
||||
return OffsetDateTime.MIN;
|
||||
}
|
||||
|
||||
try {
|
||||
return Optional.of(OffsetDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(isoDateTime)));
|
||||
return OffsetDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(isoDateTime));
|
||||
} catch (DateTimeException ex) {
|
||||
// Swallowing exception (no need to handle - proceed as if the date was never provided)
|
||||
LOGGER.debug("Failed to parse [{}] timestamp: {}. Exception: {}", contextualName, isoDateTime,
|
||||
ex.getMessage());
|
||||
return Optional.empty();
|
||||
return OffsetDateTime.MIN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +149,7 @@ class DeviceStatus {
|
||||
* @return Time elapsed since last device-side update
|
||||
*/
|
||||
Duration getLastSeenDelta() {
|
||||
return Duration.between(lastSeen.orElse(OffsetDateTime.MIN).toInstant(), Instant.now());
|
||||
return Duration.between(lastSeen.toInstant(), Instant.now());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,18 +161,50 @@ class DeviceStatus {
|
||||
SortedMap<String, String> asPropertiesRaw(TimeZoneProvider timeZoneProvider) {
|
||||
var result = new TreeMap<String, String>();
|
||||
|
||||
this.lastSeen.map((value) -> result.put(ArgoClimaBindingConstants.PROPERTY_LAST_SEEN,
|
||||
dateTimeToStringLocal(value, timeZoneProvider)));
|
||||
this.localIP.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_IP_ADDRESS, value));
|
||||
this.vendorUiUrl.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI, value.toString()));
|
||||
this.cpuId.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_CPU_ID, value));
|
||||
this.webUiUsername.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_USERNAME, value));
|
||||
this.webUiPassword.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_PASSWORD, value));
|
||||
this.unitFWVersion.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_UNIT_FW, value));
|
||||
this.wifiFWVersion.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_FW, value));
|
||||
this.wifiSSID.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_SSID, value));
|
||||
this.wifiPassword.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_PASSWORD, value));
|
||||
this.localTime.map(value -> result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_TIME, value));
|
||||
String localIP = this.localIP;
|
||||
String cpuId = this.cpuId;
|
||||
URL vendorUiUrl = this.vendorUiUrl;
|
||||
String webUiUsername = this.webUiUsername;
|
||||
String webUiPassword = this.webUiPassword;
|
||||
String unitFWVersion = this.unitFWVersion;
|
||||
String wifiFWVersion = this.wifiFWVersion;
|
||||
String wifiSSID = this.wifiSSID;
|
||||
String wifiPassword = this.wifiPassword;
|
||||
String localTime = this.localTime;
|
||||
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_LAST_SEEN,
|
||||
dateTimeToStringLocal(this.lastSeen, timeZoneProvider));
|
||||
|
||||
if (localIP != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_IP_ADDRESS, localIP);
|
||||
}
|
||||
if (cpuId != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_CPU_ID, cpuId);
|
||||
}
|
||||
if (vendorUiUrl != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI, vendorUiUrl.toString());
|
||||
}
|
||||
if (webUiUsername != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_USERNAME, webUiUsername);
|
||||
}
|
||||
if (webUiPassword != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_WEB_UI_PASSWORD, webUiPassword);
|
||||
}
|
||||
if (unitFWVersion != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_UNIT_FW, unitFWVersion);
|
||||
}
|
||||
if (wifiFWVersion != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_FW, wifiFWVersion);
|
||||
}
|
||||
if (wifiSSID != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_SSID, wifiSSID);
|
||||
}
|
||||
if (wifiPassword != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_WIFI_PASSWORD, wifiPassword);
|
||||
}
|
||||
if (localTime != null) {
|
||||
result.put(ArgoClimaBindingConstants.PROPERTY_LOCAL_TIME, localTime);
|
||||
}
|
||||
return Collections.unmodifiableSortedMap(result);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.argoclima.internal.device.api.protocol.elements;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -413,8 +414,9 @@ public abstract class ArgoApiElementBase implements IArgoElement {
|
||||
|
||||
private final String getInFlightCommandsRawValueOrDefault() {
|
||||
final String valueNotAvailablePlaceholder = "N/A";
|
||||
return inFlightCommand.map(c -> c.deviceCommandToSend.orElse(valueNotAvailablePlaceholder))
|
||||
.orElse(valueNotAvailablePlaceholder);
|
||||
return Objects
|
||||
.requireNonNull(inFlightCommand.map(c -> c.deviceCommandToSend.orElse(valueNotAvailablePlaceholder))
|
||||
.orElse(valueNotAvailablePlaceholder));
|
||||
}
|
||||
|
||||
/////////////
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.argoclima.internal.device.api.protocol.elements;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -44,7 +45,7 @@ public class OnOffParam extends ArgoApiElementBase {
|
||||
}
|
||||
|
||||
private static State valueToState(Optional<Boolean> value) {
|
||||
return value.<State> map(v -> OnOffType.from(v)).orElse(UnDefType.UNDEF);
|
||||
return Objects.requireNonNull(value.<State> map(v -> OnOffType.from(v)).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,7 +140,9 @@ public class AsuswrtHttpClient {
|
||||
String rBody = getContentAsString();
|
||||
logger.trace("({}) requestCompleted '{}'", uid, rBody);
|
||||
// Handle result
|
||||
handleHttpSuccessResponse(rBody, command);
|
||||
if (rBody != null) {
|
||||
handleHttpSuccessResponse(rBody, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -64,6 +64,8 @@ public class FritzAhaContentExchange extends BufferingResponseListener
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import java.util.Collection;
|
||||
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;
|
||||
@ -358,7 +357,7 @@ public class BridgeHandler extends BaseBridgeHandler {
|
||||
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();
|
||||
@ -391,7 +390,7 @@ public class BridgeHandler extends BaseBridgeHandler {
|
||||
}.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();
|
||||
|
@ -181,7 +181,7 @@ public class LongPolling {
|
||||
* @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);
|
||||
@ -211,7 +211,7 @@ public class LongPolling {
|
||||
* @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 {
|
||||
|
@ -16,6 +16,7 @@ import java.time.Instant;
|
||||
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;
|
||||
@ -214,7 +215,8 @@ public class ThingDiscoveryService extends AbstractThingHandlerDiscoveryService<
|
||||
}
|
||||
|
||||
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(
|
||||
rooms.stream().filter(room -> room.id.equals(device.roomId)).findAny().map(r -> r.name).orElse(""));
|
||||
}
|
||||
|
||||
protected void addDevice(Device device, String roomName) {
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.coronastats.internal.handler;
|
||||
|
||||
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;
|
||||
@ -154,7 +155,8 @@ public class CoronaStatsWorldHandler extends BaseBridgeHandler {
|
||||
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);
|
||||
|
@ -14,7 +14,6 @@ package org.openhab.binding.daikin.internal.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.slf4j.Logger;
|
||||
@ -43,9 +42,9 @@ public class BasicInfo {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.daikin.internal.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -59,23 +60,23 @@ public class ControlInfo {
|
||||
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");
|
||||
@ -89,8 +90,8 @@ public class ControlInfo {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -110,7 +111,7 @@ public class ControlInfo {
|
||||
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;
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ package org.openhab.binding.daikin.internal.api.airbase;
|
||||
|
||||
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;
|
||||
@ -44,9 +43,9 @@ public class AirbaseBasicInfo {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.daikin.internal.api.airbase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -54,18 +55,20 @@ public class AirbaseControlInfo {
|
||||
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;
|
||||
}
|
||||
@ -79,7 +82,7 @@ public class AirbaseControlInfo {
|
||||
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;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class AirbaseModelInfo {
|
||||
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"))
|
||||
|
@ -14,7 +14,6 @@ package org.openhab.binding.daikin.internal.api.airbase;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@ -46,8 +45,8 @@ public class AirbaseZoneInfo {
|
||||
Map<String, String> responseMap = InfoParser.parse(response);
|
||||
|
||||
AirbaseZoneInfo info = new AirbaseZoneInfo();
|
||||
info.zonenames = Optional.ofNullable(responseMap.get("zone_name")).orElse("");
|
||||
String zoneinfo = Optional.ofNullable(responseMap.get("zone_onoff")).orElse("");
|
||||
info.zonenames = responseMap.getOrDefault("zone_name", "");
|
||||
String zoneinfo = responseMap.getOrDefault("zone_onoff", "");
|
||||
|
||||
String[] zones = zoneinfo.split(";");
|
||||
|
||||
|
@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@ -133,8 +132,8 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService {
|
||||
|
||||
Map<String, String> parsedData = InfoParser.parse(data);
|
||||
Boolean secure = "1".equals(parsedData.get("en_secure"));
|
||||
String thingId = Optional.ofNullable(parsedData.get("ssid")).orElse(host.replace(".", "_"));
|
||||
String mac = Optional.ofNullable(parsedData.get("mac")).orElse("");
|
||||
String thingId = parsedData.getOrDefault("ssid", host.replace(".", "_"));
|
||||
String mac = parsedData.getOrDefault("mac", "");
|
||||
String uuid = mac.isEmpty() ? UUID.randomUUID().toString()
|
||||
: UUID.nameUUIDFromBytes(mac.getBytes()).toString();
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.daikin.internal.handler;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@ -273,9 +274,9 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler {
|
||||
protected void updateEnergyYearChannel(String channel, Optional<Integer[]> maybePower) {
|
||||
IntStream.range(1, 13).forEach(i -> updateState(
|
||||
String.format(DaikinBindingConstants.CHANNEL_ENERGY_STRING_FORMAT, channel, i),
|
||||
maybePower.<State> map(
|
||||
Objects.requireNonNull(maybePower.<State> map(
|
||||
t -> new QuantityType<>(BigDecimal.valueOf(t[i - 1].longValue(), 1), Units.KILOWATT_HOUR))
|
||||
.orElse(UnDefType.UNDEF))
|
||||
.orElse(UnDefType.UNDEF)))
|
||||
|
||||
);
|
||||
}
|
||||
@ -288,8 +289,9 @@ public class DaikinAcUnitHandler extends DaikinBaseHandler {
|
||||
protected void updateEnergyDayAndWeekChannel(String channel, Optional<Double> maybePower) {
|
||||
if (maybePower.isPresent()) {
|
||||
updateState(channel,
|
||||
maybePower.<State> map(t -> new QuantityType<>(new DecimalType(t), Units.KILOWATT_HOUR))
|
||||
.orElse(UnDefType.UNDEF));
|
||||
Objects.requireNonNull(
|
||||
maybePower.<State> map(t -> new QuantityType<>(new DecimalType(t), Units.KILOWATT_HOUR))
|
||||
.orElse(UnDefType.UNDEF)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.daikin.internal.handler;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -205,8 +206,8 @@ public abstract class DaikinBaseHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
protected void updateTemperatureChannel(String channel, Optional<Double> maybeTemperature) {
|
||||
updateState(channel,
|
||||
maybeTemperature.<State> map(t -> new QuantityType<>(t, SIUnits.CELSIUS)).orElse(UnDefType.UNDEF));
|
||||
updateState(channel, Objects.requireNonNull(
|
||||
maybeTemperature.<State> map(t -> new QuantityType<>(t, SIUnits.CELSIUS)).orElse(UnDefType.UNDEF)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.digiplex.internal.communication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
@ -44,8 +45,8 @@ public enum AreaStatus {
|
||||
}
|
||||
|
||||
public static AreaStatus fromMessage(char indicator) {
|
||||
return Arrays.stream(AreaStatus.values()).filter(type -> type.indicator == indicator).findFirst()
|
||||
.orElse(UNKNOWN);
|
||||
return Objects.requireNonNull(Arrays.stream(AreaStatus.values()).filter(type -> type.indicator == indicator)
|
||||
.findFirst().orElse(UNKNOWN));
|
||||
}
|
||||
|
||||
public StringType toStringType() {
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.digiplex.internal.communication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -37,7 +38,7 @@ public enum ArmDisarmType {
|
||||
}
|
||||
|
||||
public static ArmDisarmType fromMessage(String indicator) {
|
||||
return Arrays.stream(ArmDisarmType.values()).filter(type -> type.indicator.equals(indicator)).findFirst()
|
||||
.orElse(UNKNOWN);
|
||||
return Objects.requireNonNull(Arrays.stream(ArmDisarmType.values())
|
||||
.filter(type -> type.indicator.equals(indicator)).findFirst().orElse(UNKNOWN));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.digiplex.internal.communication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -41,6 +42,7 @@ public enum ArmType {
|
||||
}
|
||||
|
||||
public static ArmType fromMessage(char indicator) {
|
||||
return Arrays.stream(values()).filter(type -> type.indicator == indicator).findFirst().orElse(UNKNOWN);
|
||||
return Objects.requireNonNull(
|
||||
Arrays.stream(values()).filter(type -> type.indicator == indicator).findFirst().orElse(UNKNOWN));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.digiplex.internal.communication;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
@ -42,7 +43,7 @@ public enum ZoneStatus {
|
||||
}
|
||||
|
||||
public static ZoneStatus fromMessage(char indicator) {
|
||||
return Arrays.stream(ZoneStatus.values()).filter(type -> type.indicator == indicator).findFirst()
|
||||
.orElse(UNKNOWN);
|
||||
return Objects.requireNonNull(Arrays.stream(ZoneStatus.values()).filter(type -> type.indicator == indicator)
|
||||
.findFirst().orElse(UNKNOWN));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.digiplex.internal.communication.events;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -39,6 +40,7 @@ public enum SpecialAlarmType {
|
||||
}
|
||||
|
||||
public static SpecialAlarmType fromMessage(int indicator) {
|
||||
return Arrays.stream(values()).filter(type -> type.indicator == indicator).findFirst().orElse(UNKNOWN);
|
||||
return Objects.requireNonNull(
|
||||
Arrays.stream(values()).filter(type -> type.indicator == indicator).findFirst().orElse(UNKNOWN));
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.dsmr.internal.device;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -88,7 +88,7 @@ public class DSMRDeviceRunnable implements Runnable {
|
||||
} catch (final RuntimeException e) {
|
||||
logger.warn("DSMRDeviceRunnable stopped with a RuntimeException", e);
|
||||
portEventListener.onError(DSMRErrorStatus.SERIAL_DATA_READ_ERROR,
|
||||
Optional.ofNullable(e.getMessage()).orElse(""));
|
||||
Objects.requireNonNullElse(e.getMessage(), ""));
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
|
@ -17,7 +17,7 @@ import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
@ -227,7 +227,7 @@ public class SmartyDecrypter implements TelegramParser {
|
||||
logger.warn("Exception of failed decryption of telegram: ", e);
|
||||
}
|
||||
telegramListener.onError(DSMRErrorStatus.INVALID_DECRYPTION_KEY,
|
||||
Optional.ofNullable(e.getMessage()).orElse(""));
|
||||
Objects.requireNonNullElse(e.getMessage(), ""));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ package org.openhab.binding.dsmr.internal.device.connector;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -125,7 +125,7 @@ class DSMRBaseConnector {
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
dsmrConnectorListener.handleError(DSMRErrorStatus.SERIAL_DATA_READ_ERROR,
|
||||
Optional.ofNullable(e.getMessage()).orElse(""));
|
||||
Objects.requireNonNullElse(e.getMessage(), ""));
|
||||
logger.debug("Exception on read data", e);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ package org.openhab.binding.dsmr.internal.device.connector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -245,7 +245,7 @@ public class DSMRSerialConnector extends DSMRBaseConnector implements SerialPort
|
||||
"Port does {} not support requested port settings (invalid dsmr:portsettings parameter?): {}",
|
||||
serialPortName, portSettings);
|
||||
dsmrConnectorListener.handleError(DSMRErrorStatus.PORT_NOT_COMPATIBLE,
|
||||
Optional.ofNullable(e.getMessage()).orElse(""));
|
||||
Objects.requireNonNullElse(e.getMessage(), ""));
|
||||
}
|
||||
} else {
|
||||
restart(portSettings);
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.dwdpollenflug.internal.handler;
|
||||
|
||||
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;
|
||||
@ -153,7 +154,7 @@ public class DWDPollenflugBridgeHandler extends BaseBridgeHandler {
|
||||
f.completeExceptionally(new DWDPollingException("Request failed", e));
|
||||
}
|
||||
} else if (response.getStatus() != 200) {
|
||||
f.completeExceptionally(new DWDPollingException(getContentAsString()));
|
||||
f.completeExceptionally(new DWDPollingException(Objects.requireNonNull(getContentAsString())));
|
||||
} else {
|
||||
try {
|
||||
DWDPollenflug pollenflugJSON = gson.fromJson(getContentAsString(), DWDPollenflug.class);
|
||||
|
@ -125,7 +125,7 @@ public abstract class AbstractCommand extends BufferingResponseListener implemen
|
||||
* Log request success
|
||||
*/
|
||||
@Override
|
||||
public final void onSuccess(@Nullable Response response) {
|
||||
public final void onSuccess(Response response) {
|
||||
super.onSuccess(response);
|
||||
if (response != null) {
|
||||
communicationStatus.setHttpCode(HttpStatus.getCode(response.getStatus()));
|
||||
@ -138,7 +138,9 @@ public abstract class AbstractCommand extends BufferingResponseListener implemen
|
||||
*/
|
||||
@Override
|
||||
public final void onFailure(@Nullable Response response, @Nullable Throwable failure) {
|
||||
super.onFailure(response, failure);
|
||||
if (response != null && failure != null) {
|
||||
super.onFailure(response, failure);
|
||||
}
|
||||
if (failure != null) {
|
||||
logger.info("Request failed: {}", failure.toString());
|
||||
communicationStatus.setError((Exception) failure);
|
||||
@ -161,7 +163,7 @@ public abstract class AbstractCommand extends BufferingResponseListener implemen
|
||||
* just for logging of content
|
||||
*/
|
||||
@Override
|
||||
public void onContent(@Nullable Response response, @Nullable ByteBuffer content) {
|
||||
public void onContent(Response response, ByteBuffer content) {
|
||||
super.onContent(response, content);
|
||||
logger.debug("received content, length: {}", getContentAsString().length());
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.ecovacs.internal.api.commands;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.ecovacs.internal.api.impl.ProtocolVersion;
|
||||
import org.openhab.binding.ecovacs.internal.api.impl.dto.response.deviceapi.json.CachedMapInfoReport;
|
||||
@ -42,7 +44,8 @@ public class GetActiveMapIdCommand extends IotDeviceCommand<String> {
|
||||
throws DataParsingException {
|
||||
if (response instanceof PortalIotCommandJsonResponse jsonResponse) {
|
||||
CachedMapInfoReport resp = jsonResponse.getResponsePayloadAs(gson, CachedMapInfoReport.class);
|
||||
return resp.mapInfos.stream().filter(i -> i.used != 0).map(i -> i.mapId).findFirst().orElse("");
|
||||
return Objects.requireNonNull(
|
||||
resp.mapInfos.stream().filter(i -> i.used != 0).map(i -> i.mapId).findFirst().orElse(""));
|
||||
} else {
|
||||
String payload = ((PortalIotCommandXmlResponse) response).getResponsePayloadXml();
|
||||
return XPathUtils.getFirstXPathMatch(payload, "//@i").getNodeValue();
|
||||
|
@ -20,6 +20,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
@ -320,7 +321,7 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev
|
||||
}
|
||||
return new StringType(def);
|
||||
});
|
||||
updateState(CHANNEL_ID_CLEANING_SPOT_DEFINITION, areaDefState.orElse(UnDefType.UNDEF));
|
||||
updateState(CHANNEL_ID_CLEANING_SPOT_DEFINITION, Objects.requireNonNull(areaDefState.orElse(UnDefType.UNDEF)));
|
||||
if (newMode == CleanMode.RETURNING) {
|
||||
scheduleNextPoll(30);
|
||||
} else if (newMode.isIdle()) {
|
||||
@ -597,7 +598,7 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev
|
||||
lastDownloadedCleanMapUrl = record.mapImageUrl;
|
||||
return new RawType(bytes, "image/png");
|
||||
});
|
||||
updateState(CHANNEL_ID_LAST_CLEAN_MAP, content.orElse(UnDefType.NULL));
|
||||
updateState(CHANNEL_ID_LAST_CLEAN_MAP, Objects.requireNonNull(content.orElse(UnDefType.NULL)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -713,7 +714,7 @@ public class EcovacsVacuumHandler extends BaseThingHandler implements EcovacsDev
|
||||
|
||||
private State stringToState(@Nullable String value) {
|
||||
Optional<State> stateOpt = Optional.ofNullable(value).map(v -> StringType.valueOf(v));
|
||||
return stateOpt.orElse(UnDefType.UNDEF);
|
||||
return Objects.requireNonNull(stateOpt.orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
private @Nullable AbstractNoResponseCommand determineDeviceCommand(EcovacsDevice device, String command) {
|
||||
|
@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -85,7 +85,7 @@ public class EkeyHandler extends BaseThingHandler implements EkeyPacketListener
|
||||
String readerThreadName = "OH-binding-" + getThing().getUID().getAsString();
|
||||
|
||||
EkeyUdpPacketReceiver localReceiver = receiver = new EkeyUdpPacketReceiver(
|
||||
Optional.ofNullable(config.natIp).orElse(config.ipAddress), config.port, readerThreadName);
|
||||
Objects.requireNonNullElse(config.natIp, config.ipAddress), config.port, readerThreadName);
|
||||
localReceiver.addEkeyPacketListener(this);
|
||||
try {
|
||||
localReceiver.openConnection();
|
||||
|
@ -17,6 +17,7 @@ import java.io.StringReader;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -297,8 +298,8 @@ public class Enigma2Client {
|
||||
}
|
||||
|
||||
private String getString(Document document, String elementId) {
|
||||
return Optional.ofNullable(document.getElementsByTagName(elementId)).map(nodeList -> nodeList.item(0))
|
||||
.map(Node::getTextContent).map(String::trim).orElse("");
|
||||
return Objects.requireNonNull(Optional.ofNullable(document.getElementsByTagName(elementId))
|
||||
.map(nodeList -> nodeList.item(0)).map(Node::getTextContent).map(String::trim).orElse(""));
|
||||
}
|
||||
|
||||
private boolean getBoolean(Document document, String elementId) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.enocean.internal.messages;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -50,7 +51,8 @@ public class EventMessage extends BasePacket {
|
||||
}
|
||||
|
||||
public static EventMessageType getEventMessageType(byte value) {
|
||||
return Stream.of(EventMessageType.values()).filter(t -> t.value == value).findFirst().orElse(UNKNOWN);
|
||||
return Objects.requireNonNull(
|
||||
Stream.of(EventMessageType.values()).filter(t -> t.value == value).findFirst().orElse(UNKNOWN));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -372,8 +373,8 @@ public enum Measurand {
|
||||
if (customizationType == null) {
|
||||
return measureType;
|
||||
}
|
||||
return Optional.ofNullable(customizations).map(m -> m.get(customizationType))
|
||||
.map(ParserCustomization::getMeasureType).orElse(measureType);
|
||||
return Objects.requireNonNull(Optional.ofNullable(customizations).map(m -> m.get(customizationType))
|
||||
.map(ParserCustomization::getMeasureType).orElse(measureType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class AbstractWeatherHandlerTest {
|
||||
try {
|
||||
method = AbstractWeatherHandler.class.getDeclaredMethod("floorToEvenMinutes", long.class, int.class);
|
||||
method.setAccessible(true);
|
||||
Object res = method.invoke(null, epochSeconds, roundMinutes);
|
||||
Object res = method.invoke("", epochSeconds, roundMinutes);
|
||||
assertNotNull(res);
|
||||
return (long) res;
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
|
||||
@ -60,7 +60,7 @@ public class AbstractWeatherHandlerTest {
|
||||
try {
|
||||
method = AbstractWeatherHandler.class.getDeclaredMethod("ceilToEvenMinutes", long.class, int.class);
|
||||
method.setAccessible(true);
|
||||
Object res = method.invoke(null, epochSeconds, roundMinutes);
|
||||
Object res = method.invoke("", epochSeconds, roundMinutes);
|
||||
assertNotNull(res);
|
||||
return (long) res;
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
|
||||
@ -85,7 +85,7 @@ public class AbstractWeatherHandlerTest {
|
||||
try {
|
||||
method = AbstractWeatherHandler.class.getDeclaredMethod("lastValidIndex", Data.class);
|
||||
method.setAccessible(true);
|
||||
Object res = method.invoke(null, data);
|
||||
Object res = method.invoke("", data);
|
||||
assertNotNull(res);
|
||||
return (int) res;
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
|
||||
|
@ -18,6 +18,7 @@ import java.time.ZonedDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
@ -226,7 +227,7 @@ public class PlayerManager extends ListableRest<PlayerManager.Player, PlayerMana
|
||||
// The player API does not allow to directly request a given player like others api parts
|
||||
@Override
|
||||
public Player getDevice(int id) throws FreeboxException {
|
||||
return getDevices().stream().filter(player -> player.id == id).findFirst().orElse(null);
|
||||
return Objects.requireNonNull(getDevices().stream().filter(player -> player.id == id).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
public @Nullable Configuration getConfig(int id) throws FreeboxException {
|
||||
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@ -104,8 +105,9 @@ public class StatusFileInterpreter {
|
||||
}
|
||||
|
||||
public String getElement(StatusEntry entry) {
|
||||
return getRoot().map(root -> root.getElementsByTagName(entry.name().toLowerCase()).item(0).getTextContent())
|
||||
.orElse("");
|
||||
return Objects.requireNonNull(
|
||||
getRoot().map(root -> root.getElementsByTagName(entry.name().toLowerCase()).item(0).getTextContent())
|
||||
.orElse(""));
|
||||
}
|
||||
|
||||
private List<Node> getMatchingNodes(NodeList nodeList, String criteria) {
|
||||
|
@ -16,6 +16,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -39,13 +40,12 @@ public class HaasSohnpelletstoveJSONCommunication {
|
||||
private HaasSohnpelletstoveConfiguration config;
|
||||
|
||||
private Gson gson;
|
||||
private @Nullable String xhspin;
|
||||
private String xhspin = "";
|
||||
private @Nullable HaasSohnpelletstoveJsonDataDTO ovenData;
|
||||
|
||||
public HaasSohnpelletstoveJSONCommunication() {
|
||||
gson = new Gson();
|
||||
ovenData = new HaasSohnpelletstoveJsonDataDTO();
|
||||
xhspin = "";
|
||||
config = new HaasSohnpelletstoveConfiguration();
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ public class HaasSohnpelletstoveJSONCommunication {
|
||||
*/
|
||||
private Properties createHeader(@Nullable String postData) {
|
||||
Properties httpHeader = new Properties();
|
||||
httpHeader.setProperty("Host", config.hostIP);
|
||||
httpHeader.setProperty("Host", Objects.requireNonNull(config.hostIP));
|
||||
httpHeader.setProperty("Accept", "*/*");
|
||||
httpHeader.setProperty("Proxy-Connection", "keep-alive");
|
||||
httpHeader.setProperty("X-BACKEND-IP", "https://app.haassohn.com");
|
||||
@ -182,16 +182,16 @@ public class HaasSohnpelletstoveJSONCommunication {
|
||||
* Generate the valid encrypted string to communicate with the oven.
|
||||
*
|
||||
* @param ovenData
|
||||
* @return
|
||||
* @return XHSPIN or empty when it cannot be determined
|
||||
*/
|
||||
private @Nullable String getValidXHSPIN(@Nullable HaasSohnpelletstoveJsonDataDTO ovenData) {
|
||||
private String getValidXHSPIN(@Nullable HaasSohnpelletstoveJsonDataDTO ovenData) {
|
||||
if (ovenData != null && config.hostPIN != null) {
|
||||
String nonce = ovenData.getNonce();
|
||||
String hostPIN = config.hostPIN;
|
||||
String ePin = MD5Utils.getMD5String(hostPIN);
|
||||
return MD5Utils.getMD5String(nonce + ePin);
|
||||
} else {
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -68,7 +69,8 @@ public class HeliosVentilationBindingConstants {
|
||||
String channel = (String) keys.nextElement();
|
||||
HeliosVentilationDataPoint dp;
|
||||
try {
|
||||
dp = new HeliosVentilationDataPoint(channel, properties.getProperty(channel));
|
||||
dp = new HeliosVentilationDataPoint(channel,
|
||||
Objects.requireNonNull(properties.getProperty(channel)));
|
||||
if (result.containsKey(dp.address())) {
|
||||
result.get(dp.address()).append(dp);
|
||||
} else {
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.heos.internal.handler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@ -42,7 +43,7 @@ public class HeosDynamicStateDescriptionProvider extends BaseDynamicStateDescrip
|
||||
.filter(o -> input.equals(o.getLabel())).map(StateOption::getValue).findFirst();
|
||||
|
||||
// if no match was found we assume that it already was a value and not a label
|
||||
return optionalValueByLabel.orElse(input);
|
||||
return Objects.requireNonNull(optionalValueByLabel.orElse(input));
|
||||
}
|
||||
|
||||
public void setFavorites(ChannelUID channelUID, List<BrowseResult> favorites) {
|
||||
|
@ -1233,8 +1233,8 @@ public class Clip2ThingHandler extends BaseThingHandler {
|
||||
sceneContributorsCache.putAll(scenes.stream().collect(Collectors.toMap(s -> s.getId(), s -> s)));
|
||||
sceneResourceEntries.putAll(scenes.stream().collect(Collectors.toMap(s -> s.getName(), s -> s)));
|
||||
|
||||
State state = scenes.stream().filter(s -> s.getSceneActive().orElse(false)).map(s -> s.getSceneState())
|
||||
.findAny().orElse(UnDefType.UNDEF);
|
||||
State state = Objects.requireNonNull(scenes.stream().filter(s -> s.getSceneActive().orElse(false))
|
||||
.map(s -> s.getSceneState()).findAny().orElse(UnDefType.UNDEF));
|
||||
|
||||
// create scene channel if it is missing
|
||||
if (getThing().getChannel(CHANNEL_2_SCENE) == null) {
|
||||
|
@ -15,7 +15,6 @@ package org.openhab.binding.knx.internal.client;
|
||||
import static org.openhab.binding.knx.internal.dpt.DPTUtil.NORMALIZED_DPT;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
@ -273,19 +272,20 @@ public abstract class AbstractKNXClient implements NetworkLinkListener, KNXClien
|
||||
return false;
|
||||
} catch (KNXIllegalArgumentException e) {
|
||||
logger.debug("Bridge {} cannot connect: {}", thingUID, e.getMessage());
|
||||
disconnect(e, Optional.of(ThingStatusDetail.CONFIGURATION_ERROR));
|
||||
disconnect(e, ThingStatusDetail.CONFIGURATION_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void disconnect(@Nullable Exception e) {
|
||||
disconnect(e, Optional.empty());
|
||||
disconnect(e, null);
|
||||
}
|
||||
|
||||
private synchronized void disconnect(@Nullable Exception e, Optional<ThingStatusDetail> detail) {
|
||||
private synchronized void disconnect(@Nullable Exception e, @Nullable ThingStatusDetail detail) {
|
||||
releaseConnection();
|
||||
if (e != null) {
|
||||
statusUpdateCallback.updateStatus(ThingStatus.OFFLINE, detail.orElse(ThingStatusDetail.COMMUNICATION_ERROR),
|
||||
statusUpdateCallback.updateStatus(ThingStatus.OFFLINE,
|
||||
detail != null ? detail : ThingStatusDetail.COMMUNICATION_ERROR,
|
||||
KNXTranslationProvider.I18N.getLocalizedException(e));
|
||||
} else {
|
||||
statusUpdateCallback.updateStatus(ThingStatus.OFFLINE);
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.lcn.internal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -203,10 +204,10 @@ public class LcnModuleActions implements ThingActions {
|
||||
localCount = 1;
|
||||
}
|
||||
|
||||
String filteredTonality = LcnBindingConstants.ALLOWED_BEEP_TONALITIES.stream() //
|
||||
String filteredTonality = Objects.requireNonNull(LcnBindingConstants.ALLOWED_BEEP_TONALITIES.stream() //
|
||||
.filter(t -> t.equals(tonality)) //
|
||||
.findAny() //
|
||||
.orElse("N");
|
||||
.orElse("N"));
|
||||
|
||||
getHandler().sendPck(PckGenerator.beep(filteredTonality, Math.min(localCount, MAX_BEEP_COUNT)));
|
||||
} catch (LcnException e) {
|
||||
|
@ -14,7 +14,6 @@ package org.openhab.binding.lcn.internal.subhandler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.IntStream;
|
||||
@ -72,16 +71,16 @@ public class LcnModuleThresholdSubHandler extends AbstractLcnModuleVariableSubHa
|
||||
@Override
|
||||
public void handleStatusMessage(Matcher matcher) {
|
||||
IntStream stream;
|
||||
Optional<String> groupSuffix;
|
||||
String groupSuffix;
|
||||
int registerNumber;
|
||||
if (matcher.pattern() == PATTERN) {
|
||||
int thresholdId = Integer.parseInt(matcher.group("thresholdId")) - 1;
|
||||
registerNumber = Integer.parseInt(matcher.group("registerId")) - 1;
|
||||
stream = IntStream.rangeClosed(thresholdId, thresholdId);
|
||||
groupSuffix = Optional.of("");
|
||||
groupSuffix = "";
|
||||
} else if (matcher.pattern() == PATTERN_BEFORE_2013) {
|
||||
stream = IntStream.range(0, LcnDefs.THRESHOLD_COUNT_BEFORE_2013);
|
||||
groupSuffix = Optional.empty();
|
||||
groupSuffix = null;
|
||||
registerNumber = 0;
|
||||
} else {
|
||||
logger.warn("Unexpected pattern: {}", matcher.pattern());
|
||||
@ -90,7 +89,7 @@ public class LcnModuleThresholdSubHandler extends AbstractLcnModuleVariableSubHa
|
||||
|
||||
stream.forEach(i -> {
|
||||
try {
|
||||
fireUpdateAndReset(matcher, groupSuffix.orElse(String.valueOf(i)),
|
||||
fireUpdateAndReset(matcher, groupSuffix != null ? groupSuffix : String.valueOf(i),
|
||||
Variable.thrsIdToVar(registerNumber, i));
|
||||
} catch (LcnException e) {
|
||||
logger.warn("Parse error: {}", e.getMessage());
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.luxom.internal.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -55,8 +56,8 @@ public enum LuxomAction {
|
||||
}
|
||||
|
||||
public static LuxomAction of(String command) {
|
||||
return Arrays.stream(LuxomAction.values()).filter(a -> a.getCommand().equals(command)).findFirst()
|
||||
.orElse(INVALID_ACTION);
|
||||
return Objects.requireNonNull(Arrays.stream(LuxomAction.values()).filter(a -> a.getCommand().equals(command))
|
||||
.findFirst().orElse(INVALID_ACTION));
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
|
@ -22,6 +22,7 @@ import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -215,7 +216,7 @@ public class MagentaTVOAuth {
|
||||
TimeUnit.MILLISECONDS);
|
||||
for (Enumeration<?> e = headers.keys(); e.hasMoreElements();) {
|
||||
String key = (String) e.nextElement();
|
||||
String val = (String) headers.get(key);
|
||||
String val = (String) headers.get(Objects.requireNonNull(key));
|
||||
request.header(key, val);
|
||||
}
|
||||
if (method.equals(HttpMethod.POST)) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
package org.openhab.binding.mielecloud.internal.config.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -68,9 +68,9 @@ public final class PairAccountServlet extends AbstractShowPageServlet {
|
||||
}
|
||||
|
||||
private String renderClientIdAndClientSecret(HttpServletRequest request, String skeleton) {
|
||||
String prefilledClientId = Optional.ofNullable(request.getParameter(CLIENT_ID_PARAMETER_NAME)).orElse("");
|
||||
String prefilledClientSecret = Optional.ofNullable(request.getParameter(CLIENT_SECRET_PARAMETER_NAME))
|
||||
.orElse("");
|
||||
String prefilledClientId = Objects.requireNonNullElse(request.getParameter(CLIENT_ID_PARAMETER_NAME), "");
|
||||
String prefilledClientSecret = Objects.requireNonNullElse(request.getParameter(CLIENT_SECRET_PARAMETER_NAME),
|
||||
"");
|
||||
return skeleton.replace(CLIENT_ID_PLACEHOLDER, prefilledClientId).replace(CLIENT_SECRET_PLACEHOLDER,
|
||||
prefilledClientSecret);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.mielecloud.internal.config.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@ -148,7 +149,7 @@ public class SuccessServlet extends AbstractShowPageServlet {
|
||||
|
||||
private String renderBridgeConfigurationTemplate(String skeleton, ThingUID bridgeUid, String email) {
|
||||
String bridgeTemplate = templateGenerator.createBridgeConfigurationTemplate(bridgeUid.getId(), email,
|
||||
languageProvider.getLanguage().orElse("en"));
|
||||
Objects.requireNonNull(languageProvider.getLanguage().orElse("en")));
|
||||
return skeleton.replace(THINGS_TEMPLATE_CODE_PLACEHOLDER, bridgeTemplate);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import static org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants
|
||||
import static org.openhab.binding.mielecloud.internal.handler.MieleHandlerFactory.SUPPORTED_THING_TYPES;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -189,7 +190,8 @@ public class ThingDiscoveryService extends AbstractThingHandlerDiscoveryService<
|
||||
return deviceName.get();
|
||||
}
|
||||
|
||||
return ThingInformationExtractor.getDeviceAndTechType(deviceState).orElse("Miele Device");
|
||||
return Objects
|
||||
.requireNonNull(ThingInformationExtractor.getDeviceAndTechType(deviceState).orElse("Miele Device"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.mielecloud.internal.discovery;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -58,11 +59,11 @@ public final class ThingInformationExtractor {
|
||||
}
|
||||
|
||||
private static String getSerialNumber(DeviceState deviceState) {
|
||||
return deviceState.getFabNumber().orElse(deviceState.getDeviceIdentifier());
|
||||
return Objects.requireNonNull(deviceState.getFabNumber().orElse(deviceState.getDeviceIdentifier()));
|
||||
}
|
||||
|
||||
private static String getModelId(DeviceState deviceState) {
|
||||
return getDeviceAndTechType(deviceState).orElse("Unknown");
|
||||
return Objects.requireNonNull(getDeviceAndTechType(deviceState).orElse("Unknown"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ import static org.openhab.binding.mielecloud.internal.webservice.api.PowerStatus
|
||||
import static org.openhab.binding.mielecloud.internal.webservice.api.ProgramStatus.*;
|
||||
import static org.openhab.binding.mielecloud.internal.webservice.api.json.ProcessAction.*;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -88,8 +89,8 @@ public abstract class AbstractMieleThingHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
protected MieleWebservice getWebservice() {
|
||||
return getMieleBridgeHandler().map(MieleBridgeHandler::getWebservice)
|
||||
.orElse(UnavailableMieleWebservice.INSTANCE);
|
||||
return Objects.requireNonNull(getMieleBridgeHandler().map(MieleBridgeHandler::getWebservice)
|
||||
.orElse(UnavailableMieleWebservice.INSTANCE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,7 @@ package org.openhab.binding.mielecloud.internal.handler.channel;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -46,29 +47,31 @@ public final class ChannelTypeUtil {
|
||||
* Converts an {@link Optional} of {@link String} to {@link State}.
|
||||
*/
|
||||
public static State stringToState(Optional<String> value) {
|
||||
return value.filter(v -> !v.isEmpty()).filter(v -> !"null".equals(v)).map(v -> (State) new StringType(v))
|
||||
.orElse(UnDefType.UNDEF);
|
||||
return Objects.requireNonNull(value.filter(v -> !v.isEmpty()).filter(v -> !"null".equals(v))
|
||||
.map(v -> (State) new StringType(v)).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an {@link Optional} of {@link Boolean} to {@link State}.
|
||||
*/
|
||||
public static State booleanToState(Optional<Boolean> value) {
|
||||
return value.map(v -> (State) OnOffType.from(v)).orElse(UnDefType.UNDEF);
|
||||
return Objects.requireNonNull(value.map(v -> (State) OnOffType.from(v)).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an {@link Optional} of {@link Integer} to {@link State}.
|
||||
*/
|
||||
public static State intToState(Optional<Integer> value) {
|
||||
return value.map(v -> (State) new DecimalType(new BigDecimal(v))).orElse(UnDefType.UNDEF);
|
||||
return Objects
|
||||
.requireNonNull(value.map(v -> (State) new DecimalType(new BigDecimal(v))).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an {@link Optional} of {@link Long} to {@link State}.
|
||||
*/
|
||||
public static State longToState(Optional<Long> value) {
|
||||
return value.map(v -> (State) new DecimalType(new BigDecimal(v))).orElse(UnDefType.UNDEF);
|
||||
return Objects
|
||||
.requireNonNull(value.map(v -> (State) new DecimalType(new BigDecimal(v))).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,15 +79,16 @@ public final class ChannelTypeUtil {
|
||||
*/
|
||||
public static State intToTemperatureState(Optional<Integer> value) {
|
||||
// The Miele 3rd Party API always provides temperatures in °C (even if the device uses another unit).
|
||||
return value.map(v -> (State) new QuantityType<>(v, SIUnits.CELSIUS)).orElse(UnDefType.UNDEF);
|
||||
return Objects
|
||||
.requireNonNull(value.map(v -> (State) new QuantityType<>(v, SIUnits.CELSIUS)).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an {@link Optional} of {@link Quantity} to {@link State}.
|
||||
*/
|
||||
public static State quantityToState(Optional<Quantity> value) {
|
||||
return value.flatMap(ChannelTypeUtil::formatQuantity).flatMap(ChannelTypeUtil::parseQuantityType)
|
||||
.orElse(UnDefType.UNDEF);
|
||||
return Objects.requireNonNull(value.flatMap(ChannelTypeUtil::formatQuantity)
|
||||
.flatMap(ChannelTypeUtil::parseQuantityType).orElse(UnDefType.UNDEF));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,8 +518,8 @@ public class DeviceState {
|
||||
* @return The raw device type.
|
||||
*/
|
||||
public DeviceType getRawType() {
|
||||
return device.flatMap(Device::getIdent).flatMap(Ident::getType).map(Type::getValueRaw)
|
||||
.orElse(DeviceType.UNKNOWN);
|
||||
return Objects.requireNonNull(device.flatMap(Device::getIdent).flatMap(Ident::getType).map(Type::getValueRaw)
|
||||
.orElse(DeviceType.UNKNOWN));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ public class Type {
|
||||
}
|
||||
|
||||
public DeviceType getValueRaw() {
|
||||
return Optional.ofNullable(valueRaw).orElse(DeviceType.UNKNOWN);
|
||||
return Objects.requireNonNullElse(valueRaw, DeviceType.UNKNOWN);
|
||||
}
|
||||
|
||||
public Optional<String> getValueLocalized() {
|
||||
|
@ -112,7 +112,8 @@ public class SseConnectionTest {
|
||||
getSseConnection().addSseListener(getMockedSseListener());
|
||||
getSseConnection().connect();
|
||||
|
||||
getRegisteredHeadersListener().onHeaders(null);
|
||||
Response response = mock(Response.class);
|
||||
getRegisteredHeadersListener().onHeaders(response);
|
||||
}
|
||||
|
||||
private Request getMockedRequest() {
|
||||
@ -206,7 +207,8 @@ public class SseConnectionTest {
|
||||
assertNotNull(headersListener);
|
||||
|
||||
// when:
|
||||
headersListener.onHeaders(null);
|
||||
Response response = mock(Response.class);
|
||||
headersListener.onHeaders(response);
|
||||
|
||||
// then:
|
||||
verify(scheduler).schedule(ArgumentMatchers.<Runnable> any(), anyLong(), any());
|
||||
@ -266,7 +268,8 @@ public class SseConnectionTest {
|
||||
setUpRunningConnection();
|
||||
|
||||
// when:
|
||||
getRegisteredCompleteListener().onComplete(null);
|
||||
Result result = mock(Result.class);
|
||||
getRegisteredCompleteListener().onComplete(result);
|
||||
|
||||
// then:
|
||||
verify(getMockedScheduler(), times(2)).schedule(ArgumentMatchers.<Runnable> any(), anyLong(), any());
|
||||
@ -505,7 +508,8 @@ public class SseConnectionTest {
|
||||
|
||||
HeadersListener headersListener = registeredHeadersListener;
|
||||
assertNotNull(headersListener);
|
||||
headersListener.onHeaders(null);
|
||||
Response response = mock(Response.class);
|
||||
headersListener.onHeaders(response);
|
||||
|
||||
ServerSentEvent serverSentEvent = new ServerSentEvent("ping", "ping");
|
||||
|
||||
|
@ -56,6 +56,7 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
|
||||
private void triggerSwitch(String variableName) {
|
||||
try {
|
||||
HeliosEasyControlsHandler handler = this.handler;
|
||||
if (handler != null) {
|
||||
handler.writeValue(variableName, "1");
|
||||
}
|
||||
@ -159,6 +160,7 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
|
||||
@RuleAction(label = "@text/action.getErrorMessages.label", description = "@text/action.getErrorMessages.description")
|
||||
public @ActionOutput(name = "errorMessages", type = "java.util.List<String>") List<String> getErrorMessages() {
|
||||
HeliosEasyControlsHandler handler = this.handler;
|
||||
return (handler != null) ? handler.getErrorMessages() : new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -168,6 +170,7 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
|
||||
@RuleAction(label = "@text/action.getWarningMessages.label", description = "@text/action.getWarningMessages.description")
|
||||
public @ActionOutput(name = "warningMessages", type = "java.util.List<String>") List<String> getWarningMessages() {
|
||||
HeliosEasyControlsHandler handler = this.handler;
|
||||
return (handler != null) ? handler.getWarningMessages() : new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -177,6 +180,7 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
|
||||
@RuleAction(label = "@text/action.getInfoMessages.label", description = "@text/action.getInfoMessages.description")
|
||||
public @ActionOutput(name = "infoMessages", type = "java.util.List<String>") List<String> getInfoMessages() {
|
||||
HeliosEasyControlsHandler handler = this.handler;
|
||||
return (handler != null) ? handler.getInfoMessages() : new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -186,6 +190,7 @@ public class HeliosEasyControlsActions implements ThingActions {
|
||||
|
||||
@RuleAction(label = "@text/action.getStatusMessages.label", description = "@text/action.getStatusMessages.description")
|
||||
public @ActionOutput(name = "statusMessages", type = "java.util.List<String>") List<String> getStatusMessages() {
|
||||
HeliosEasyControlsHandler handler = this.handler;
|
||||
return (handler != null) ? handler.getStatusMessages() : new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -168,9 +168,10 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
} catch (IOException e) {
|
||||
this.handleError("Error reading variable definition file", ThingStatusDetail.CONFIGURATION_ERROR);
|
||||
}
|
||||
Map<String, HeliosVariable> variableMap = this.variableMap;
|
||||
if (variableMap != null) {
|
||||
// add the name to the variable itself
|
||||
for (Map.Entry<String, HeliosVariable> entry : this.variableMap.entrySet()) {
|
||||
for (Map.Entry<String, HeliosVariable> entry : variableMap.entrySet()) {
|
||||
entry.getValue().setName(entry.getKey()); // workaround to set the variable name inside the
|
||||
// HeliosVariable object
|
||||
if (!entry.getValue().isOk()) {
|
||||
@ -225,7 +226,6 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
|
||||
ModbusEndpointThingHandler slaveEndpointThingHandler = getEndpointThingHandler();
|
||||
if (slaveEndpointThingHandler == null) {
|
||||
@SuppressWarnings("null")
|
||||
String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE,
|
||||
String.format("Bridge '%s' is offline", label));
|
||||
@ -236,7 +236,6 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
comms = slaveEndpointThingHandler.getCommunicationInterface();
|
||||
|
||||
if (comms == null) {
|
||||
@SuppressWarnings("null")
|
||||
String label = Optional.ofNullable(getBridge()).map(b -> b.getLabel()).orElse("<null>");
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE,
|
||||
String.format("Bridge '%s' not completely initialized", label));
|
||||
@ -250,8 +249,9 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
this.config = getConfigAs(HeliosEasyControlsConfiguration.class);
|
||||
this.readVariableDefinition();
|
||||
this.connectEndpoint();
|
||||
if ((this.comms != null) && (this.variableMap != null) && (this.config != null)) {
|
||||
this.transactionLocks.putIfAbsent(this.comms.getEndpoint(), new Semaphore(1, true));
|
||||
ModbusCommunicationInterface comms = this.comms;
|
||||
if (comms != null && this.variableMap != null && this.config != null) {
|
||||
this.transactionLocks.putIfAbsent(comms.getEndpoint(), new Semaphore(1, true));
|
||||
updateStatus(ThingStatus.UNKNOWN);
|
||||
|
||||
// background initialization
|
||||
@ -264,6 +264,7 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
HeliosEasyControlsConfiguration config = this.config;
|
||||
if (config != null) {
|
||||
this.pollingJob = scheduler.scheduleWithFixedDelay(() -> {
|
||||
Map<String, HeliosVariable> variableMap = this.variableMap;
|
||||
if (variableMap != null) {
|
||||
for (Map.Entry<String, HeliosVariable> entry : variableMap.entrySet()) {
|
||||
if (this.isProperty(entry.getKey()) || isLinked(entry.getValue().getGroupAndName())
|
||||
@ -293,8 +294,10 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (this.pollingJob != null) {
|
||||
this.pollingJob.cancel(true);
|
||||
ScheduledFuture<?> pollingJob = this.pollingJob;
|
||||
if (pollingJob != null) {
|
||||
pollingJob.cancel(true);
|
||||
this.pollingJob = null;
|
||||
}
|
||||
this.comms = null;
|
||||
}
|
||||
@ -382,6 +385,7 @@ public class HeliosEasyControlsHandler extends BaseThingHandler {
|
||||
scheduler.submit(() -> {
|
||||
try {
|
||||
writeValue(channelId, v);
|
||||
Map<String, HeliosVariable> variableMap = this.variableMap;
|
||||
if (variableMap != null) {
|
||||
HeliosVariable variable = variableMap.get(channelId);
|
||||
if (variable != null) {
|
||||
|
@ -39,7 +39,7 @@ public class PreparePayloadTest {
|
||||
|
||||
private ModbusRegisterArray preparePayload(String payload) {
|
||||
try {
|
||||
return (ModbusRegisterArray) preparePayloadMethod.invoke(null, payload);
|
||||
return (ModbusRegisterArray) preparePayloadMethod.invoke("", payload);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
fail("Reflection failure:" + e.getMessage());
|
||||
throw new RuntimeException(); // to make compiler happy
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.modbus.stiebeleltron.internal.parser;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -50,7 +51,7 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or the default if the field is not implemented
|
||||
*/
|
||||
protected Double extractDouble(ModbusRegisterArray raw, int index, double def) {
|
||||
return extractOptionalDouble(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalDouble(raw, index).orElse(def));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +75,7 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or the default if the field is not implemented
|
||||
*/
|
||||
protected Short extractInt16(ModbusRegisterArray raw, int index, short def) {
|
||||
return extractOptionalInt16(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalInt16(raw, index).orElse(def));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +99,7 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or the default if the field is not implemented
|
||||
*/
|
||||
protected Integer extractUInt16(ModbusRegisterArray raw, int index, int def) {
|
||||
return extractOptionalUInt16(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalUInt16(raw, index).orElse(def));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,6 +123,6 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or default if the field is not implemented
|
||||
*/
|
||||
protected Long extractUnit32(ModbusRegisterArray raw, int index, long def) {
|
||||
return extractOptionalUInt32(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalUInt32(raw, index).orElse(def));
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import static org.openhab.binding.modbus.sunspec.internal.SunSpecConstants.*;
|
||||
import static org.openhab.core.library.unit.SIUnits.CELSIUS;
|
||||
import static org.openhab.core.library.unit.Units.*;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -85,7 +86,7 @@ public class InverterHandler extends AbstractSunSpecHandler {
|
||||
status == null ? UnDefType.UNDEF : new StringType(status.name()));
|
||||
|
||||
updateState(channelUID(GROUP_DEVICE_INFO, CHANNEL_STATUS_VENDOR),
|
||||
block.statusVendor.<State> map(DecimalType::new).orElse(UnDefType.UNDEF));
|
||||
Objects.requireNonNull(block.statusVendor.<State> map(DecimalType::new).orElse(UnDefType.UNDEF)));
|
||||
|
||||
// AC General group
|
||||
updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_TOTAL_CURRENT),
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.binding.modbus.sunspec.internal.handler;
|
||||
import static org.openhab.binding.modbus.sunspec.internal.SunSpecConstants.*;
|
||||
import static org.openhab.core.library.unit.Units.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.modbus.sunspec.internal.dto.MeterModelBlock;
|
||||
import org.openhab.binding.modbus.sunspec.internal.parser.MeterModelParser;
|
||||
@ -92,7 +94,7 @@ public class MeterHandler extends AbstractSunSpecHandler {
|
||||
getScaled(block.acVoltageLineToLineAverage, block.acVoltageSF, VOLT));
|
||||
|
||||
updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_FREQUENCY),
|
||||
getScaled(block.acFrequency, block.acFrequencySF.orElse((short) 1), HERTZ));
|
||||
getScaled(block.acFrequency, Objects.requireNonNull(block.acFrequencySF.orElse((short) 1)), HERTZ));
|
||||
|
||||
updateState(channelUID(GROUP_AC_GENERAL, CHANNEL_AC_TOTAL_REAL_POWER),
|
||||
getScaled(block.acRealPowerTotal, block.acRealPowerSF, WATT));
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.modbus.sunspec.internal.parser;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -50,7 +51,7 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or the default if the field is not implemented
|
||||
*/
|
||||
protected Short extractInt16(ModbusRegisterArray raw, int index, short def) {
|
||||
return extractOptionalInt16(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalInt16(raw, index).orElse(def));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +75,7 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or the default if the field is not implemented
|
||||
*/
|
||||
protected Integer extractUInt16(ModbusRegisterArray raw, int index, int def) {
|
||||
return extractOptionalUInt16(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalUInt16(raw, index).orElse(def));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +99,7 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or default if the field is not implemented
|
||||
*/
|
||||
protected Long extractAcc32(ModbusRegisterArray raw, int index, long def) {
|
||||
return extractOptionalAcc32(raw, index).orElse(def);
|
||||
return Objects.requireNonNull(extractOptionalAcc32(raw, index).orElse(def));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,6 +122,6 @@ public class AbstractBaseParser {
|
||||
* @return the parsed value or 1 if the field is not implemented
|
||||
*/
|
||||
protected Short extractSunSSF(ModbusRegisterArray raw, int index) {
|
||||
return extractOptionalSunSSF(raw, index).orElse((short) 0);
|
||||
return Objects.requireNonNull(extractOptionalSunSSF(raw, index).orElse((short) 0));
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import java.lang.reflect.Method;
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -118,7 +119,8 @@ public class ChargingStatisticsTest {
|
||||
Method updateChargeStatisticsMethod = VehicleHandler.class.getDeclaredMethod("updateChargingStatistics",
|
||||
ChargingStatisticsContainer.class, String.class);
|
||||
updateChargeStatisticsMethod.setAccessible(true);
|
||||
updateChargeStatisticsMethod.invoke(vehicleHandler,
|
||||
assertNotNull(vehicleHandler);
|
||||
updateChargeStatisticsMethod.invoke(Objects.requireNonNull(vehicleHandler),
|
||||
JsonStringDeserializer.getChargingStatistics(statusContent), null);
|
||||
} catch (Exception e) {
|
||||
logger.error("chargeStatistics could not be set", e);
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.mycroft.internal.api;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
@ -100,8 +101,8 @@ public enum MessageType {
|
||||
|
||||
@NotNull
|
||||
public static MessageType fromString(String asString) {
|
||||
return Stream.of(values()).filter(messageType -> messageType.messageTypeName.equals(asString)).findFirst()
|
||||
.orElse(any);
|
||||
return Objects.requireNonNull(Stream.of(values())
|
||||
.filter(messageType -> messageType.messageTypeName.equals(asString)).findFirst().orElse(any));
|
||||
}
|
||||
|
||||
public String getMessageTypeName() {
|
||||
|
@ -18,7 +18,7 @@ import static org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.*;
|
||||
import java.net.URI;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -170,7 +170,7 @@ public enum ModuleType {
|
||||
|
||||
public static final EnumSet<ModuleType> AS_SET = EnumSet.allOf(ModuleType.class);
|
||||
|
||||
private final Optional<ModuleType> bridgeType;
|
||||
private final @Nullable ModuleType bridgeType;
|
||||
public final Set<ChannelGroup> channelGroups;
|
||||
public final Set<Class<? extends Capability>> capabilities;
|
||||
public final ThingTypeUID thingTypeUID;
|
||||
@ -181,7 +181,7 @@ public enum ModuleType {
|
||||
|
||||
ModuleType(FeatureArea feature, String apiName, int thingTypeVersion, String config, @Nullable ModuleType bridge,
|
||||
Set<Class<? extends Capability>> capabilities, ChannelGroup... channelGroups) {
|
||||
this.bridgeType = Optional.ofNullable(bridge);
|
||||
this.bridgeType = bridge;
|
||||
this.feature = feature;
|
||||
this.capabilities = capabilities;
|
||||
this.apiName = apiName;
|
||||
@ -219,7 +219,7 @@ public enum ModuleType {
|
||||
}
|
||||
|
||||
public ModuleType getBridge() {
|
||||
return bridgeType.orElse(UNKNOWN);
|
||||
return Objects.requireNonNullElse(this.bridgeType, UNKNOWN);
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
|
@ -67,8 +67,8 @@ public class NAThing extends NAObject implements NAModule {
|
||||
return radioStatus;
|
||||
}
|
||||
|
||||
public Optional<ZonedDateTime> getLastSeen() {
|
||||
return Optional.ofNullable(lastSeen);
|
||||
public @Nullable ZonedDateTime getLastSeen() {
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.netatmo.internal.deserialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -62,8 +63,8 @@ class NAPushTypeDeserializer implements JsonDeserializer<NAPushType> {
|
||||
* @return moduletype value if found, or else Unknown
|
||||
*/
|
||||
public static ModuleType fromNetatmoObject(String apiName) {
|
||||
return ModuleType.AS_SET.stream().filter(mt -> apiName.equals(mt.apiName)).findFirst()
|
||||
.orElse(ModuleType.UNKNOWN);
|
||||
return Objects.requireNonNull(ModuleType.AS_SET.stream().filter(mt -> apiName.equals(mt.apiName)).findFirst()
|
||||
.orElse(ModuleType.UNKNOWN));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +72,7 @@ class NAPushTypeDeserializer implements JsonDeserializer<NAPushType> {
|
||||
* @return eventType value if found, or else Unknown
|
||||
*/
|
||||
public static EventType fromEvent(String apiName) {
|
||||
return EventType.AS_SET.stream().filter(et -> apiName.equalsIgnoreCase(et.name())).findFirst()
|
||||
.orElse(EventType.UNKNOWN);
|
||||
return Objects.requireNonNull(EventType.AS_SET.stream().filter(et -> apiName.equalsIgnoreCase(et.name()))
|
||||
.findFirst().orElse(EventType.UNKNOWN));
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ package org.openhab.binding.netatmo.internal.handler;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@ -169,8 +170,8 @@ public interface CommonInterface {
|
||||
}
|
||||
|
||||
default <T extends RestCapability<?>> Optional<T> getHomeCapability(Class<T> clazz) {
|
||||
return recurseUpToHomeHandler(this).map(handler -> handler.getCapabilities().get(clazz))
|
||||
.orElse(Optional.empty());
|
||||
return Objects.requireNonNull(recurseUpToHomeHandler(this).map(handler -> handler.getCapabilities().get(clazz))
|
||||
.orElse(Optional.empty()));
|
||||
}
|
||||
|
||||
default void setNewData(NAObject newData) {
|
||||
|
@ -16,6 +16,7 @@ import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
|
||||
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
||||
@ -46,8 +47,8 @@ public class AlarmEventCapability extends HomeSecurityThingCapability {
|
||||
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_TYPE, toStringType(event.getEventType()));
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_TIME, toDateTimeType(event.getTime()));
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE,
|
||||
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL));
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE, Objects.requireNonNull(
|
||||
event.getSubTypeDescription().map(ChannelTypeUtils::toStringType).orElse(UnDefType.NULL)));
|
||||
final String message = event.getName();
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE,
|
||||
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
|
||||
@ -55,7 +56,8 @@ public class AlarmEventCapability extends HomeSecurityThingCapability {
|
||||
|
||||
@Override
|
||||
public List<NAObject> updateReadings() {
|
||||
return getSecurityCapability().map(cap -> cap.getDeviceLastEvent(handler.getId(), moduleType.apiName))
|
||||
.map(event -> List.of((NAObject) event)).orElse(List.of());
|
||||
return Objects.requireNonNull(
|
||||
getSecurityCapability().map(cap -> cap.getDeviceLastEvent(handler.getId(), moduleType.apiName))
|
||||
.map(event -> List.of((NAObject) event)).orElse(List.of()));
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriBuilderException;
|
||||
@ -129,7 +130,7 @@ public class CameraCapability extends HomeSecurityThingCapability {
|
||||
handler.updateState(group, CHANNEL_EVENT_VIGNETTE, toRawType(event.getVignetteUrl()));
|
||||
handler.updateState(group, CHANNEL_EVENT_VIGNETTE_URL, toStringType(event.getVignetteUrl()));
|
||||
handler.updateState(group, CHANNEL_EVENT_SUBTYPE,
|
||||
event.getSubTypeDescription().map(d -> toStringType(d)).orElse(UnDefType.NULL));
|
||||
Objects.requireNonNull(event.getSubTypeDescription().map(d -> toStringType(d)).orElse(UnDefType.NULL)));
|
||||
final String message = event.getName();
|
||||
handler.updateState(group, CHANNEL_EVENT_MESSAGE,
|
||||
message == null || message.isBlank() ? UnDefType.NULL : toStringType(message));
|
||||
|
@ -18,6 +18,7 @@ import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -79,7 +80,7 @@ public class PersonCapability extends HomeSecurityThingCapability {
|
||||
super.updateWebhookEvent(event);
|
||||
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_SUBTYPE,
|
||||
event.getSubTypeDescription().map(d -> toStringType(d)).orElse(UnDefType.NULL));
|
||||
Objects.requireNonNull(event.getSubTypeDescription().map(d -> toStringType(d)).orElse(UnDefType.NULL)));
|
||||
|
||||
final String message = event.getName();
|
||||
handler.updateState(GROUP_LAST_EVENT, CHANNEL_EVENT_MESSAGE,
|
||||
@ -100,8 +101,8 @@ public class PersonCapability extends HomeSecurityThingCapability {
|
||||
return; // ignore incoming events if they are deprecated
|
||||
}
|
||||
lastEventTime = eventTime;
|
||||
handler.triggerChannel(CHANNEL_HOME_EVENT,
|
||||
event.getSubTypeDescription().map(EventSubType::name).orElse(event.getEventType().name()));
|
||||
handler.triggerChannel(CHANNEL_HOME_EVENT, Objects.requireNonNull(
|
||||
event.getSubTypeDescription().map(EventSubType::name).orElse(event.getEventType().name())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +69,8 @@ public class RefreshAutoCapability extends RefreshCapability {
|
||||
@Override
|
||||
protected void updateNAThing(NAThing newData) {
|
||||
super.updateNAThing(newData);
|
||||
dataTimeStamp = newData.getLastSeen().map(ZonedDateTime::toInstant).orElse(Instant.MIN);
|
||||
ZonedDateTime lastSeen = newData.getLastSeen();
|
||||
dataTimeStamp = lastSeen != null ? lastSeen.toInstant() : Instant.MIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -175,25 +176,25 @@ class SecurityCapability extends RestCapability<SecurityApi> {
|
||||
}
|
||||
|
||||
private Collection<HomeEvent> requestDeviceEvents(String moduleId, String deviceType) {
|
||||
return getApi().map(api -> {
|
||||
return Objects.requireNonNull(getApi().map(api -> {
|
||||
try {
|
||||
return api.getDeviceEvents(securityId, moduleId, deviceType);
|
||||
} catch (NetatmoException e) {
|
||||
logger.warn("Error retrieving last events of camera '{}' : {}", moduleId, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}).orElse(List.of());
|
||||
}).orElse(List.of()));
|
||||
}
|
||||
|
||||
private Collection<HomeEvent> requestPersonEvents(String personId) {
|
||||
return getApi().map(api -> {
|
||||
return Objects.requireNonNull(getApi().map(api -> {
|
||||
try {
|
||||
return api.getPersonEvents(securityId, personId);
|
||||
} catch (NetatmoException e) {
|
||||
logger.warn("Error retrieving last events of person '{}' : {}", personId, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}).orElse(List.of());
|
||||
}).orElse(List.of()));
|
||||
}
|
||||
|
||||
public void setPersonAway(String personId, boolean away) {
|
||||
|
@ -16,7 +16,6 @@ import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
|
||||
import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.toDateTimeType;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -42,8 +41,8 @@ public class TimestampChannelHelper extends ChannelHelper {
|
||||
|
||||
@Override
|
||||
protected @Nullable State internalGetProperty(String channelId, NAThing naThing, Configuration config) {
|
||||
Optional<ZonedDateTime> lastSeen = naThing.getLastSeen();
|
||||
return CHANNEL_LAST_SEEN.equals(channelId) && lastSeen.isPresent() ? toDateTimeType(lastSeen) : null;
|
||||
ZonedDateTime lastSeen = naThing.getLastSeen();
|
||||
return CHANNEL_LAST_SEEN.equals(channelId) && lastSeen != null ? toDateTimeType(lastSeen) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,6 @@ package org.openhab.binding.netatmo.internal.utils;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.measure.Unit;
|
||||
|
||||
@ -71,10 +70,6 @@ public class ChannelTypeUtils {
|
||||
return (zonedDateTime == null) ? UnDefType.NULL : new DateTimeType(zonedDateTime);
|
||||
}
|
||||
|
||||
public static State toDateTimeType(Optional<ZonedDateTime> zonedDateTime) {
|
||||
return zonedDateTime.map(zdt -> (State) new DateTimeType(zdt)).orElse(UnDefType.NULL);
|
||||
}
|
||||
|
||||
public static State toQuantityType(@Nullable Double value, MeasureClass measureClass) {
|
||||
if (value != null && !value.isNaN()) {
|
||||
Measure measureDef = measureClass.measureDefinition;
|
||||
|
@ -94,7 +94,7 @@ public abstract class AbstractUplinkCommandCallback extends BufferingResponseLis
|
||||
* Log request success
|
||||
*/
|
||||
@Override
|
||||
public final void onSuccess(@Nullable Response response) {
|
||||
public final void onSuccess(Response response) {
|
||||
super.onSuccess(response);
|
||||
if (response != null) {
|
||||
communicationStatus.setHttpCode(HttpStatus.getCode(response.getStatus()));
|
||||
@ -107,7 +107,9 @@ public abstract class AbstractUplinkCommandCallback extends BufferingResponseLis
|
||||
*/
|
||||
@Override
|
||||
public final void onFailure(@Nullable Response response, @Nullable Throwable failure) {
|
||||
super.onFailure(response, failure);
|
||||
if (response != null && failure != null) {
|
||||
super.onFailure(response, failure);
|
||||
}
|
||||
if (failure != null) {
|
||||
logger.debug("Request failed: {}", failure.toString());
|
||||
communicationStatus.setError((Exception) failure);
|
||||
@ -123,9 +125,10 @@ public abstract class AbstractUplinkCommandCallback extends BufferingResponseLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContent(@Nullable Response response, @Nullable ByteBuffer content) {
|
||||
public void onContent(Response response, ByteBuffer content) {
|
||||
super.onContent(response, content);
|
||||
logger.debug("received content, length: {}", getContentAsString().length());
|
||||
String contentAsString = getContentAsString();
|
||||
logger.debug("received content, length: {}", contentAsString != null ? getContentAsString().length() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.nikohomecontrol.internal.protocol.nhc2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -45,14 +46,16 @@ public class NhcSystemInfo2 {
|
||||
* @return the NhcVersion
|
||||
*/
|
||||
public String getNhcVersion() {
|
||||
return swVersions.stream().map(p -> p.nhcVersion).filter(v -> !v.isEmpty()).findFirst().orElse("");
|
||||
return Objects.requireNonNull(
|
||||
swVersions.stream().map(p -> p.nhcVersion).filter(v -> !v.isEmpty()).findFirst().orElse(""));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the CocoImage version
|
||||
*/
|
||||
public String getCocoImage() {
|
||||
return swVersions.stream().map(p -> p.cocoImage).filter(v -> !v.isEmpty()).findFirst().orElse("");
|
||||
return Objects.requireNonNull(
|
||||
swVersions.stream().map(p -> p.cocoImage).filter(v -> !v.isEmpty()).findFirst().orElse(""));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ import java.net.UnknownHostException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@ -239,9 +240,9 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
|
||||
* HAI only supports one audio player - cycle through features until we find a feature that is an audio
|
||||
* player.
|
||||
*/
|
||||
audioPlayer = reqSystemFeatures().getFeatures().stream()
|
||||
audioPlayer = Objects.requireNonNull(reqSystemFeatures().getFeatures().stream()
|
||||
.map(featureCode -> AudioPlayer.getAudioPlayerForFeatureCode(featureCode))
|
||||
.filter(Optional::isPresent).findFirst().orElse(Optional.empty());
|
||||
.filter(Optional::isPresent).findFirst().orElse(Optional.empty()));
|
||||
|
||||
systemType = SystemType.getType(reqSystemInformation().getModel());
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.pentair.internal.handler.helpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -156,8 +157,8 @@ public class PentairControllerCircuit {
|
||||
}
|
||||
|
||||
public static CircuitName valueOfModeNumber(int number) {
|
||||
return Arrays.stream(values()).filter(value -> (value.getCode() == number)).findFirst()
|
||||
.orElse(CircuitName.EMPTY);
|
||||
return Objects.requireNonNull(Arrays.stream(values()).filter(value -> (value.getCode() == number))
|
||||
.findFirst().orElse(CircuitName.EMPTY));
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,8 +198,8 @@ public class PentairControllerCircuit {
|
||||
}
|
||||
|
||||
public static CircuitFunction valueOfModeNumber(int number) {
|
||||
return Arrays.stream(values()).filter(value -> (value.getCode() == number)).findFirst()
|
||||
.orElse(CircuitFunction.EMPTY);
|
||||
return Objects.requireNonNull(Arrays.stream(values()).filter(value -> (value.getCode() == number))
|
||||
.findFirst().orElse(CircuitFunction.EMPTY));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.pentair.internal.handler.helpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -58,6 +59,7 @@ public enum PentairControllerLightMode {
|
||||
}
|
||||
|
||||
public static PentairControllerLightMode valueOfModeNumber(int modeNumber) {
|
||||
return Arrays.stream(values()).filter(value -> (value.getModeNumber() == modeNumber)).findFirst().orElse(EMPTY);
|
||||
return Objects.requireNonNull(Arrays.stream(values()).filter(value -> (value.getModeNumber() == modeNumber))
|
||||
.findFirst().orElse(EMPTY));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.pentair.internal.handler.helpers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.pentair.internal.parser.PentairStandardPacket;
|
||||
@ -49,7 +50,8 @@ public class PentairHeatStatus {
|
||||
}
|
||||
|
||||
public static HeatMode valueOfCode(int code) {
|
||||
return Arrays.stream(values()).filter(value -> (value.getCode() == code)).findFirst().orElse(EMPTY);
|
||||
return Objects.requireNonNull(
|
||||
Arrays.stream(values()).filter(value -> (value.getCode() == code)).findFirst().orElse(EMPTY));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,12 @@ public class MeterHandler extends BaseThingHandler {
|
||||
|
||||
Properties urlHeader = new Properties();
|
||||
urlHeader.put("CONTENT-TYPE", "application/json");
|
||||
urlHeader.put("Authorization", getTokenFromBridge());
|
||||
String token = getTokenFromBridge();
|
||||
if (token == null) {
|
||||
logger.debug("Unable to get the token from the bridge");
|
||||
return null;
|
||||
}
|
||||
urlHeader.put("Authorization", token);
|
||||
|
||||
String urlResponse = HttpUtil.executeUrl("GET", url, urlHeader, null, null, 2000);
|
||||
|
||||
|
@ -308,7 +308,7 @@ public class PushsaferMessageBuilder {
|
||||
body.addFieldPart(MESSAGE_KEY_ANSWER, new StringContentProvider(String.valueOf(answer)), null);
|
||||
|
||||
body.addFieldPart(MESSAGE_KEY_TIME2LIVE, new StringContentProvider(String.valueOf(time2live)), null);
|
||||
|
||||
String attachment = this.attachment;
|
||||
if (attachment != null) {
|
||||
String localAttachment = attachment;
|
||||
final String encodedString;
|
||||
|
@ -158,11 +158,15 @@ public class RadioThermostatConnector {
|
||||
|
||||
/**
|
||||
* Dispatch an event (key, value) to the event listeners
|
||||
* Events with a null value are discarded
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
private void dispatchKeyValue(String key, String value) {
|
||||
private void dispatchKeyValue(String key, @Nullable String value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
RadioThermostatEvent event = new RadioThermostatEvent(this, key, value);
|
||||
for (RadioThermostatEventListener listener : listeners) {
|
||||
listener.onNewMessageEvent(event);
|
||||
|
@ -56,13 +56,13 @@ public class StatusService {
|
||||
}
|
||||
|
||||
private StatusDTO getStatus(final List<UdpResponseDTO> singleResponse) {
|
||||
return singleResponse.stream()
|
||||
return Objects.requireNonNull(singleResponse.stream()
|
||||
.filter(response -> !response.getAnswer().isEmpty() && response.getAnswer().contains(VERSION_STRING))
|
||||
.map(response -> deserializeString(response.getAnswer()))
|
||||
.filter(statusRaw -> statusRaw.getCode() == 200 && statusRaw.getResponse() == 90)
|
||||
.map(statusRaw -> new StatusDTO(true, statusRaw.getCode(), statusRaw.getData().getSwitchValue(),
|
||||
statusRaw.getData().getWatt(), statusRaw.getData().getAmp()))
|
||||
.findFirst().orElse(new StatusDTO(false, 503, null, null, null));
|
||||
.findFirst().orElse(new StatusDTO(false, 503, null, null, null)));
|
||||
}
|
||||
|
||||
private StatusRawDTO deserializeString(String response) {
|
||||
|
@ -66,10 +66,10 @@ public class SwitchService {
|
||||
}
|
||||
|
||||
private SwitchResponseDTO getSwitchResponse(final List<UdpResponseDTO> singleResponse) {
|
||||
return singleResponse.stream().filter(response -> !response.getAnswer().isEmpty())
|
||||
return Objects.requireNonNull(singleResponse.stream().filter(response -> !response.getAnswer().isEmpty())
|
||||
.map(response -> deserializeString(response.getAnswer()))
|
||||
.filter(switchResponse -> switchResponse.getCode() == 200 && switchResponse.getResponse() == 20)
|
||||
.findFirst().orElse(new SwitchResponseDTO(0, 503));
|
||||
.findFirst().orElse(new SwitchResponseDTO(0, 503)));
|
||||
}
|
||||
|
||||
private SwitchResponseDTO deserializeString(String response) {
|
||||
|
@ -58,10 +58,11 @@ package org.openhab.binding.sagercaster.internal.caster;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.ServiceScope;
|
||||
@ -89,7 +90,7 @@ public class SagerWeatherCaster {
|
||||
private final Logger logger = LoggerFactory.getLogger(SagerWeatherCaster.class);
|
||||
private final Properties forecaster = new Properties();
|
||||
|
||||
private Optional<SagerPrediction> prevision = Optional.empty();
|
||||
private @Nullable SagerPrediction prevision;
|
||||
private String[] usedDirections = NTZDIRECTIONS; // Defaulted to Northern Zone
|
||||
|
||||
private int currentBearing = -1;
|
||||
@ -107,7 +108,7 @@ public class SagerWeatherCaster {
|
||||
public SagerWeatherCaster() {
|
||||
try (InputStream input = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream("/sagerForecaster.properties")) {
|
||||
forecaster.load(input);
|
||||
forecaster.load(Objects.requireNonNull(input));
|
||||
} catch (IOException e) {
|
||||
logger.warn("Error during Sager Forecaster startup", e);
|
||||
}
|
||||
@ -319,27 +320,31 @@ public class SagerWeatherCaster {
|
||||
}
|
||||
}
|
||||
String forecast = forecaster.getProperty(d1 + sagerPressure + pressureEvolution + nubes);
|
||||
prevision = Optional.ofNullable(forecast != null ? new SagerPrediction(forecast) : null);
|
||||
prevision = forecast != null ? new SagerPrediction(forecast) : null;
|
||||
}
|
||||
|
||||
public String getForecast() {
|
||||
return prevision.map(p -> p.getForecast()).orElse(UNDEF);
|
||||
return Objects.requireNonNullElse(this.prevision.getForecast(), UNDEF);
|
||||
}
|
||||
|
||||
public String getWindVelocity() {
|
||||
return prevision.map(p -> p.getWindVelocity()).orElse(UNDEF);
|
||||
SagerPrediction prevision = this.prevision;
|
||||
return prevision != null ? prevision.getWindVelocity() : UNDEF;
|
||||
}
|
||||
|
||||
public String getWindDirection() {
|
||||
return prevision.map(p -> p.getWindDirection()).orElse(UNDEF);
|
||||
SagerPrediction prevision = this.prevision;
|
||||
return prevision != null ? prevision.getWindDirection() : UNDEF;
|
||||
}
|
||||
|
||||
public String getWindDirection2() {
|
||||
return prevision.map(p -> p.getWindDirection2()).orElse(UNDEF);
|
||||
SagerPrediction prevision = this.prevision;
|
||||
return prevision != null ? prevision.getWindDirection2() : UNDEF;
|
||||
}
|
||||
|
||||
public String getSagerCode() {
|
||||
return prevision.map(p -> p.getSagerCode()).orElse(UNDEF);
|
||||
SagerPrediction prevision = this.prevision;
|
||||
return prevision != null ? prevision.getSagerCode() : UNDEF;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
|
@ -23,7 +23,6 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -272,7 +271,8 @@ public class SAICiSMARTBridgeHandler extends BaseBridgeHandler {
|
||||
}
|
||||
|
||||
public Collection<VinInfo> getVinList() {
|
||||
return Optional.ofNullable(vinList).orElse(Collections.emptyList());
|
||||
Collection<VinInfo> vinList = this.vinList;
|
||||
return vinList != null ? vinList : Collections.emptyList();
|
||||
}
|
||||
|
||||
public String sendRequest(String request, String endpoint)
|
||||
|
@ -15,6 +15,7 @@ package org.openhab.binding.samsungtv.internal;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@ -52,7 +53,7 @@ public class Utils {
|
||||
} catch (ParserConfigurationException e) {
|
||||
LOGGER.debug("XMLParser Configuration Error: {}", e.getMessage());
|
||||
}
|
||||
return Optional.ofNullable(factory).orElse(DocumentBuilderFactory.newInstance());
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,30 +86,32 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static String getModelName(@Nullable RemoteDevice device) {
|
||||
return Optional.ofNullable(device).map(a -> a.getDetails()).map(a -> a.getModelDetails())
|
||||
.map(a -> a.getModelName()).orElse("");
|
||||
return Objects.requireNonNull(Optional.ofNullable(device).map(a -> a.getDetails()).map(a -> a.getModelDetails())
|
||||
.map(a -> a.getModelName()).orElse(""));
|
||||
}
|
||||
|
||||
public static String getManufacturer(@Nullable RemoteDevice device) {
|
||||
return Optional.ofNullable(device).map(a -> a.getDetails()).map(a -> a.getManufacturerDetails())
|
||||
.map(a -> a.getManufacturer()).orElse("");
|
||||
return Objects.requireNonNull(Optional.ofNullable(device).map(a -> a.getDetails())
|
||||
.map(a -> a.getManufacturerDetails()).map(a -> a.getManufacturer()).orElse(""));
|
||||
}
|
||||
|
||||
public static String getFriendlyName(@Nullable RemoteDevice device) {
|
||||
return Optional.ofNullable(device).map(a -> a.getDetails()).map(a -> a.getFriendlyName()).orElse("");
|
||||
return Objects.requireNonNull(
|
||||
Optional.ofNullable(device).map(a -> a.getDetails()).map(a -> a.getFriendlyName()).orElse(""));
|
||||
}
|
||||
|
||||
public static String getUdn(@Nullable RemoteDevice device) {
|
||||
return Optional.ofNullable(device).map(a -> a.getIdentity()).map(a -> a.getUdn())
|
||||
.map(a -> a.getIdentifierString()).orElse("");
|
||||
return Objects.requireNonNull(Optional.ofNullable(device).map(a -> a.getIdentity()).map(a -> a.getUdn())
|
||||
.map(a -> a.getIdentifierString()).orElse(""));
|
||||
}
|
||||
|
||||
public static String getHost(@Nullable RemoteDevice device) {
|
||||
return Optional.ofNullable(device).map(a -> a.getIdentity()).map(a -> a.getDescriptorURL())
|
||||
.map(a -> a.getHost()).orElse("");
|
||||
return Objects.requireNonNull(Optional.ofNullable(device).map(a -> a.getIdentity())
|
||||
.map(a -> a.getDescriptorURL()).map(a -> a.getHost()).orElse(""));
|
||||
}
|
||||
|
||||
public static String getType(@Nullable RemoteDevice device) {
|
||||
return Optional.ofNullable(device).map(a -> a.getType()).map(a -> a.getType()).orElse("");
|
||||
return Objects
|
||||
.requireNonNull(Optional.ofNullable(device).map(a -> a.getType()).map(a -> a.getType()).orElse(""));
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +105,11 @@ public class RemoteControllerWebSocket extends RemoteController implements Liste
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return Optional.ofNullable(appId).orElse("");
|
||||
return appId != null ? appId : "";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Optional.ofNullable(name).orElse("");
|
||||
return name != null ? name : "";
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user