[miio] cleanup some sat errors (#10539)
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
@@ -12,20 +12,22 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.miio.internal;
|
package org.openhab.binding.miio.internal;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link MiIoBindingConfiguration} class defines variables which are
|
* The {@link MiIoBindingConfiguration} class defines variables which are
|
||||||
* used for the binding configuration.
|
* used for the binding configuration.
|
||||||
*
|
*
|
||||||
* @author Marcel Verpaalen - Initial contribution
|
* @author Marcel Verpaalen - Initial contribution
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("null")
|
@NonNullByDefault
|
||||||
public final class MiIoBindingConfiguration {
|
public final class MiIoBindingConfiguration {
|
||||||
public String host;
|
public String host = "";
|
||||||
public String token;
|
public String token = "";
|
||||||
public String deviceId;
|
public String deviceId = "";
|
||||||
public String model;
|
public String model = "";
|
||||||
public String communication;
|
public String communication = "direct";
|
||||||
public int refreshInterval;
|
public int refreshInterval = 30;
|
||||||
public int timeout;
|
public int timeout = 15000;
|
||||||
public String cloudServer;
|
public String cloudServer = "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
|
|||||||
|
|
||||||
final MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
|
final MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
if (configuration.host == null || configuration.host.isEmpty()) {
|
if (configuration.host.isEmpty()) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"IP address required. Configure IP address");
|
"IP address required. Configure IP address");
|
||||||
return;
|
return;
|
||||||
@@ -142,7 +142,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
|
|||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Token required. Configure token");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Token required. Configure token");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cloudServer = (configuration.cloudServer != null) ? configuration.cloudServer : "";
|
this.cloudServer = configuration.cloudServer;
|
||||||
isIdentified = false;
|
isIdentified = false;
|
||||||
miIoScheduler.schedule(this::initializeData, 1, TimeUnit.SECONDS);
|
miIoScheduler.schedule(this::initializeData, 1, TimeUnit.SECONDS);
|
||||||
int pollingPeriod = configuration.refreshInterval;
|
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
|
// 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.
|
// simple and only have the option for cloud or direct.
|
||||||
final MiIoBindingConfiguration configuration = this.configuration;
|
final MiIoBindingConfiguration configuration = this.configuration;
|
||||||
if (configuration != null && configuration.communication != null) {
|
if (configuration != null) {
|
||||||
return configuration.communication.equals("cloud") ? cloudServer : "";
|
return configuration.communication.equals("cloud") ? cloudServer : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -333,13 +333,13 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
|
|||||||
return miioCom;
|
return miioCom;
|
||||||
}
|
}
|
||||||
final MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
|
final MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
|
||||||
if (configuration.host == null || configuration.host.isEmpty()) {
|
if (configuration.host.isBlank()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Nullable
|
@Nullable
|
||||||
String deviceId = configuration.deviceId;
|
String deviceId = configuration.deviceId;
|
||||||
try {
|
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,
|
final MiIoAsyncCommunication miioCom = new MiIoAsyncCommunication(configuration.host, token,
|
||||||
Utils.hexStringToByteArray(deviceId), lastId, configuration.timeout, cloudConnector);
|
Utils.hexStringToByteArray(deviceId), lastId, configuration.timeout, cloudConnector);
|
||||||
if (getCloudServer().isBlank()) {
|
if (getCloudServer().isBlank()) {
|
||||||
@@ -444,7 +444,7 @@ public abstract class MiIoAbstractHandler extends BaseThingHandler implements Mi
|
|||||||
MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
|
MiIoBindingConfiguration configuration = getConfigAs(MiIoBindingConfiguration.class);
|
||||||
String model = miioInfo.get("model").getAsString();
|
String model = miioInfo.get("model").getAsString();
|
||||||
miDevice = MiIoDevices.getType(model);
|
miDevice = MiIoDevices.getType(model);
|
||||||
if (configuration.model == null || configuration.model.isEmpty()) {
|
if (configuration.model.isEmpty()) {
|
||||||
Configuration config = editConfiguration();
|
Configuration config = editConfiguration();
|
||||||
config.put(PROPERTY_MODEL, model);
|
config.put(PROPERTY_MODEL, model);
|
||||||
updateConfiguration(config);
|
updateConfiguration(config);
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!hasChannelStructure) {
|
if (!hasChannelStructure) {
|
||||||
if (configuration.model == null || configuration.model.isEmpty()) {
|
if (configuration.model.isEmpty()) {
|
||||||
logger.debug("Model needs to be determined");
|
logger.debug("Model needs to be determined");
|
||||||
isIdentified = false;
|
isIdentified = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -579,7 +579,7 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
|
|||||||
} else {
|
} else {
|
||||||
String strVal = val.getAsString().toLowerCase();
|
String strVal = val.getAsString().toLowerCase();
|
||||||
updateState(basicChannel.getChannel(),
|
updateState(basicChannel.getChannel(),
|
||||||
strVal.equals("on") || strVal.equals("true") ? OnOffType.ON : OnOffType.OFF);
|
"on".equals(strVal) || "true".equals(strVal) ? OnOffType.ON : OnOffType.OFF);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "color":
|
case "color":
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class MiIoUnsupportedHandler extends MiIoAbstractHandler {
|
|||||||
private int lastCommand = -1;
|
private int lastCommand = -1;
|
||||||
private LinkedHashMap<Integer, MiIoBasicChannel> testChannelList = new LinkedHashMap<>();
|
private LinkedHashMap<Integer, MiIoBasicChannel> testChannelList = new LinkedHashMap<>();
|
||||||
private LinkedHashMap<MiIoBasicChannel, String> supportedChannelList = 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, () -> {
|
private final ExpiringCache<Boolean> updateDataCache = new ExpiringCache<>(CACHE_EXPIRY, () -> {
|
||||||
miIoScheduler.schedule(this::updateData, 0, TimeUnit.SECONDS);
|
miIoScheduler.schedule(this::updateData, 0, TimeUnit.SECONDS);
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
|
|||||||
control = "undef";
|
control = "undef";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (control.equals("undef")) {
|
if ("undef".equals(control)) {
|
||||||
updateState(CHANNEL_CONTROL, UnDefType.UNDEF);
|
updateState(CHANNEL_CONTROL, UnDefType.UNDEF);
|
||||||
} else {
|
} else {
|
||||||
updateState(CHANNEL_CONTROL, new StringType(control));
|
updateState(CHANNEL_CONTROL, new StringType(control));
|
||||||
@@ -646,8 +646,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
|
|||||||
final MiIoBindingConfiguration configuration = this.configuration;
|
final MiIoBindingConfiguration configuration = this.configuration;
|
||||||
if (configuration != null && cloudConnector.isConnected()) {
|
if (configuration != null && cloudConnector.isConnected()) {
|
||||||
try {
|
try {
|
||||||
final @Nullable RawType mapDl = cloudConnector.getMap(map,
|
final @Nullable RawType mapDl = cloudConnector.getMap(map, configuration.cloudServer);
|
||||||
(configuration.cloudServer != null) ? configuration.cloudServer : "");
|
|
||||||
if (mapDl != null) {
|
if (mapDl != null) {
|
||||||
byte[] mapData = mapDl.getBytes();
|
byte[] mapData = mapDl.getBytes();
|
||||||
RRMapDraw rrMap = RRMapDraw.loadImage(new ByteArrayInputStream(mapData));
|
RRMapDraw rrMap = RRMapDraw.loadImage(new ByteArrayInputStream(mapData));
|
||||||
|
|||||||
Reference in New Issue
Block a user