Introduce method to check if lock is in some state of connection

parent 27d265fc
......@@ -53,24 +53,24 @@ Lock.prototype.connect = function() {
// initialize the secure session
this._secureSession = new SecureLockSession(
this._peripheral,
characteristicByUuid("bd4ac6130b4511e38ffd0800200c9a66"),
characteristicByUuid("bd4ac6140b4511e38ffd0800200c9a66"),
this._offlineKeyOffset
this._peripheral,
characteristicByUuid("bd4ac6130b4511e38ffd0800200c9a66"),
characteristicByUuid("bd4ac6140b4511e38ffd0800200c9a66"),
this._offlineKeyOffset
);
this._secureSession.setKey(this._offlineKey);
// intialize the session
this._session = new LockSession(
this._peripheral,
characteristicByUuid("bd4ac6110b4511e38ffd0800200c9a66"),
characteristicByUuid("bd4ac6120b4511e38ffd0800200c9a66")
this._peripheral,
characteristicByUuid("bd4ac6110b4511e38ffd0800200c9a66"),
characteristicByUuid("bd4ac6120b4511e38ffd0800200c9a66")
);
// start the sessions
return Promise.join(
this._secureSession.start(),
this._session.start()
this._secureSession.start(),
this._session.start()
);
}.bind(this)).then(function() {
// send SEC_LOCK_TO_MOBILE_KEY_EXCHANGE
......@@ -127,9 +127,9 @@ Lock.prototype.lock = function() {
Lock.prototype.unlock = function() {
return this.status(true).then(function(status) {
if (status == 'locked')
if (status == 'locked')
return this.forceUnlock();
}.bind(this));
}.bind(this));
};
Lock.prototype.status = function() {
......@@ -178,4 +178,18 @@ Lock.prototype.disconnect = function() {
}
};
Lock.prototype.isConnected = function() {
debug( 'checking connection...' );
if (
this._session instanceof LockSession &&
'undefined' !== typeof this._session._peripheral.state &&
'disconnected' !== this._session._peripheral.state
) {
return true;
}
return false;
};
module.exports = Lock;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment