diff --git a/bundles/org.openhab.binding.august/README.md b/bundles/org.openhab.binding.august/README.md index ba9aae7622473..8eeb661f726c3 100644 --- a/bundles/org.openhab.binding.august/README.md +++ b/bundles/org.openhab.binding.august/README.md @@ -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 diff --git a/bundles/org.openhab.binding.august/src/main/java/org/openhab/binding/august/internal/handler/AugustLockHandler.java b/bundles/org.openhab.binding.august/src/main/java/org/openhab/binding/august/internal/handler/AugustLockHandler.java index 9bf6abeb502ad..24f3bc23b5555 100644 --- a/bundles/org.openhab.binding.august/src/main/java/org/openhab/binding/august/internal/handler/AugustLockHandler.java +++ b/bundles/org.openhab.binding.august/src/main/java/org/openhab/binding/august/internal/handler/AugustLockHandler.java @@ -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); } @@ -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)); } @@ -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 diff --git a/bundles/org.openhab.binding.august/src/test/java/org/openhab/binding/august/internal/dto/SerializationDeserializationTest.java b/bundles/org.openhab.binding.august/src/test/java/org/openhab/binding/august/internal/dto/SerializationDeserializationTest.java index f5d34ac6e0a72..57ef83197adee 100644 --- a/bundles/org.openhab.binding.august/src/test/java/org/openhab/binding/august/internal/dto/SerializationDeserializationTest.java +++ b/bundles/org.openhab.binding.august/src/test/java/org/openhab/binding/august/internal/dto/SerializationDeserializationTest.java @@ -173,7 +173,7 @@ void testRemoteOperateLockResponse() throws IOException { } @Test - void testLockPushMessage() throws IOException { + void testLockAndDoorPushMessage() throws IOException { final Type type = new TypeToken() { }.getType(); @@ -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() { + }.getType(); + + final LockStatusDTO message = wireHelper + .deSerializeFromClasspathResource("/mock_responses/lock_status_no_doorstate_async.json", type); + + assertEquals("unlocked", message.lockStatus); + assertEquals("closed", message.doorStatus); + } } diff --git a/bundles/org.openhab.binding.august/src/test/resources/mock_responses/lock_status_no_doorstate_async.json b/bundles/org.openhab.binding.august/src/test/resources/mock_responses/lock_status_no_doorstate_async.json new file mode 100644 index 0000000000000..52f009debb2ce --- /dev/null +++ b/bundles/org.openhab.binding.august/src/test/resources/mock_responses/lock_status_no_doorstate_async.json @@ -0,0 +1,5 @@ +{ + "status": "unlocked", + "callingUserID": "manuallock", + "doorState": "closed" +} \ No newline at end of file