Skip to content

Commit

Permalink
Add fix for locks not reporting door state
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Feb 16, 2023
1 parent bcbecbf commit 687416d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 31 deletions.
12 changes: 6 additions & 6 deletions bundles/org.openhab.binding.august/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ Only a few channels have been added so far, but quite a bit more data is availab
If you feel something important is missing, take a look
in [lock details response](src/test/resources/get_lock_response.json) and report back/create a PR.

| Channel | Read/write | Item type | Description |
|---------------|------------|----------------------|------------------------------------------------------------------|
| lockState | R/W | Switch | State of locking bolt, ON = locked, OFF = unlocked |
| doorState | R | Contact | Whether the door is OPEN or CLOSED |
| battery | R | Number:Dimensionless | Remaining battery percentage |
| changedByUser | R | String | User last locking/unlocking the door. `Manual` if door knob used |
| Channel | Read/write | Item type | Description |
|---------------|------------|----------------------|-------------------------------------------------------------------------------------------------------|
| lockState | R/W | Switch | State of locking bolt, ON = locked, OFF = unlocked |
| doorState | R | Contact | Whether the door is OPEN or CLOSED. Not all doors report this, in that case the channel reports UNDEF |
| battery | R | Number:Dimensionless | Remaining battery percentage |
| changedByUser | R | String | User last locking/unlocking the door. `Manual` if door knob used |

## Requesting latest status from lock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ private void handleCommandInternal(final ChannelUID channelUID, final Command co

private void handleDoorStateCommand(ChannelUID channelUID, Command command) {
if (command == null || command instanceof RefreshType) {
logger.info("{} Updating door state channel with cloud state", config.lockId);
updateState(channelUID,
"closed".equals(lock.lockStatus.doorStatus) ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
if (lock.lockStatus.doorStatus != null) {
logger.info("{} Updating door state channel with cloud state", config.lockId);
updateState(channelUID,
"closed".equals(lock.lockStatus.doorStatus) ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
} else {
updateState(channelUID, UnDefType.UNDEF);
}
} else {
logger.debug(ERROR_MESSAGE_UNSUPPORTED_COMMAND, command, channelUID);
}
Expand Down Expand Up @@ -285,33 +289,36 @@ public void onPushMessage(String channelName, JsonElement message) {
}.getType());

State lockState = UnDefType.UNDEF;
switch (asyncStatus.lockStatus) {
case "locked":
lockState = OnOffType.ON;
break;
case "unlocked":
lockState = OnOffType.OFF;
break;
default:
logger.warn("Unexpected lockState from async message {}", asyncStatus.lockStatus);
if (asyncStatus.lockStatus != null) {
switch (asyncStatus.lockStatus) {
case "locked":
lockState = OnOffType.ON;
break;
case "unlocked":
lockState = OnOffType.OFF;
break;
default:
logger.warn("Unexpected lockState from async message {}", asyncStatus.lockStatus);
}
}

updateState(CHANNEL_LOCK_STATE, lockState);

State doorState = UnDefType.UNDEF;
switch (asyncStatus.doorStatus) {
case "open":
doorState = OpenClosedType.OPEN;
break;
case "closed":
doorState = OpenClosedType.CLOSED;
break;
default:
logger.warn("Unexpected doorState from async message {}", asyncStatus.doorStatus);
}
if (asyncStatus.doorStatus != null) {
switch (asyncStatus.doorStatus) {
case "open":
doorState = OpenClosedType.OPEN;
break;
case "closed":
doorState = OpenClosedType.CLOSED;
break;
default:
logger.warn("Unexpected doorState from async message {}", asyncStatus.doorStatus);
}

}
updateState(CHANNEL_DOOR_STATE, doorState);

updateState(CHANNEL_CHANGED_BY_USER, getLastChangeBy(asyncStatus.callingUserID));

}
Expand All @@ -337,7 +344,10 @@ private State getLastChangeBy(String callingUserID) {
}

private void parseUserMap(GetLockResponse lock) {
lock.userList.loaded.forEach(e -> userIdToName.put(e.userID, String.format("%s %s", e.firstName, e.lastName)));
if (lock.userList != null) {
lock.userList.loaded
.forEach(e -> userIdToName.put(e.userID, String.format("%s %s", e.firstName, e.lastName)));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void testRemoteOperateLockResponse() throws IOException {
}

@Test
void testLockPushMessage() throws IOException {
void testLockAndDoorPushMessage() throws IOException {
final Type type = new TypeToken<LockStatusDTO>() {
}.getType();

Expand All @@ -183,4 +183,16 @@ void testLockPushMessage() throws IOException {
assertEquals("unlocked", message.lockStatus);
assertEquals("closed", message.doorStatus);
}

@Test
void testLockPushMessage() throws IOException {
final Type type = new TypeToken<LockStatusDTO>() {
}.getType();

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

assertEquals("unlocked", message.lockStatus);
assertEquals("closed", message.doorStatus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"status": "unlocked",
"callingUserID": "manuallock",
"doorState": "closed"
}

0 comments on commit 687416d

Please sign in to comment.