Skip to content

Commit

Permalink
Some cleanup. More explicit handling of error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Mar 3, 2023
1 parent 701ff3f commit 2a7af45
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,27 @@ private void cancelUnlockedByUserFuture() {
private void handleRemoteEventPushMessage(JsonElement message, JsonElement eventType) {
switch (eventType.getAsInt()) {
case 1:
RemoteOperateLockResponse remoteEvent = gson.fromJson(message,
new TypeToken<RemoteOperateLockResponse>() {
}.getType());
if (remoteEvent.info != null) {
updateThingProperties(remoteEvent.info);
}

if (remoteEvent.lockState != null && !"kAugLockState_Unlocking".equals(remoteEvent.lockState)
&& !"kAugLockState_Locking".equals(remoteEvent.lockState)) {
State lockState = parseLockState(remoteEvent.lockState);
updateState(CHANNEL_LOCK_STATE, lockState);
if (!message.getAsJsonObject().get("error").isJsonNull()) {
logger.debug("Ignoring error message from bridge");
} else {

RemoteOperateLockResponse remoteEvent = gson.fromJson(message,
new TypeToken<RemoteOperateLockResponse>() {
}.getType());
if (remoteEvent.info != null) {
updateThingProperties(remoteEvent.info);
}

if (remoteEvent.lockState != null && !"kAugLockState_Unlocking".equals(remoteEvent.lockState)
&& !"kAugLockState_Locking".equals(remoteEvent.lockState)) {
State lockState = parseLockState(remoteEvent.lockState);
updateState(CHANNEL_LOCK_STATE, lockState);

}
if (remoteEvent.doorState != null) {
updateState(CHANNEL_DOOR_STATE, parseDoorState(remoteEvent.doorState));
}
}
if (remoteEvent.doorState != null) {
updateState(CHANNEL_DOOR_STATE, parseDoorState(remoteEvent.doorState));
}

break;
// Other events may occur
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void testLockAndDoorPushMessage() throws IOException {
}.getType();

final LockStatusDTO message = wireHelper
.deSerializeFromClasspathResource("/mock_responses/lock_status_unlocked_async.json", type);
.deSerializeFromClasspathResource("/mock_responses/pubnub/lock_status_unlocked_async.json", type);

assertEquals("unlocked", message.lockStatus);
assertEquals("closed", message.doorStatus);
Expand All @@ -190,7 +190,7 @@ void testLockPushMessage() throws IOException {
}.getType();

final LockStatusDTO message = wireHelper
.deSerializeFromClasspathResource("/mock_responses/lock_status_no_doorstate_async.json", type);
.deSerializeFromClasspathResource("/mock_responses/pubnub/lock_status_no_doorstate_async.json", type);

assertEquals("unlocked", message.lockStatus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ void testUnlockDoor() throws IOException, InterruptedException {

lockHandler.handleCommand(new ChannelUID(thing.getUID(), BindingConstants.CHANNEL_LOCK_STATE), OnOffType.OFF);

lockHandler.onPushMessage("ignored",
JsonParser.parseString(getClasspathJSONContent("/mock_responses/lock_status_unlocked_async.json")));
lockHandler.onPushMessage("ignored", JsonParser
.parseString(getClasspathJSONContent("/mock_responses/pubnub/lock_status_unlocked_async.json")));
verify(thingHandlerCallback).stateUpdated(new ChannelUID(thing.getUID(), BindingConstants.CHANNEL_LOCK_STATE),
OnOffType.OFF);
}
Expand Down

0 comments on commit 2a7af45

Please sign in to comment.