Skip to content

Commit

Permalink
Add keypad battery level + keypad properties if keypad is installed &…
Browse files Browse the repository at this point in the history
… linked to a lock
  • Loading branch information
seime committed Dec 2, 2023
1 parent 7421373 commit 8fdb7bb
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ in [lock details response](src/test/resources/get_lock_response.json) and report
| battery | R | Number:Dimensionless | Remaining battery percentage |
| changedByUser | R | String | User last locking/unlocking the door. `Manual` if door knob used |
| unlockedByUser | R | String | User last unlocking the door. `Manual` if door knob used |
| batteryKeypad | R | String | Remaining battery level of keypad (if installed) |

## Requesting latest status from lock

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>4.0.1</version>
<version>4.0.4</version>
</parent>

<artifactId>no.seime.openhab.binding.august</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ public class BindingConstants {
public static final String CHANNEL_LOCK_STATE = "lockState";
public static final String CHANNEL_DOOR_STATE = "doorState";
public static final String CHANNEL_BATTERY = "battery";
public static final String CHANNEL_BATTERY_KEYPAD = "batteryKeypad";
public static final String CHANNEL_UNLOCKED_BY_USER = "unlockedByUser";
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ public class GetLockResponse {

@SerializedName("pins")
public UserListDTO userList;

public KeypadDTO keypad;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2023 Contributors to the Seime Openhab Addons 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 no.seime.openhab.binding.august.internal.dto;

import com.google.gson.annotations.SerializedName;

/**
* All classes in the .dto are data transfer classes used by the GSON mapper. This class reflects a
* part of a request/response data structure.
*
* @author Arne Seime - Initial contribution.
*/

public class KeypadDTO {

@SerializedName("_id")
public String id;

@SerializedName("LockID")
public String lockId;

@SerializedName("batteryLevel")
public String batteryLevel;

public String serialNumber;

@SerializedName("currentFirmwareVersion")
public String firmwareVersion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ private void updateThingProperties(GetLockResponse lockResponse) {
properties.put("lockSerialNumber", lockResponse.serialNumber);
properties.put("lockType", getLockName("" + lockResponse.type));

if (lockResponse.keypad != null) {
properties.put("keypadFirmwareVersion", lockResponse.keypad.firmwareVersion);
properties.put("keypadSerialNumber", lockResponse.keypad.serialNumber);
properties.put("keypadId", lockResponse.keypad.id);
}

updateThing(editThing().withProperties(properties).build());
}

Expand Down Expand Up @@ -222,6 +228,9 @@ private void handleCommandInternal(final ChannelUID channelUID, final Command co
case BindingConstants.CHANNEL_BATTERY:
handleBatteryCommand(channelUID, command);
break;
case BindingConstants.CHANNEL_BATTERY_KEYPAD:
handleBatteryKeypadCommand(channelUID, command);
break;
case BindingConstants.CHANNEL_LOCK_STATE:
handleLockStateCommand(channelUID, command);
break;
Expand Down Expand Up @@ -278,6 +287,18 @@ private void handleBatteryCommand(ChannelUID channelUID, Command command) {
}
}

private void handleBatteryKeypadCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType || command == null) {
if (lock.keypad != null) {
updateState(channelUID, new StringType(lock.keypad.batteryLevel));
} else {
updateState(channelUID, UnDefType.UNDEF);
}
} else {
logger.debug(ERROR_MESSAGE_UNSUPPORTED_COMMAND, command, channelUID);
}
}

private RemoteOperateLockRequest.Operation getOperationFromCommand(Command command) {
if (command instanceof RefreshType) {
return RemoteOperateLockRequest.Operation.STATUS;
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/OH-INF/thing/channels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@
<category>Motion</category>
<state readOnly="true"/>
</channel-type>
<channel-type id="batteryLevelKeypad">
<item-type>String</item-type>
<label>Battery level keypad (if installed)</label>
<category>BatteryLevel</category>
<state readOnly="true"/>
</channel-type>
</thing:thing-descriptions>
1 change: 1 addition & 0 deletions src/main/resources/OH-INF/thing/lock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<channel id="doorState" typeId="doorState"/>
<channel id="lockState" typeId="lockState"/>
<channel id="battery" typeId="battery"/>
<channel id="batteryKeypad" typeId="batteryLevelKeypad"/>
<channel id="unlockedByUser" typeId="unlockedByUser"/>
</channels>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ void testInitialize() throws IOException, InterruptedException {

verify(thingHandlerCallback).stateUpdated(new ChannelUID(thing.getUID(), BindingConstants.CHANNEL_BATTERY),
new QuantityType<>(47.75072124321014, Units.PERCENT));
verify(thingHandlerCallback).stateUpdated(
new ChannelUID(thing.getUID(), BindingConstants.CHANNEL_BATTERY_KEYPAD), new StringType("Full"));
verify(thingHandlerCallback).stateUpdated(new ChannelUID(thing.getUID(), BindingConstants.CHANNEL_LOCK_STATE),
OnOffType.ON);
verify(thingHandlerCallback).stateUpdated(new ChannelUID(thing.getUID(), BindingConstants.CHANNEL_DOOR_STATE),
Expand Down Expand Up @@ -320,6 +322,8 @@ private ThingImpl createLockThing() {
ChannelBuilder.create(new ChannelUID(lockThing.getUID(), BindingConstants.CHANNEL_DOOR_STATE)).build());
lockThing.addChannel(
ChannelBuilder.create(new ChannelUID(lockThing.getUID(), BindingConstants.CHANNEL_BATTERY)).build());
lockThing.addChannel(ChannelBuilder
.create(new ChannelUID(lockThing.getUID(), BindingConstants.CHANNEL_BATTERY_KEYPAD)).build());
lockThing.addChannel(ChannelBuilder
.create(new ChannelUID(lockThing.getUID(), BindingConstants.CHANNEL_UNLOCKED_BY_USER)).build());
lockThing.setConfiguration(configuration);
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/mock_responses/get_lock_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,14 @@
"enabling": [],
"deleting": [],
"updating": []
},
"keypad": {
"_id": "KEYPAD_ID",
"serialNumber": "K2IC007",
"lockID": "LockId",
"currentFirmwareVersion": "2.27.0",
"battery": null,
"batteryLevel": "Full",
"batteryRaw": 189
}
}

0 comments on commit 8fdb7bb

Please sign in to comment.