[yioremote] Make the Binding compatible to new firmware version of YIO Dock (#9094)
* Make the Binding compatible to new firmware version of YIO Dock Signed-off-by: Michael Loercher <MichaelLoercher@web.de>
This commit is contained in:
parent
0a9ea9fd45
commit
3fb0b86989
@ -32,6 +32,8 @@ public class YIOremoteBindingConstants {
|
|||||||
AUTHENTICATION_PROCESS,
|
AUTHENTICATION_PROCESS,
|
||||||
AUTHENTICATION_FAILED,
|
AUTHENTICATION_FAILED,
|
||||||
AUTHENTICATION_COMPLETE,
|
AUTHENTICATION_COMPLETE,
|
||||||
|
SEND_PING,
|
||||||
|
CHECK_PONG,
|
||||||
CONNECTION_FAILED,
|
CONNECTION_FAILED,
|
||||||
CONNECTION_ESTABLISHED,
|
CONNECTION_ESTABLISHED,
|
||||||
COMMUNICATION_ERROR,
|
COMMUNICATION_ERROR,
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import org.openhab.binding.yioremote.internal.dto.AuthenticationMessage;
|
|||||||
import org.openhab.binding.yioremote.internal.dto.IRCode;
|
import org.openhab.binding.yioremote.internal.dto.IRCode;
|
||||||
import org.openhab.binding.yioremote.internal.dto.IRCodeSendMessage;
|
import org.openhab.binding.yioremote.internal.dto.IRCodeSendMessage;
|
||||||
import org.openhab.binding.yioremote.internal.dto.IRReceiverMessage;
|
import org.openhab.binding.yioremote.internal.dto.IRReceiverMessage;
|
||||||
|
import org.openhab.binding.yioremote.internal.dto.PingMessage;
|
||||||
import org.openhab.binding.yioremote.internal.utils.Websocket;
|
import org.openhab.binding.yioremote.internal.utils.Websocket;
|
||||||
import org.openhab.binding.yioremote.internal.utils.WebsocketInterface;
|
import org.openhab.binding.yioremote.internal.utils.WebsocketInterface;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
@ -80,6 +81,7 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
private IRCodeSendMessage irCodeSendMessageHandler = new IRCodeSendMessage(irCodeSendHandler);
|
private IRCodeSendMessage irCodeSendMessageHandler = new IRCodeSendMessage(irCodeSendHandler);
|
||||||
private AuthenticationMessage authenticationMessageHandler = new AuthenticationMessage();
|
private AuthenticationMessage authenticationMessageHandler = new AuthenticationMessage();
|
||||||
private IRReceiverMessage irReceiverMessageHandler = new IRReceiverMessage();
|
private IRReceiverMessage irReceiverMessageHandler = new IRReceiverMessage();
|
||||||
|
private PingMessage pingMessageHandler = new PingMessage();
|
||||||
|
|
||||||
public YIOremoteDockHandler(Thing thing) {
|
public YIOremoteDockHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
@ -165,27 +167,23 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
if (message.has("type")) {
|
if (message.has("type")) {
|
||||||
if (message.get("type").toString().equalsIgnoreCase("\"auth_required\"")) {
|
if (message.get("type").toString().equalsIgnoreCase("\"auth_required\"")) {
|
||||||
heartBeat = true;
|
|
||||||
success = true;
|
success = true;
|
||||||
receivedStatus = "Authentication required";
|
receivedStatus = "Authentication required";
|
||||||
} else if (message.get("type").toString().equalsIgnoreCase("\"auth_ok\"")) {
|
} else if (message.get("type").toString().equalsIgnoreCase("\"auth_ok\"")) {
|
||||||
authenticationOk = true;
|
authenticationOk = true;
|
||||||
heartBeat = true;
|
|
||||||
success = true;
|
success = true;
|
||||||
receivedStatus = "Authentication ok";
|
receivedStatus = "Authentication ok";
|
||||||
} else if (message.get("type").toString().equalsIgnoreCase("\"dock\"") && message.has("message")) {
|
} else if (message.get("type").toString().equalsIgnoreCase("\"dock\"") && message.has("message")) {
|
||||||
if (message.get("message").toString().equalsIgnoreCase("\"ir_send\"")) {
|
if (message.get("message").toString().equalsIgnoreCase("\"pong\"")) {
|
||||||
|
heartBeat = true;
|
||||||
|
success = true;
|
||||||
|
receivedStatus = "Heart beat received";
|
||||||
|
} else if (message.get("message").toString().equalsIgnoreCase("\"ir_send\"")) {
|
||||||
if (message.get("success").toString().equalsIgnoreCase("true")) {
|
if (message.get("success").toString().equalsIgnoreCase("true")) {
|
||||||
receivedStatus = "Send IR Code successfully";
|
receivedStatus = "Send IR Code successfully";
|
||||||
heartBeat = true;
|
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
if (irCodeSendHandler.getCode().equalsIgnoreCase("0;0x0;0;0")) {
|
receivedStatus = "Send IR Code failure";
|
||||||
logger.debug("Send heartBeat Code success");
|
|
||||||
receivedStatus = "Send heartBeat Code success";
|
|
||||||
} else {
|
|
||||||
receivedStatus = "Send IR Code failure";
|
|
||||||
}
|
|
||||||
heartBeat = true;
|
heartBeat = true;
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
@ -253,6 +251,8 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
if (webSocketReconnectionPollingJob != null) {
|
if (webSocketReconnectionPollingJob != null) {
|
||||||
if (!webSocketReconnectionPollingJob.isCancelled() && webSocketReconnectionPollingJob != null) {
|
if (!webSocketReconnectionPollingJob.isCancelled() && webSocketReconnectionPollingJob != null) {
|
||||||
webSocketReconnectionPollingJob.cancel(true);
|
webSocketReconnectionPollingJob.cancel(true);
|
||||||
|
authenticationOk = false;
|
||||||
|
heartBeat = false;
|
||||||
}
|
}
|
||||||
webSocketReconnectionPollingJob = null;
|
webSocketReconnectionPollingJob = null;
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
if (authenticationOk) {
|
if (authenticationOk) {
|
||||||
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_COMPLETE;
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_COMPLETE;
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
webSocketPollingJob = scheduler.scheduleWithFixedDelay(this::pollingWebsocketJob, 0, 150,
|
webSocketPollingJob = scheduler.scheduleWithFixedDelay(this::pollingWebsocketJob, 0, 60,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_FAILED;
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_FAILED;
|
||||||
@ -337,11 +337,20 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
private void pollingWebsocketJob() {
|
private void pollingWebsocketJob() {
|
||||||
switch (yioRemoteDockActualStatus) {
|
switch (yioRemoteDockActualStatus) {
|
||||||
case AUTHENTICATION_COMPLETE:
|
case AUTHENTICATION_COMPLETE:
|
||||||
if (getAndResetHeartbeat()) {
|
resetHeartbeat();
|
||||||
updateChannelString(GROUP_OUTPUT, STATUS_STRING_CHANNEL,
|
sendMessage(YioRemoteMessages.HEARTBEAT_MESSAGE, "");
|
||||||
irCodeReceivedHandler.getCode() + irCodeReceivedHandler.getFormat());
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.CHECK_PONG;
|
||||||
|
break;
|
||||||
|
case SEND_PING:
|
||||||
|
resetHeartbeat();
|
||||||
|
sendMessage(YioRemoteMessages.HEARTBEAT_MESSAGE, "");
|
||||||
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.CHECK_PONG;
|
||||||
|
break;
|
||||||
|
case CHECK_PONG:
|
||||||
|
if (getHeartbeat()) {
|
||||||
|
updateChannelString(GROUP_OUTPUT, STATUS_STRING_CHANNEL, receivedStatus);
|
||||||
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.SEND_PING;
|
||||||
logger.debug("heartBeat ok");
|
logger.debug("heartBeat ok");
|
||||||
sendMessage(YioRemoteMessages.HEARTBEAT_MESSAGE, "");
|
|
||||||
} else {
|
} else {
|
||||||
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.COMMUNICATION_ERROR;
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.COMMUNICATION_ERROR;
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
|
||||||
@ -360,10 +369,13 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAndResetHeartbeat() {
|
public boolean resetHeartbeat() {
|
||||||
boolean result = heartBeat;
|
|
||||||
heartBeat = false;
|
heartBeat = false;
|
||||||
return result;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getHeartbeat() {
|
||||||
|
return heartBeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reconnectWebsocket() {
|
public void reconnectWebsocket() {
|
||||||
@ -423,9 +435,8 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
authenticationMessageHandler.getAuthenticationMessageString());
|
authenticationMessageHandler.getAuthenticationMessageString());
|
||||||
break;
|
break;
|
||||||
case HEARTBEAT_MESSAGE:
|
case HEARTBEAT_MESSAGE:
|
||||||
irCodeSendHandler.setCode("0;0x0;0;0");
|
yioremoteDockwebSocketClient.sendMessage(pingMessageHandler.getPingMessageString());
|
||||||
yioremoteDockwebSocketClient.sendMessage(irCodeSendMessageHandler.getIRcodeSendMessageString());
|
logger.debug("sending ping {}", pingMessageHandler.getPingMessageString());
|
||||||
logger.debug("sending heartBeat message: {}", irCodeSendMessageHandler.getIRcodeSendMessageString());
|
|
||||||
break;
|
break;
|
||||||
case IR_RECEIVER_ON:
|
case IR_RECEIVER_ON:
|
||||||
irReceiverMessageHandler.setOn();
|
irReceiverMessageHandler.setOn();
|
||||||
|
|||||||
@ -47,9 +47,6 @@ public class AuthenticationMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthenticationMessageString() {
|
public String getAuthenticationMessageString() {
|
||||||
JsonObject authenticationMessage = new JsonObject();
|
return getAuthenticationMessageJsonObject().toString();
|
||||||
authenticationMessage.addProperty("type", type);
|
|
||||||
authenticationMessage.addProperty("token", token);
|
|
||||||
return authenticationMessage.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,11 +51,6 @@ public class IRCodeSendMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getIRcodeSendMessageString() {
|
public String getIRcodeSendMessageString() {
|
||||||
JsonObject irCodeSendMessage = new JsonObject();
|
return getIRcodeSendMessageJsonObject().toString();
|
||||||
irCodeSendMessage.addProperty("type", type);
|
|
||||||
irCodeSendMessage.addProperty("command", command);
|
|
||||||
irCodeSendMessage.addProperty("code", ircode.getCode());
|
|
||||||
irCodeSendMessage.addProperty("format", ircode.getFormat());
|
|
||||||
return irCodeSendMessage.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,9 +43,6 @@ public class IRReceiverMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getIRreceiverMessageString() {
|
public String getIRreceiverMessageString() {
|
||||||
JsonObject irReceiverMessage = new JsonObject();
|
return getIRreceiverMessageJsonObject().toString();
|
||||||
irReceiverMessage.addProperty("type", type);
|
|
||||||
irReceiverMessage.addProperty("command", command);
|
|
||||||
return irReceiverMessage.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2010-2020 Contributors to the openHAB project
|
||||||
|
*
|
||||||
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
* information.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available under the
|
||||||
|
* terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-2.0
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: EPL-2.0
|
||||||
|
*/
|
||||||
|
package org.openhab.binding.yioremote.internal.dto;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link PingMessage} the AuthenticationMessage DTO
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Michael Loercher - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class PingMessage {
|
||||||
|
private String type = "dock";
|
||||||
|
private String command = "ping";
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getcommand() {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken(String command) {
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject getPingMessageJsonObject() {
|
||||||
|
JsonObject pingMessage = new JsonObject();
|
||||||
|
pingMessage.addProperty("type", type);
|
||||||
|
pingMessage.addProperty("command", command);
|
||||||
|
return pingMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPingMessageString() {
|
||||||
|
return getPingMessageJsonObject().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user