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

Add boolean to disable auto check of isUserAtHome #473

Merged
merged 2 commits into from Mar 3, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions api/core/task/task.init.js
Expand Up @@ -67,15 +67,17 @@ module.exports = function(cb){

// checking for update on module now
gladys.module.checkUpdate();

// CheckUserPresence every XX minutes, default is 5 minutes
const DEFAULT_CHECK_USER_PRESENCE_FREQUENCY = 5;

gladys.param.getValue('USER_CHECK_PRESENCE_FREQUENCY')
.catch(() => DEFAULT_CHECK_USER_PRESENCE_FREQUENCY)
.then((checkFrequency) => {
setInterval(function() {
gladys.house.checkUsersPresence();
if(userHasCheckPresence()){
gladys.house.checkUsersPresence();
}
}, checkFrequency * 60 * 1000);
});

Expand All @@ -85,4 +87,17 @@ module.exports = function(cb){
gladys.module.checkUpdate();
}, sails.config.update.checkUpdateInterval);

};
};

function userHasCheckPresence(){
return gladys.param.getValue('CHECK_USER_PRESENCE')
.catch((err) => {
if(err.message === 'Param CHECK_USER_PRESENCE not found'){
gladys.param.setValue({name: 'CHECK_USER_PRESENCE', value: 'false', type: 'secret'});
} else {
sails.log.err(err);
}
return false;
})
.then((value) => value);
}
24 changes: 22 additions & 2 deletions assets/js/app/house/house.controller.js
Expand Up @@ -6,9 +6,9 @@
.module('gladys')
.controller('HouseCtrl', HouseCtrl);

HouseCtrl.$inject = ['houseService', 'roomService', 'notificationService'];
HouseCtrl.$inject = ['houseService', 'roomService', 'notificationService', 'paramService'];

function HouseCtrl(houseService, roomService, notificationService) {
function HouseCtrl(houseService, roomService, notificationService, paramService) {
/* jshint validthis: true */
var vm = this;

Expand All @@ -22,18 +22,21 @@
vm.newRoom = {};
vm.updateRoom = updateRoom;
vm.updateHouse = updateHouse;
vm.updateCheckUserPresence = updateCheckUserPresence;

vm.houses = [];
vm.rooms = [];

vm.savingHouse = false;
vm.savingRoom = false;
vm.checkUserPresence = false;

activate();

function activate() {
getHouses();
getRooms();
getCheckUserPresenceValue()
return ;
}

Expand Down Expand Up @@ -97,6 +100,16 @@
});
}

function updateCheckUserPresence(){
paramService.create({name: 'CHECK_USER_PRESENCE', value: !vm.checkUserPresence})
.then(function(data){
vm.checkUserPresence = !vm.checkUserPresence
})
.catch(function(){
notificationService.errorNotificationTranslated('DEFAULT.ERROR');
})
}

function deleteHouse(index, id) {
return houseService.destroy(id)
.then(function(data){
Expand Down Expand Up @@ -129,6 +142,13 @@
});
}

function getCheckUserPresenceValue(){
paramService.getValue('CHECK_USER_PRESENCE')
.then(function(data){
vm.checkUserPresence = data.data.value
})
}

function resetNewHouseFields() {
vm.newHouse = {};
}
Expand Down
5 changes: 5 additions & 0 deletions assets/js/app/param/param.service.js
Expand Up @@ -13,6 +13,7 @@
var service = {
get: get,
getByModule: getByModule,
getValue: getValue,
create: create,
update: update,
destroy: destroy,
Expand All @@ -32,6 +33,10 @@
function getByModule(id) {
return $http({method: 'GET', url: '/module/' + id + '/param'});
}

function getValue(name) {
return $http({method: 'GET', url: '/param/' + name});
}

function create(param) {
return $http({method: 'POST', url: '/param', data: param});
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.json
Expand Up @@ -188,7 +188,9 @@
"area-tooltip-longitude": "Enter the longitude e. g. 4.5487",
"area-tooltip-radius": "Enter a radius in meters e. g. 25",
"house-box-title": "Houses",
"house-box-description": "You can define here your houses in Gladys. Latitude and longitude can be found on Google Maps, and must be entered with the format (example): Latitude = 42.1, Longitude = 40.1. Remember, all this is saved on your machine and do not leave your Gladys installation.",
"house-box-description": "You can define here your houses in Gladys. Latitude and longitude can be found on Google Maps, and must be entered with the format (example): Latitude = 42.1, Longitude = 40.1. Remember, all this is saved on your machine and do not leave your Gladys installation.",
"house-box-check-presence": "Presence detection:",
"house-box-check-presence-description": "Enable/Disable the presence detection of the house. For more information go to the official documentation in the configuration tab then housing.",
"room-box-title": "Rooms",
"mode-box-title": "Modes",
"mode-box-description": "Modes are states the house can take. A house can be in one and only one mode at the same time.",
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.json
Expand Up @@ -351,6 +351,8 @@
"area-delete": "Supprimer",
"house-box-title": "Maisons",
"house-box-description": "Vous pouvez définir ici votre maison dans Gladys. Pour la latitude et la longitude, vous pouvez utiliser Google Maps pour trouver la latitude et la longitude votre maison, et la rentrer au format (par exemple) : latitude = 42.1, longitude = 43.2. Rappel: Toutes ces données restent en locale sur votre machine, et ne sont jamais envoyées nulle part.",
"house-box-check-presence": "Détection de présence:",
"house-box-check-presence-description": "Activer/Désactiver la détection de présence de la maison. Pour plus d'information rendez-vous sur la documentation officielle dans l'onglet configuration puis logement.",
"room-box-title": "Pièces",
"mode-box-title": "Modes",
"mode-box-description": "Les modes sont des états que la maison peut prendre. Une maison peut être dans un et un seul mode à la fois.",
Expand Down
15 changes: 15 additions & 0 deletions views/partials/houses.ejs
Expand Up @@ -4,6 +4,21 @@
<div class="box skin-box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><%= __('house-box-title') %> <small class="ng-cloak" ng-show="vm.savingHouse"><%= __('house-box-saving') %></small></h3>

<div class="pull-right" data-toggle="tooltip" data-original-title="<%= __('house-box-check-presence-description') %>">
<div class="raw">
<div class="col-sm-9 no-padding">
<span><%= __('house-box-check-presence') %></span>
</div>
<div class="col-sm-3" style="padding-left: inherit;">
<div class="toogle" ng-click="vm.updateCheckUserPresence()">
<input type="checkbox" ng-model="vm.checkUserPresence" ng-true-value="true" ng-false-value="false" class="toogle-checkbox toogle-blue" />
<label class="toogle-label" for="mytoogle"></label>
</div>
</div>
</div>
</div>

</div>

<div class="box-body table-responsive">
Expand Down