Skip to content

Commit

Permalink
counting implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
BenAhrdt committed Sep 29, 2022
1 parent 00bcada commit 53e0375
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ To reset the counted operating hours just write one numeric state to 0.
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS** count the activation
* (BenAhrdt) activation counter implemented to count the enable flags

### 0.0.16 (2022-09-26) automatic reset timestamp improoved
* (BenAhrdt) all states with the same resetCronjob became the same timestamp

Expand Down
23 changes: 19 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class OperatingHours extends utils.Adapter {
timestring_h_m_s :{name:"timestring_h_m_s",type:"string",write:false,unit:"h:m:s",def:""}
};
this.administrative = {
enableCounting : {name:"enableCounting", write:true}
enableCounting : {name:"enableCounting", type:"boolean", write:true, def:false},
activationCounter : {name:"activationCounter", type:"number", write:false, def:0}
};

this.timeouts = {};
Expand Down Expand Up @@ -208,11 +209,11 @@ class OperatingHours extends utils.Adapter {
type: "state",
common: {
name: administrative.name,
type: "boolean",
type: administrative.type,
role: "value",
read: true,
write: administrative.write,
def: false
def: administrative.def
},
native: {},
});
Expand All @@ -224,7 +225,7 @@ class OperatingHours extends utils.Adapter {
this.configedChannels[channel][this.channelFolders.administrative][administrative.name] = state.val;
}
else{
this.configedChannels[channel][this.channelFolders.administrative][administrative.name] = false;
this.configedChannels[channel][this.channelFolders.administrative][administrative.name] = administrative.def;
}
}

Expand Down Expand Up @@ -286,6 +287,17 @@ class OperatingHours extends utils.Adapter {
this.configedChannels[channel].operatingHours.timestring_h_m = h_m;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.timestring_h_m_s.name}`,h_m_s,true);
this.configedChannels[channel].operatingHours.timestring_h_m_s = h_m_s;

// Rücksetzen des counters, wenn die millesekunden 0 sind
if(milliseconds === 0){
if(this.configedChannels[channel].administrative.enableCounting){
this.configedChannels[channel].administrative.activationCounter = 1;
}
else{
this.configedChannels[channel].administrative.activationCounter =0;
}
this.setState(`${channel}.${this.channelFolders.administrative}.${this.administrative.activationCounter.name}`,this.configedChannels[channel].administrative.activationCounter ,true);
}
}


Expand Down Expand Up @@ -365,6 +377,9 @@ class OperatingHours extends utils.Adapter {
if(state.val !== lastState){
// Abfrage, ob der neue Wert true ist
if(state.val){
// Hochzählen des aktivierungscounters
this.configedChannels[channel].administrative.activationCounter += 1;
this.setState(`${channel}.${this.channelFolders.administrative}.${this.administrative.activationCounter.name}`,this.configedChannels[channel].administrative.activationCounter,true);
this.configedChannels[channel].timestamp = state.ts;
if(!this.timeouts.countingTimeout){
this.timeouts.countingTimeout = setTimeout(this.counting.bind(this),this.config.refreshRate);
Expand Down

0 comments on commit 53e0375

Please sign in to comment.