[nikohomecontrol] Nhc fixes (#12859)
* Make trigger type items act on off * Fix gson serializing empty values * Fix some null pointer warnings Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
This commit is contained in:
parent
97b423b273
commit
be06730c32
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.nikohomecontrol.internal.protocol.nhc1;
|
package org.openhab.binding.nikohomecontrol.internal.protocol.nhc1;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class {@link NhcMessageBase1} used as base class for output from gson for cmd or event feedback from Niko Home
|
* Class {@link NhcMessageBase1} used as base class for output from gson for cmd or event feedback from Niko Home
|
||||||
@ -26,11 +27,12 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
abstract class NhcMessageBase1 {
|
abstract class NhcMessageBase1 {
|
||||||
|
|
||||||
private String cmd = "";
|
private @Nullable String cmd;
|
||||||
private String event = "";
|
private @Nullable String event;
|
||||||
|
|
||||||
String getCmd() {
|
String getCmd() {
|
||||||
return cmd;
|
String cmd = this.cmd;
|
||||||
|
return ((cmd != null) ? cmd : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCmd(String cmd) {
|
void setCmd(String cmd) {
|
||||||
@ -38,7 +40,8 @@ abstract class NhcMessageBase1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getEvent() {
|
String getEvent() {
|
||||||
return event;
|
String event = this.event;
|
||||||
|
return ((event != null) ? event : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEvent(String event) {
|
void setEvent(String event) {
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.nikohomecontrol.internal.protocol.nhc1;
|
package org.openhab.binding.nikohomecontrol.internal.protocol.nhc1;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class {@link NhcMessageCmd1} used as input to gson to send commands to Niko Home Control. Extends
|
* Class {@link NhcMessageCmd1} used as input to gson to send commands to Niko Home Control. Extends
|
||||||
@ -26,13 +27,13 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
class NhcMessageCmd1 extends NhcMessageBase1 {
|
class NhcMessageCmd1 extends NhcMessageBase1 {
|
||||||
|
|
||||||
private int id;
|
private @Nullable Integer id;
|
||||||
private int value1;
|
private @Nullable Integer value1;
|
||||||
private int value2;
|
private @Nullable Integer value2;
|
||||||
private int value3;
|
private @Nullable Integer value3;
|
||||||
private int mode;
|
private @Nullable Integer mode;
|
||||||
private int overrule;
|
private @Nullable Integer overrule;
|
||||||
private String overruletime = "";
|
private @Nullable String overruletime;
|
||||||
|
|
||||||
NhcMessageCmd1(String cmd) {
|
NhcMessageCmd1(String cmd) {
|
||||||
super.setCmd(cmd);
|
super.setCmd(cmd);
|
||||||
|
|||||||
@ -169,8 +169,11 @@ public class NikoHomeControlCommunication1 extends NikoHomeControlCommunication
|
|||||||
nhcEventsRunning = true;
|
nhcEventsRunning = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (!listenerStopped & (nhcIn != null) & ((nhcMessage = nhcIn.readLine()) != null)) {
|
BufferedReader in = nhcIn;
|
||||||
readMessage(nhcMessage);
|
if (in != null) {
|
||||||
|
while (!listenerStopped && ((nhcMessage = in.readLine()) != null)) {
|
||||||
|
readMessage(nhcMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (!listenerStopped) {
|
if (!listenerStopped) {
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import org.openhab.binding.nikohomecontrol.internal.protocol.NhcEnergyMeter;
|
|||||||
import org.openhab.binding.nikohomecontrol.internal.protocol.NhcThermostat;
|
import org.openhab.binding.nikohomecontrol.internal.protocol.NhcThermostat;
|
||||||
import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlCommunication;
|
import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlCommunication;
|
||||||
import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.ActionType;
|
import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.ActionType;
|
||||||
|
import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcDevice2.NhcParameter;
|
||||||
import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcDevice2.NhcProperty;
|
import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcDevice2.NhcProperty;
|
||||||
import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcMessage2.NhcMessageParam;
|
import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcMessage2.NhcMessageParam;
|
||||||
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
|
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
|
||||||
@ -357,9 +358,9 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
|
|
||||||
private void addDevice(NhcDevice2 device) {
|
private void addDevice(NhcDevice2 device) {
|
||||||
String location = null;
|
String location = null;
|
||||||
if (device.parameters != null) {
|
List<NhcParameter> parameters = device.parameters;
|
||||||
location = device.parameters.stream().map(p -> p.locationName).filter(Objects::nonNull).findFirst()
|
if (parameters != null) {
|
||||||
.orElse(null);
|
location = parameters.stream().map(p -> p.locationName).filter(Objects::nonNull).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("action".equals(device.type) || "virtual".equals(device.type)) {
|
if ("action".equals(device.type) || "virtual".equals(device.type)) {
|
||||||
@ -620,10 +621,6 @@ public class NikoHomeControlCommunication2 extends NikoHomeControlCommunication
|
|||||||
switch (action.getType()) {
|
switch (action.getType()) {
|
||||||
case GENERIC:
|
case GENERIC:
|
||||||
case TRIGGER:
|
case TRIGGER:
|
||||||
if (!NHCON.equals(value)) {
|
|
||||||
// Only trigger for ON
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
property.basicState = NHCTRIGGERED;
|
property.basicState = NHCTRIGGERED;
|
||||||
break;
|
break;
|
||||||
case RELAY:
|
case RELAY:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user