Add RSSI channel to intesisHome and fixed some NPEs (#13244)

Signed-off-by: Hans-Jörg Merk <github@hmerk.de>
This commit is contained in:
Hans-Jörg Merk 2022-08-12 10:51:42 +02:00 committed by GitHub
parent e4c9a40d03
commit 9b128c2f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 236 additions and 179 deletions

View File

@ -42,7 +42,7 @@ The binding uses the following configuration parameters.
| outdoorTemperature | Number:Temperature | (Readonly) The outdoor air temperature (if applicable) | |
| errorStatus | String | (Readonly) The error status of the device | OK,ERR |
| errorCode | String | (Readonly) The error code if an error encountered | not documented |
| wifiSignal | Number | (Readonly) WiFi signal strength (IntesisBox only) | 4=excellent, 3=very good, 2=good, 1=acceptable, 0=low |
| wifiSignal | Number | (Readonly) WiFi signal strength | 4=excellent, 3=very good, 2=good, 1=acceptable, 0=low |
Note that individual A/C units may not support all channels, or all possible values for those channels.

View File

@ -34,8 +34,6 @@ import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link IntesisHandlerFactory} is responsible for creating things and thing
@ -47,7 +45,6 @@ import org.slf4j.LoggerFactory;
@Component(configurationPid = "binding.intesis", service = ThingHandlerFactory.class)
public class IntesisHandlerFactory extends BaseThingHandlerFactory {
private final Logger logger = LoggerFactory.getLogger(IntesisHandlerFactory.class);
private final HttpClient httpClient;
private final IntesisDynamicStateDescriptionProvider intesisStateDescriptionProvider;

View File

@ -41,6 +41,7 @@ import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Dpval;
import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Id;
import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Info;
import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Response;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
@ -222,8 +223,12 @@ public class IntesisHomeHandler extends BaseThingHandler {
"{\"command\":\"login\",\"data\":{\"username\":\"Admin\",\"password\":\"" + config.password + "\"}}",
resp -> {
Data data = gson.fromJson(resp.data, Data.class);
if (data != null) {
Id id = gson.fromJson(data.id, Id.class);
if (id != null) {
sessionId[0] = id.sessionID.toString();
}
}
});
if (sessionId[0] != null && !sessionId[0].isEmpty()) {
updateStatus(ThingStatus.ONLINE);
@ -243,13 +248,45 @@ public class IntesisHomeHandler extends BaseThingHandler {
public void populateProperties() {
postRequest("{\"command\":\"getinfo\",\"data\":\"\"}", resp -> {
Data data = gson.fromJson(resp.data, Data.class);
if (data != null) {
Info info = gson.fromJson(data.info, Info.class);
if (info != null) {
properties.put(PROPERTY_VENDOR, "Intesis");
properties.put(PROPERTY_MODEL_ID, info.deviceModel);
properties.put(PROPERTY_SERIAL_NUMBER, info.sn);
properties.put(PROPERTY_FIRMWARE_VERSION, info.fwVersion);
properties.put(PROPERTY_MAC_ADDRESS, info.wlanSTAMAC);
updateStatus(ThingStatus.ONLINE);
}
}
});
}
public void getWiFiSignal() {
postRequest("{\"command\":\"getinfo\",\"data\":\"\"}", resp -> {
Data data = gson.fromJson(resp.data, Data.class);
if (data != null) {
Info info = gson.fromJson(data.info, Info.class);
if (info != null) {
String rssi = info.rssi;
int dbm = Integer.valueOf(rssi);
int strength = -1;
if (dbm > -60) {
strength = 4;
} else if (dbm > -70) {
strength = 3;
} else if (dbm > -80) {
strength = 2;
} else if (dbm > -90) {
strength = 1;
} else {
strength = 0;
}
DecimalType signalStrength = new DecimalType(strength);
updateState(CHANNEL_TYPE_RSSI, signalStrength);
}
}
});
}
@ -279,11 +316,14 @@ public class IntesisHomeHandler extends BaseThingHandler {
String response = api.postRequest(config.ipAddress, request);
if (response != null) {
Response resp = gson.fromJson(response, Response.class);
if (resp != null) {
boolean success = resp.success;
if (success) {
handler.accept(resp);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Request unsuccessful");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Request unsuccessful");
}
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No Response");
@ -308,14 +348,18 @@ public class IntesisHomeHandler extends BaseThingHandler {
private void handleDataPointsResponse(Response response) {
try {
Data data = gson.fromJson(response.data, Data.class);
if (data != null) {
Dp dp = gson.fromJson(data.dp, Dp.class);
if (dp != null) {
Datapoints[] datapoints = gson.fromJson(dp.datapoints, Datapoints[].class);
if (datapoints != null) {
for (Datapoints datapoint : datapoints) {
Descr descr = gson.fromJson(datapoint.descr, Descr.class);
String channelId = "";
String itemType = "String";
switch (datapoint.uid) {
case 2:
if (descr != null) {
List<String> opModes = new ArrayList<>();
for (String modString : descr.states) {
switch (modString) {
@ -335,12 +379,14 @@ public class IntesisHomeHandler extends BaseThingHandler {
opModes.add("COOL");
break;
}
}
properties.put("supported modes", opModes.toString());
channelId = CHANNEL_TYPE_MODE;
addChannel(channelId, itemType, opModes);
}
}
break;
case 4:
if (descr != null) {
List<String> fanLevels = new ArrayList<>();
for (String fanString : descr.states) {
if ("AUTO".contentEquals(fanString)) {
@ -352,10 +398,12 @@ public class IntesisHomeHandler extends BaseThingHandler {
properties.put("supported fan levels", fanLevels.toString());
channelId = CHANNEL_TYPE_FANSPEED;
addChannel(channelId, itemType, fanLevels);
}
break;
case 5:
case 6:
List<String> swingModes = new ArrayList<>();
if (descr != null) {
for (String swingString : descr.states) {
if ("AUTO".contentEquals(swingString)) {
swingModes.add("AUTO");
@ -368,6 +416,8 @@ public class IntesisHomeHandler extends BaseThingHandler {
} else {
swingModes.add(swingString);
}
}
}
switch (datapoint.uid) {
case 5:
@ -409,6 +459,9 @@ public class IntesisHomeHandler extends BaseThingHandler {
break;
}
}
}
}
}
} catch (JsonSyntaxException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
@ -423,12 +476,15 @@ public class IntesisHomeHandler extends BaseThingHandler {
private void getAllUidValues() {
postRequestInSession(sessionId -> "{\"command\":\"getdatapointvalue\",\"data\":{\"sessionID\":\"" + sessionId
+ "\", \"uid\":\"all\"}}", this::handleDataPointValues);
getWiFiSignal();
}
private void handleDataPointValues(Response response) {
try {
Data data = gson.fromJson(response.data, Data.class);
if (data != null) {
Dpval[] dpval = gson.fromJson(data.dpval, Dpval[].class);
if (dpval != null) {
for (Dpval element : dpval) {
logger.trace("UID : {} ; value : {}", element.uid, element.value);
switch (element.uid) {
@ -459,7 +515,8 @@ public class IntesisHomeHandler extends BaseThingHandler {
if ((element.value) == 0) {
updateState(CHANNEL_TYPE_FANSPEED, StringType.valueOf("AUTO"));
} else {
updateState(CHANNEL_TYPE_FANSPEED, StringType.valueOf(String.valueOf(element.value)));
updateState(CHANNEL_TYPE_FANSPEED,
StringType.valueOf(String.valueOf(element.value)));
}
break;
case 5:
@ -509,6 +566,8 @@ public class IntesisHomeHandler extends BaseThingHandler {
break;
}
}
}
}
} catch (JsonSyntaxException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}

View File

@ -9,6 +9,7 @@
<description>Represents a single IntesisHome WiFi adapter on the network, connected to an A/C unit.</description>
<channels>
<channel id="power" typeId="system.power"/>
<channel id="wifiSignal" typeId="system.signal-strength"/>
</channels>
<config-description>
<parameter name="ipAddress" type="text" required="true">