Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] updated disconnection logic and clean up unused noise #381

Merged
merged 1 commit into from
Oct 16, 2022
Merged
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
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