Skip to content

Commit

Permalink
var
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-blackson committed Jul 30, 2023
1 parent 359fdba commit 0577561
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
1 change: 1 addition & 0 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
}

function loadSetup() {
values2table('countdownData', countdownData,_onChange);

socket.emit('getObjectView', 'system', 'state', { startkey: 'countdown.' + instance + '.setup', endkey: 'countdown.' + instance + '.setup' + '.\u9999', include_docs: true }, function (err, _setup) {

Expand Down
4 changes: 4 additions & 0 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
"platform": "Javascript/Node.js",
"mode": "daemon",
"messagebox": true,
"adminUI": {
"config": "materialize",
"tab": "materialize"
},
"enabled": true,
"compact": true,
"dependencies": [
Expand Down
43 changes: 14 additions & 29 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ async function cleanresults(CountName){
let done = await deleteCountdownResults(channel.common.name)
}
});

}
adapter.log.debug('2.2 Cleaned results')
resolve('done')
});
adapter.log.debug('2.2 Cleaned results')
resolve('done')


}
else{
Expand Down Expand Up @@ -205,7 +207,7 @@ async function getStatesOfObj(name){

adapter.getState('setup.' + name, async function (err, state) {
//prüfen ob Device schon vorhanden ist
let check = await checkifCountdownExists(name, state)
let check = await checkifCountdownExists(name, state.val)
resolve('done')
});

Expand All @@ -215,50 +217,33 @@ async function getStatesOfObj(name){

async function checkifCountdownExists(name, state){
return new Promise(function(resolve){
adapter.log.debug('1.3 check if countdown ' + name + ' exists')
adapter.log.debug('1.3 check if countdown objects' + name + ' exists')
adapter.getObject('countdowns.' + name + '.name', async function (err1, result1) {

if(result1 === null && typeof result1 === "object") {

const CountName = name
const done = await createObjects(CountName)
adapter.getState('setup.' + CountName, async function (err, state) {
if (state && state.val){
let done = await createCountdownData(name,state.val)
adapter.log.debug(' 1.6-1 Created Countdown ' + CountName);
adapter.getState('setup.' + CountName, async function (err, state1) {
if (state1 && state1.val){
let done = await createCountdownData(name,state1.val)
adapter.log.debug(' 1.6-2 Created Countdown ' + CountName);
resolve('done')

}
else{
const CountName = name
adapter.log.error('1.6-2 Date in setup is invalid for countdown ' + CountName)
adapter.log.error('1.6-3 Date in setup is invalid for countdown ' + CountName)
resolve('done')

}
});

}
else{
if (state.val && state){
adapter.log.debug(' TEMP Updated Countdown state' + state);
adapter.log.debug(' TEMP Updated Countdown state' + state.val);


let done1 = await createCountdownData(name,state.val)
adapter.log.debug(' 1.6-3 Updated Countdown ' + name);
let done1 = await createCountdownData(name,state)
adapter.log.debug(' 1.6.6 Updated Countdown ' + name);
resolve('done')


}
else{
const CountName = name
adapter.log.debug(' TEMP Updated Countdown state' + state);
adapter.log.debug(' TEMP Updated Countdown state' + state.val);

adapter.log.error('1.6-4 Date in setup is invalid for countdown ' + CountName)
resolve('done')

}
}

});
Expand All @@ -283,7 +268,7 @@ function getVariableTranslation(){


async function createCountdownData(CountName, CountDate){
adapter.log.debug('1.4 Updating countdown objects for countdown ' + CountName)
adapter.log.debug('1.4 Updating countdown objects for countdown ' + CountName + ' with value ' + JSON.stringify(CountDate))
return new Promise(async function(resolve){

var repeatCycle = ''
Expand Down

0 comments on commit 0577561

Please sign in to comment.