Skip to content

Commit

Permalink
Corrected setup of dbsize for virtual assistants (nightscout#6270)
Browse files Browse the repository at this point in the history
* Corrected db size config for virtual assistants

* Language fix, improvements, added dbsize to virtAsst config

* Using env

* Added logging

* Debug logging

* Different logging

* More troubleshooting

* Another try

* Reverted stuff, added dbsize to server defaults

* Fixed test

* Fixed another test
  • Loading branch information
inventor96 authored and tanja3981 committed Nov 15, 2020
1 parent ef9e379 commit 87b6fff
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
10 changes: 10 additions & 0 deletions docs/plugins/alexa-templates/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@
"name": {
"value": "cgm mode"
}
},
{
"name": {
"value": "db size",
"synonyms": [
"database size",
"data size",
"file size"
]
}
}
]
}
Expand Down
Binary file modified docs/plugins/google-home-templates/en-us.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -15133,7 +15133,7 @@ function init() {
,nl: 'Datagrootte'
},
'virtAsstDatabaseSize': {
en: '%1 MiB that is %2% of available database space'
en: '%1 MiB. That is %2% of available database space.'
,pl: '%1 MiB co stanowi %2% przestrzeni dostępnej dla bazy danych'
,nl: '%1 MiB dat is %2% van de beschikbaare database ruimte'
},
Expand Down
11 changes: 3 additions & 8 deletions lib/plugins/dbsize.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ function init (ctx) {

function virtAsstDatabaseSizeHandler (next, slots, sbx) {
var display = _.get(sbx, 'properties.dbsize.display');
var dataSize = _.get(sbx, 'properties.dbsize.details.dataSize');
var dataPercentage = _.get(sbx, 'properties.dbsize.dataPercentage');
if (display) {
var dataSize = _.get(sbx, 'properties.dbsize.details.dataSize');
var dataPercentage = _.get(sbx, 'properties.dbsize.dataPercentage');
var response = translate('virtAsstDatabaseSize', {
params: [
dataSize
Expand All @@ -137,13 +137,8 @@ function init (ctx) {
dbsize.virtAsst = {
intentHandlers: [
{
// for backwards compatibility
intent: 'DatabaseSize'
, intentHandler: virtAsstDatabaseSizeHandler
}
, {
intent: 'MetricNow'
, metrics: ['database size', 'file size', 'db size', 'data size']
, metrics: ['db size']
, intentHandler: virtAsstDatabaseSizeHandler
}
]
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function init (ctx) {
, require('./treatmentnotify')(ctx)
, require('./timeago')(ctx)
, require('./basalprofile')(ctx)
, require('./dbsize')(ctx)
];

plugins.registerServerDefaults = function registerServerDefaults () {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/virtAsstBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function init(env, ctx) {
};

virtAsstBase.setupVirtAsstHandlers = function (configuredPlugin) {
ctx.plugins.eachEnabledPlugin(function (plugin){
ctx.plugins.eachEnabledPlugin(function (plugin) {
if (plugin.virtAsst) {
if (plugin.virtAsst.intentHandlers) {
console.log('Plugin "' + plugin.name + '" supports Virtual Assistants');
Expand Down
11 changes: 3 additions & 8 deletions tests/dbsize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,13 @@ describe('Database Size', function() {
var dbsize = require('../lib/plugins/dbsize')(ctx);
dbsize.setProperties(sbx);

dbsize.virtAsst.intentHandlers.length.should.equal(2);
dbsize.virtAsst.intentHandlers.length.should.equal(1);

dbsize.virtAsst.intentHandlers[0].intentHandler(function next (title, response) {
title.should.equal('Database file size');
response.should.equal('450 MiB that is 90% of available database space');
response.should.equal('450 MiB. That is 90% of available database space.');

dbsize.virtAsst.intentHandlers[1].intentHandler(function next (title, response) {
title.should.equal('Database file size');
response.should.equal('450 MiB that is 90% of available database space');

done();
}, [], sbx);
done();

}, [], sbx);

Expand Down

0 comments on commit 87b6fff

Please sign in to comment.