Skip to content

Commit

Permalink
updated disconnection logic, general cleanup (openhab#381)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cunningham <[email protected]>

Signed-off-by: Dan Cunningham <[email protected]>
  • Loading branch information
digitaldan authored Oct 16, 2022
1 parent b775c7e commit 7baf6d1
Show file tree
Hide file tree
Showing 13 changed files with 11,367 additions and 432 deletions.
271 changes: 81 additions & 190 deletions app.js

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions models/accesslog.js

This file was deleted.

2 changes: 1 addition & 1 deletion models/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var NotificationSchema = new Schema({
icon: String,
severity: String,
acknowledged: Boolean,
created: { type: Date, default: Date.now }
created: { type: Date, default: Date.now, expires: '30d' }
});

NotificationSchema.index({user:1, created:1});
Expand Down
17 changes: 13 additions & 4 deletions models/openhab.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = mongoose.SchemaTypes.ObjectId,
OpenhabConfig = require('./openhabconfig')

ObjectId = mongoose.SchemaTypes.ObjectId;

var OpenhabSchema = new Schema({
name: String, // A meaningfull name of openHAB
uuid: {type: String, unique: true}, // openHAB generated UUID
Expand All @@ -16,7 +15,8 @@ var OpenhabSchema = new Schema({
last_online: { type: Date }, // last seen this openHAB online
last_email_notification: {type: Date}, // last notification about openHAB being offline for long time
status: {type: String, default: "offline"}, // current openHAB status (online/offline)
serverAddress: {type: String} // the host:port that this openhab is connected to
serverAddress: {type: String}, // the host:port that this openhab is connected to
connectionId: {type: String} // the local instance ID needed when marking openHABs offline
});

// Index for lookups by uuid
Expand All @@ -25,6 +25,8 @@ OpenhabSchema.index({uuid:1});
OpenhabSchema.index({account:1});
// Index for lookups by status
OpenhabSchema.index({status:1, last_online:1});
// Index for lookups by connectionId
OpenhabSchema.index({connectionId:1});

OpenhabSchema.methods.authenticate = function(openhabUuid, openhabSecret, callback) {
this.model('Openhab').findOne({uuid: openhabUuid, secret: openhabSecret}, function(error, openhab) {
Expand All @@ -40,4 +42,11 @@ OpenhabSchema.methods.authenticate = function(openhabUuid, openhabSecret, callba
});
}

OpenhabSchema.statics.setOffline = function(connectionId, callback) {
this.model('Openhab').findOneAndUpdate(
{ connectionId: connectionId },
{ $set: { status: 'offline', last_online: new Date()}},
callback );
}

module.exports = mongoose.model('Openhab', OpenhabSchema);
16 changes: 0 additions & 16 deletions models/openhabaccesslog.js

This file was deleted.

13 changes: 0 additions & 13 deletions models/openhabconfig.js

This file was deleted.

Loading

0 comments on commit 7baf6d1

Please sign in to comment.