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

Final gsm eric #555

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions packages/api/lib/controllers/boxesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ module.exports = {
{ name: 'windSpeedPort', dataType: 'String', defaultValue: 'C', allowedValues: ['A', 'B', 'C'] },
{ name: 'mqtt', dataType: 'object' },
{ name: 'ttn', dataType: 'object' },
{ name: 'gsm', dataType: 'object' },
{ name: 'useAuth', allowedValues: ['true', 'false'] },
{ predef: 'location', required: true }
]),
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Norwin Roosen"
],
"dependencies": {
"@sensebox/opensensemap-api-models": "^1.1.1",
"@sensebox/opensensemap-api-models": "^1.1.2",
"@turf/area": "^6.3.0",
"@turf/bbox": "^6.3.0",
"@turf/centroid": "^6.3.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/models/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## v1.1.2
- Added homeV2GSM model to box integrations

## v1.1.1

- Update @sensebox/node-sketch-templater to v1.12.1
Expand All @@ -18,6 +21,7 @@
- `grouptag` changed from `string` to `array`
- Allow mqtts nad wss for mqtt-integration


## v0.0.32-beta.0
- Allow mqtts nad wss for mqtt-integration

Expand Down
10 changes: 10 additions & 0 deletions packages/models/src/box/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ boxSchema.statics.initNew = function ({
ttn: {
app_id, dev_id, port, profile, decodeOptions: ttnDecodeOptions
} = {},
gsm: {
imsi, secret_code
} = {},
useAuth
}) {
// if model is not empty, get sensor definitions from products
Expand All @@ -252,6 +255,9 @@ boxSchema.statics.initNew = function ({
}
}
if (model) {
if (model === 'homeV2GSM' && (!imsi || !secret_code)) {
return Promise.reject(new ModelError('homeV2GSM can not be created without imsi or secret code', { type: 'UnprocessableEntityError' }));
}
//activate useAuth only for certain models until all sketches are updated
if (['homeV2Lora', 'homeV2Ethernet', 'homeV2EthernetFeinstaub', 'homeV2Wifi', 'homeV2WifiFeinstaub', 'homeEthernet', 'homeWifi', 'homeEthernetFeinstaub', 'homeWifiFeinstaub', 'hackair_home_v2'].indexOf(model) !== -1) {
useAuth = true;
Expand All @@ -268,6 +274,10 @@ boxSchema.statics.initNew = function ({
integrations.ttn = { app_id, dev_id, port, profile, decodeOptions: ttnDecodeOptions };
}

if (imsi && secret_code) {
integrations.gsm = { imsi, secret_code };
}

const boxLocation = {
coordinates: location,
timestamp: new Date(),
Expand Down
12 changes: 12 additions & 0 deletions packages/models/src/box/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const ttnSchema = new mongoose.Schema({
decodeOptions: [{}]
}, { _id: false, usePushEach: true });

const tinggSchema = new mongoose.Schema({
imsi: { type: String, trim: true, required: true },
secret_code: { type: String, trim: true, required: true }
}, { _id: false, usePushEach: true });

const integrationSchema = new mongoose.Schema({
mqtt: {
type: mqttSchema,
Expand Down Expand Up @@ -62,6 +67,13 @@ const integrationSchema = new mongoose.Schema({
},
msg: 'this profile requires an array \'decodeOptions\''
}]
},
gsm: {
type: tinggSchema,
required: false,
validate: function validate () {
return true;
}, msg: 'Something went wrong with GSM creds'
}
}, { _id: false, usePushEach: true });

Expand Down
1 change: 1 addition & 0 deletions packages/models/src/box/sensorLayouts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const senseboxhome = require('./sensebox.home'),
*/

const modelDefinitions = {
'homeV2GSM': senseboxhome_v2,
'homeV2Lora': senseboxhome_v2,
'homeV2Ethernet': senseboxhome_v2,
'homeV2EthernetFeinstaub': senseboxhome_v2,
Expand Down
6 changes: 4 additions & 2 deletions packages/models/test/helpers/senseBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const senseBox = function senseBox ({
model = 'homeEthernet',
sensors,
mqtt,
ttn
ttn,
gsm
} = {}) {
location = loc(location);

Expand All @@ -43,7 +44,8 @@ const senseBox = function senseBox ({
model,
sensors,
mqtt,
ttn
ttn,
gsm
};
};

Expand Down
29 changes: 29 additions & 0 deletions packages/models/test/tests/1-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ describe('Box model', function () {
testBoxes[box._id] = box;
});
});
it('should allow creation of gsm integration with homeV2GSM model', function () {
const box = senseBox({
model: 'homeV2GSM',
gsm: {
imsi: '973498573498563456873',
secret_code: 'superSecretCodeForTesting'
}
});

return Box.initNew(box)
.then(shouldBeABoxWithSecrets)
.then(function (box) {
return Box.findById(box._id);
})
.then(shouldBeABox)
.then(function ({ integrations }) {
expect(integrations.gsm.imsi).equal('973498573498563456873');
expect(integrations.gsm.secret_code).equal('superSecretCodeForTesting');
});
});

it('should persist integrations and other properties upon creation', function () {
const box = senseBox({
Expand Down Expand Up @@ -200,6 +220,15 @@ describe('Box model', function () {
});
});

it('should not allow creation of homeV2GSM without gsm credentials', function () {
return Box.initNew(senseBox({ model: 'homeV2GSM' }))
.then(shouldNotHappenThenner)
.catch(function (err) {
expect(err.name).equal('ModelError');
expect(err.message).equal('homeV2GSM can not be created without imsi or secret code');
});
});

it('should not allow to specify unknown model', function () {
return Box.initNew(senseBox({ model: 'fancyNewModel' }))
.then(shouldNotHappenThenner)
Expand Down
Loading