[miio] cleanup some sat errors (#10539)

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2021-04-22 20:39:23 +02:00 committed by GitHub
parent f87a7f6914
commit df18f16d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 21 deletions

View File

@ -12,20 +12,22 @@
*/
package org.openhab.binding.miio.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link MiIoBindingConfiguration} class defines variables which are
* used for the binding configuration.
*
* @author Marcel Verpaalen - Initial contribution
*/
@SuppressWarnings("null")
@NonNullByDefault
public final class MiIoBindingConfiguration {
public String host;
public String token;
public String deviceId;
public String model;
public String communication;
public int refreshInterval;
public int timeout;
public String cloudServer;
public String host = "";
public String token = "";
public String deviceId = "";
public String model = "";
public String communication = "direct";
public int refreshInterval = 30;
public int timeout = 15000;
public String cloudServer = "";
}

View File

@ -133,7 +133,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
final MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
this.configuration = configuration;
if (configuration.host == null || configuration.host.isEmpty()) {
if (configuration.host.isEmpty()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"IP address required. Configure IP address");
return;
@ -142,7 +142,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Token required. Configure token");
return;
}
cloudServer = (configuration.cloudServer != null) ? configuration.cloudServer : "";
this.cloudServer = configuration.cloudServer;
isIdentified = false;
miIoScheduler.schedule(this::initializeData, 1, TimeUnit.SECONDS);
int pollingPeriod = configuration.refreshInterval;
@ -262,7 +262,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
// use direct communications and in case of failures fall back to cloud communication. For now we keep it
// simple and only have the option for cloud or direct.
final MiIoBindingConfiguration configuration = this.configuration;
if (configuration != null && configuration.communication != null) {
if (configuration != null) {
return configuration.communication.equals("cloud") ? cloudServer : "";
}
return "";
@ -333,13 +333,13 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
return miioCom;
}
final MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
if (configuration.host == null || configuration.host.isEmpty()) {
if (configuration.host.isBlank()) {
return null;
}
@Nullable
String deviceId = configuration.deviceId;
try {
if (deviceId != null && deviceId.length() == 8 && tokenCheckPass(configuration.token)) {
if (deviceId.length() == 8 && tokenCheckPass(configuration.token)) {
final MiIoAsyncCommunication miioCom = new MiIoAsyncCommunication(configuration.host, token,
Utils.hexStringToByteArray(deviceId), lastId, configuration.timeout, cloudConnector);
if (getCloudServer().isBlank()) {
@ -444,7 +444,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
String model = miioInfo.get("model").getAsString();
miDevice = MiIoDevices.getType(model);
if (configuration.model == null || configuration.model.isEmpty()) {
if (configuration.model.isEmpty()) {
Configuration config = editConfiguration();
config.put(PROPERTY_MODEL, model);
updateConfiguration(config);

View File

@ -367,7 +367,7 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
return;
}
if (!hasChannelStructure) {
if (configuration.model == null || configuration.model.isEmpty()) {
if (configuration.model.isEmpty()) {
logger.debug("Model needs to be determined");
isIdentified = false;
} else {
@ -579,7 +579,7 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
} else {
String strVal = val.getAsString().toLowerCase();
updateState(basicChannel.getChannel(),
strVal.equals("on") || strVal.equals("true") ? OnOffType.ON : OnOffType.OFF);
"on".equals(strVal) || "true".equals(strVal) ? OnOffType.ON : OnOffType.OFF);
}
break;
case "color":

View File

@ -76,7 +76,7 @@ public class MiIoUnsupportedHandler extends MiIoAbstractHandler {
private int lastCommand = -1;
private LinkedHashMap<Integer, MiIoBasicChannel> testChannelList = new LinkedHashMap<>();
private LinkedHashMap<MiIoBasicChannel, String> supportedChannelList = new LinkedHashMap<>();
private String model = conf.model != null ? conf.model : "";
private String model = conf.model;
private final ExpiringCache<Boolean> updateDataCache = new ExpiringCache<>(CACHE_EXPIRY, () -> {
miIoScheduler.schedule(this::updateData, 0, TimeUnit.SECONDS);

View File

@ -333,7 +333,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
control = "undef";
break;
}
if (control.equals("undef")) {
if ("undef".equals(control)) {
updateState(CHANNEL_CONTROL, UnDefType.UNDEF);
} else {
updateState(CHANNEL_CONTROL, new StringType(control));
@ -646,8 +646,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
final MiIoBindingConfiguration configuration = this.configuration;
if (configuration != null && cloudConnector.isConnected()) {
try {
final @Nullable RawType mapDl = cloudConnector.getMap(map,
(configuration.cloudServer != null) ? configuration.cloudServer : "");
final @Nullable RawType mapDl = cloudConnector.getMap(map, configuration.cloudServer);
if (mapDl != null) {
byte[] mapData = mapDl.getBytes();
RRMapDraw rrMap = RRMapDraw.loadImage(new ByteArrayInputStream(mapData));