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:
parent
e4c9a40d03
commit
9b128c2f7d
@ -42,7 +42,7 @@ The binding uses the following configuration parameters.
|
|||||||
| outdoorTemperature | Number:Temperature | (Readonly) The outdoor air temperature (if applicable) | |
|
| outdoorTemperature | Number:Temperature | (Readonly) The outdoor air temperature (if applicable) | |
|
||||||
| errorStatus | String | (Readonly) The error status of the device | OK,ERR |
|
| errorStatus | String | (Readonly) The error status of the device | OK,ERR |
|
||||||
| errorCode | String | (Readonly) The error code if an error encountered | not documented |
|
| 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.
|
Note that individual A/C units may not support all channels, or all possible values for those channels.
|
||||||
|
|
||||||
|
|||||||
@ -34,8 +34,6 @@ import org.osgi.service.component.ComponentContext;
|
|||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
import org.osgi.service.component.annotations.Reference;
|
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
|
* 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)
|
@Component(configurationPid = "binding.intesis", service = ThingHandlerFactory.class)
|
||||||
public class IntesisHandlerFactory extends BaseThingHandlerFactory {
|
public class IntesisHandlerFactory extends BaseThingHandlerFactory {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(IntesisHandlerFactory.class);
|
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private final IntesisDynamicStateDescriptionProvider intesisStateDescriptionProvider;
|
private final IntesisDynamicStateDescriptionProvider intesisStateDescriptionProvider;
|
||||||
|
|
||||||
|
|||||||
@ -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.Id;
|
||||||
import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Info;
|
import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Info;
|
||||||
import org.openhab.binding.intesis.internal.gson.IntesisHomeJSonDTO.Response;
|
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.OnOffType;
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
@ -222,8 +223,12 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
"{\"command\":\"login\",\"data\":{\"username\":\"Admin\",\"password\":\"" + config.password + "\"}}",
|
"{\"command\":\"login\",\"data\":{\"username\":\"Admin\",\"password\":\"" + config.password + "\"}}",
|
||||||
resp -> {
|
resp -> {
|
||||||
Data data = gson.fromJson(resp.data, Data.class);
|
Data data = gson.fromJson(resp.data, Data.class);
|
||||||
|
if (data != null) {
|
||||||
Id id = gson.fromJson(data.id, Id.class);
|
Id id = gson.fromJson(data.id, Id.class);
|
||||||
|
if (id != null) {
|
||||||
sessionId[0] = id.sessionID.toString();
|
sessionId[0] = id.sessionID.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (sessionId[0] != null && !sessionId[0].isEmpty()) {
|
if (sessionId[0] != null && !sessionId[0].isEmpty()) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
@ -243,13 +248,45 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
public void populateProperties() {
|
public void populateProperties() {
|
||||||
postRequest("{\"command\":\"getinfo\",\"data\":\"\"}", resp -> {
|
postRequest("{\"command\":\"getinfo\",\"data\":\"\"}", resp -> {
|
||||||
Data data = gson.fromJson(resp.data, Data.class);
|
Data data = gson.fromJson(resp.data, Data.class);
|
||||||
|
if (data != null) {
|
||||||
Info info = gson.fromJson(data.info, Info.class);
|
Info info = gson.fromJson(data.info, Info.class);
|
||||||
|
if (info != null) {
|
||||||
properties.put(PROPERTY_VENDOR, "Intesis");
|
properties.put(PROPERTY_VENDOR, "Intesis");
|
||||||
properties.put(PROPERTY_MODEL_ID, info.deviceModel);
|
properties.put(PROPERTY_MODEL_ID, info.deviceModel);
|
||||||
properties.put(PROPERTY_SERIAL_NUMBER, info.sn);
|
properties.put(PROPERTY_SERIAL_NUMBER, info.sn);
|
||||||
properties.put(PROPERTY_FIRMWARE_VERSION, info.fwVersion);
|
properties.put(PROPERTY_FIRMWARE_VERSION, info.fwVersion);
|
||||||
properties.put(PROPERTY_MAC_ADDRESS, info.wlanSTAMAC);
|
properties.put(PROPERTY_MAC_ADDRESS, info.wlanSTAMAC);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
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);
|
String response = api.postRequest(config.ipAddress, request);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
Response resp = gson.fromJson(response, Response.class);
|
Response resp = gson.fromJson(response, Response.class);
|
||||||
|
if (resp != null) {
|
||||||
boolean success = resp.success;
|
boolean success = resp.success;
|
||||||
if (success) {
|
if (success) {
|
||||||
handler.accept(resp);
|
handler.accept(resp);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Request unsuccessful");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
|
"Request unsuccessful");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No Response");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "No Response");
|
||||||
@ -308,14 +348,18 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
private void handleDataPointsResponse(Response response) {
|
private void handleDataPointsResponse(Response response) {
|
||||||
try {
|
try {
|
||||||
Data data = gson.fromJson(response.data, Data.class);
|
Data data = gson.fromJson(response.data, Data.class);
|
||||||
|
if (data != null) {
|
||||||
Dp dp = gson.fromJson(data.dp, Dp.class);
|
Dp dp = gson.fromJson(data.dp, Dp.class);
|
||||||
|
if (dp != null) {
|
||||||
Datapoints[] datapoints = gson.fromJson(dp.datapoints, Datapoints[].class);
|
Datapoints[] datapoints = gson.fromJson(dp.datapoints, Datapoints[].class);
|
||||||
|
if (datapoints != null) {
|
||||||
for (Datapoints datapoint : datapoints) {
|
for (Datapoints datapoint : datapoints) {
|
||||||
Descr descr = gson.fromJson(datapoint.descr, Descr.class);
|
Descr descr = gson.fromJson(datapoint.descr, Descr.class);
|
||||||
String channelId = "";
|
String channelId = "";
|
||||||
String itemType = "String";
|
String itemType = "String";
|
||||||
switch (datapoint.uid) {
|
switch (datapoint.uid) {
|
||||||
case 2:
|
case 2:
|
||||||
|
if (descr != null) {
|
||||||
List<String> opModes = new ArrayList<>();
|
List<String> opModes = new ArrayList<>();
|
||||||
for (String modString : descr.states) {
|
for (String modString : descr.states) {
|
||||||
switch (modString) {
|
switch (modString) {
|
||||||
@ -335,12 +379,14 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
opModes.add("COOL");
|
opModes.add("COOL");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
properties.put("supported modes", opModes.toString());
|
properties.put("supported modes", opModes.toString());
|
||||||
channelId = CHANNEL_TYPE_MODE;
|
channelId = CHANNEL_TYPE_MODE;
|
||||||
addChannel(channelId, itemType, opModes);
|
addChannel(channelId, itemType, opModes);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
|
if (descr != null) {
|
||||||
List<String> fanLevels = new ArrayList<>();
|
List<String> fanLevels = new ArrayList<>();
|
||||||
for (String fanString : descr.states) {
|
for (String fanString : descr.states) {
|
||||||
if ("AUTO".contentEquals(fanString)) {
|
if ("AUTO".contentEquals(fanString)) {
|
||||||
@ -352,10 +398,12 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
properties.put("supported fan levels", fanLevels.toString());
|
properties.put("supported fan levels", fanLevels.toString());
|
||||||
channelId = CHANNEL_TYPE_FANSPEED;
|
channelId = CHANNEL_TYPE_FANSPEED;
|
||||||
addChannel(channelId, itemType, fanLevels);
|
addChannel(channelId, itemType, fanLevels);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
case 6:
|
case 6:
|
||||||
List<String> swingModes = new ArrayList<>();
|
List<String> swingModes = new ArrayList<>();
|
||||||
|
if (descr != null) {
|
||||||
for (String swingString : descr.states) {
|
for (String swingString : descr.states) {
|
||||||
if ("AUTO".contentEquals(swingString)) {
|
if ("AUTO".contentEquals(swingString)) {
|
||||||
swingModes.add("AUTO");
|
swingModes.add("AUTO");
|
||||||
@ -368,6 +416,8 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
} else {
|
} else {
|
||||||
swingModes.add(swingString);
|
swingModes.add(swingString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch (datapoint.uid) {
|
switch (datapoint.uid) {
|
||||||
case 5:
|
case 5:
|
||||||
@ -409,6 +459,9 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
@ -423,12 +476,15 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
private void getAllUidValues() {
|
private void getAllUidValues() {
|
||||||
postRequestInSession(sessionId -> "{\"command\":\"getdatapointvalue\",\"data\":{\"sessionID\":\"" + sessionId
|
postRequestInSession(sessionId -> "{\"command\":\"getdatapointvalue\",\"data\":{\"sessionID\":\"" + sessionId
|
||||||
+ "\", \"uid\":\"all\"}}", this::handleDataPointValues);
|
+ "\", \"uid\":\"all\"}}", this::handleDataPointValues);
|
||||||
|
getWiFiSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDataPointValues(Response response) {
|
private void handleDataPointValues(Response response) {
|
||||||
try {
|
try {
|
||||||
Data data = gson.fromJson(response.data, Data.class);
|
Data data = gson.fromJson(response.data, Data.class);
|
||||||
|
if (data != null) {
|
||||||
Dpval[] dpval = gson.fromJson(data.dpval, Dpval[].class);
|
Dpval[] dpval = gson.fromJson(data.dpval, Dpval[].class);
|
||||||
|
if (dpval != null) {
|
||||||
for (Dpval element : dpval) {
|
for (Dpval element : dpval) {
|
||||||
logger.trace("UID : {} ; value : {}", element.uid, element.value);
|
logger.trace("UID : {} ; value : {}", element.uid, element.value);
|
||||||
switch (element.uid) {
|
switch (element.uid) {
|
||||||
@ -459,7 +515,8 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
if ((element.value) == 0) {
|
if ((element.value) == 0) {
|
||||||
updateState(CHANNEL_TYPE_FANSPEED, StringType.valueOf("AUTO"));
|
updateState(CHANNEL_TYPE_FANSPEED, StringType.valueOf("AUTO"));
|
||||||
} else {
|
} else {
|
||||||
updateState(CHANNEL_TYPE_FANSPEED, StringType.valueOf(String.valueOf(element.value)));
|
updateState(CHANNEL_TYPE_FANSPEED,
|
||||||
|
StringType.valueOf(String.valueOf(element.value)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
@ -509,6 +566,8 @@ public class IntesisHomeHandler extends BaseThingHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
<description>Represents a single IntesisHome WiFi adapter on the network, connected to an A/C unit.</description>
|
<description>Represents a single IntesisHome WiFi adapter on the network, connected to an A/C unit.</description>
|
||||||
<channels>
|
<channels>
|
||||||
<channel id="power" typeId="system.power"/>
|
<channel id="power" typeId="system.power"/>
|
||||||
|
<channel id="wifiSignal" typeId="system.signal-strength"/>
|
||||||
</channels>
|
</channels>
|
||||||
<config-description>
|
<config-description>
|
||||||
<parameter name="ipAddress" type="text" required="true">
|
<parameter name="ipAddress" type="text" required="true">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user