Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class ErrorHandler {
return "Unknown error";
case KeyturnerError.BAD_PIN:
return "The provided PIN is invalid";
case KeyturnerError.MOTOR_BLOCKED:
return "The motor was blocked during operation";
case KeyturnerError.CLUTCH_FAILURE:
return "The clutch failed";

default:
return "Unknown error - code: 0x" + errCode.toString(16);
Expand Down
13 changes: 13 additions & 0 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ let configs = readConfigs();

console.log(configs);

app.get("/:name/status", (req, res) => {
if(!configs[req.params.name]){
res.status(404).send('Lock not present in config');
}
executeAction(configs[req.params.name].uuid, (smartLock) => {
return lockUnlockAction(smartLock, (smartlock) => smartlock.readLockState());
}).then(response => {
res.status(200).send(response);
}).catch(err => {
res.status(400).send(err.message);
});
});

app.get("/:name/lock", (req, res) => {
if(!configs[req.params.name]){
res.status(404).send('Lock not present in config');
Expand Down
5 changes: 4 additions & 1 deletion src/lib/smartLockCommands/KeyTurnerStatesCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export class KeyTurnerStatesCommand extends SmartLockCommand {

this._response.data.currentTime = date;

this._response.data.battery_critical = payload.readUInt8(12) != 0;
let battery = payload.readUInt8(12) // see https://developer.nuki.io/page/nuki-smart-lock-api-2/2#heading--keyturner-states
this._response.data.battery_critical = (battery & 0x01) != 0;
this._response.data.battery_charging = (battery & 0x02) != 0;
this._response.data.battery_percent = (battery >> 2) * 2;
this._response.data.configUpdateCount = payload.readUInt8(13);
this._response.data.lockNGoTimer = payload.readUInt8(14);
this._response.data.lastLockAction = payload.readUInt8(15);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export enum GeneralError {
}

export enum KeyturnerError {
BAD_PIN = 0x21
BAD_PIN = 0x21,
MOTOR_BLOCKED = 0x42,
CLUTCH_FAILURE = 0x43
}

export enum Status {
Expand Down