Skip to content
Snippets Groups Projects
Verified Commit 32fda0f4 authored by Erick Hitter's avatar Erick Hitter
Browse files

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

parent 27d265fc
No related branches found
No related tags found
No related merge requests found
...@@ -53,24 +53,24 @@ Lock.prototype.connect = function() { ...@@ -53,24 +53,24 @@ Lock.prototype.connect = function() {
// initialize the secure session // initialize the secure session
this._secureSession = new SecureLockSession( this._secureSession = new SecureLockSession(
this._peripheral, this._peripheral,
characteristicByUuid("bd4ac6130b4511e38ffd0800200c9a66"), characteristicByUuid("bd4ac6130b4511e38ffd0800200c9a66"),
characteristicByUuid("bd4ac6140b4511e38ffd0800200c9a66"), characteristicByUuid("bd4ac6140b4511e38ffd0800200c9a66"),
this._offlineKeyOffset this._offlineKeyOffset
); );
this._secureSession.setKey(this._offlineKey); this._secureSession.setKey(this._offlineKey);
// intialize the session // intialize the session
this._session = new LockSession( this._session = new LockSession(
this._peripheral, this._peripheral,
characteristicByUuid("bd4ac6110b4511e38ffd0800200c9a66"), characteristicByUuid("bd4ac6110b4511e38ffd0800200c9a66"),
characteristicByUuid("bd4ac6120b4511e38ffd0800200c9a66") characteristicByUuid("bd4ac6120b4511e38ffd0800200c9a66")
); );
// start the sessions // start the sessions
return Promise.join( return Promise.join(
this._secureSession.start(), this._secureSession.start(),
this._session.start() this._session.start()
); );
}.bind(this)).then(function() { }.bind(this)).then(function() {
// send SEC_LOCK_TO_MOBILE_KEY_EXCHANGE // send SEC_LOCK_TO_MOBILE_KEY_EXCHANGE
...@@ -127,9 +127,9 @@ Lock.prototype.lock = function() { ...@@ -127,9 +127,9 @@ Lock.prototype.lock = function() {
Lock.prototype.unlock = function() { Lock.prototype.unlock = function() {
return this.status(true).then(function(status) { return this.status(true).then(function(status) {
if (status == 'locked') if (status == 'locked')
return this.forceUnlock(); return this.forceUnlock();
}.bind(this)); }.bind(this));
}; };
Lock.prototype.status = function() { Lock.prototype.status = function() {
...@@ -178,4 +178,18 @@ Lock.prototype.disconnect = 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; module.exports = Lock;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment