Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 391d0c5

Browse files
committedMar 15, 2024·
Log messages fixed
1 parent 0c392b4 commit 391d0c5

File tree

7 files changed

+37
-48
lines changed

7 files changed

+37
-48
lines changed
 

‎io-package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"common": {
33
"name": "irrigation-control",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"news": {
66
"0.0.1": {
77
"en": "initial release",
@@ -14,6 +14,10 @@
1414
"es": "Versión inicial",
1515
"pl": "Pierwsze wydanie",
1616
"zh-cn": "首次出版"
17+
},
18+
"0.0.2": {
19+
"en": "First final release",
20+
"de": "Erstes finales Release"
1721
}
1822
},
1923
"title": "Irrigation Control",

‎lib/program.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ class Programs {
3939
this.weather = Weather.getInstance();
4040
this.weather.setRainingCallback(this.stop_all_programs.bind(this));
4141
const list = await this.adapter.getChannelsAsync(device_name);
42-
this.adapter.log.debug("channel list for programs: " + JSON.stringify(list));
42+
gadapter.log.debug("Channel list for programs: " + JSON.stringify(list));
4343
for (let p of list) {
4444
gadapter.log.debug(`Getting states for channel ${p.common.name}`);
4545
const slist = await this.adapter.getStatesOfAsync(device_name, p.common.name);
4646
//gadapter.log.info(`SObj: ${JSON.stringify(slist)}`);
4747
var a = {};
4848
for (let s of slist) {
49-
this.adapter.log.debug(`Getting value for state ${s.common.name} (id: ${s._id})`);
49+
gadapter.log.debug(`Getting value for state ${s.common.name} (id: ${s._id})`);
5050
const obj = await this.adapter.getStateAsync(s._id);
5151
if (s.common.name == 'running') {
5252
await this.adapter.subscribeStatesAsync(s._id);
5353
}
54-
this.adapter.log.info(`state value ${s._id}: ` + JSON.stringify(obj));
54+
this.adapter.log.debug(`State value ${s._id}: ` + JSON.stringify(obj));
5555
a[s.common.name] = obj.val;
5656
}
5757
if (a.hasOwnProperty('zone_list') && a.hasOwnProperty('parallel') && a.hasOwnProperty('enabled') && a.hasOwnProperty('weather')) {
@@ -60,11 +60,11 @@ class Programs {
6060
this.proglist.push(prog);
6161
gadapter.log.info(`Program ${prog.name} created`);
6262
} else {
63-
gadapter.log.error(`Cannot create program ${p.common.name}, because some values are missing`);
63+
gadapter.log.warn(`Cannot create program ${p.common.name}, because some values are missing`);
6464
}
6565
}
6666
} catch(err) {
67-
throw new Error(`Cannot initialize programs: ${err}`);
67+
gadapter.log.error(`Cannot initialize programs: ${err}`);
6868
}
6969
}
7070

@@ -75,6 +75,7 @@ class Programs {
7575
}
7676
}
7777

78+
/*
7879
dumpAllProgs(str) {
7980
for (let p of this.proglist) {
8081
const az = p.allZones();
@@ -84,7 +85,7 @@ class Programs {
8485
8586
}
8687
}
87-
88+
*/
8889

8990
getProgram(id) {
9091
const c = id.split('.');
@@ -94,13 +95,12 @@ class Programs {
9495
return p;
9596
}
9697
}
97-
9898
return null;
9999
}
100100

101101
async stateChange(id, state) {
102102
const p = this.getProgram(id);
103-
this.adapter.log.info(`State change (program) ${id} (${p.name}), state: ` + JSON.stringify(state));
103+
gadapter.log.info(`State change (program) ${id} (${p.name}), state: ` + JSON.stringify(state));
104104

105105
if (!p || !state) {
106106
return;
@@ -110,7 +110,7 @@ class Programs {
110110
if (!p.isRunning()) this.startProgram(p, true);
111111
} else {
112112
if (p.isRunning()) this.stopProgram(p);
113-
}
113+
}
114114
}
115115

116116
async zoneChange(id, state) {
@@ -176,22 +176,19 @@ class Programs {
176176
// convert programs
177177
let newcl = [];
178178
// name, zone, duration, parallel, weather, enabled
179-
gadapter.log.info("=============== Creating config for programs ============");
179+
180180
for (const p of conflist) {
181181
let np;
182182
if (np = newcl.find(x => x.name == p.name)) {
183183
np.zone_list.push({ name: p.zone, duration: p.duration});
184184
} else {
185185
newcl.push({ name: p.name, zone_list: [{ name: p.zone, duration: p.duration }], parallel: p.parallel, weather: p.weather, enabled: p.enabled});
186186
}
187-
gadapter.log.debug("convert conflist: p= " + JSON.stringify(p));
188-
gadapter.log.debug("convert conflist: newcl= " + JSON.stringify(newcl));
189187
}
190188
await config2object(gadapter, newcl, device_name, statelist);
191189
}
192190

193191
static async create_program(adapter, prog) {
194-
gadapter.log.debug(`ENTRY create_program() (${this.name})`);
195192
try {
196193
const obj = await adapter.createChannelAsync(device_name, prog.name);
197194
if (obj != undefined) {
@@ -222,9 +219,7 @@ class Programs {
222219
} catch (err) {
223220
adapter.log.error(`Cannot create program ${prog.name}, err: ${err}`);
224221
}
225-
gadapter.log.debug(`EXIT create_program`);
226222
}
227-
228223
}
229224

230225

@@ -282,19 +277,18 @@ class Program {
282277
}
283278

284279
async stop() {
285-
gadapter.log.debug(`ENTRY stop() (${this.name})`);
286280
if (this.isRunning()) {
287281
if (this.isParallel()) {
288282
const az = this.allZones();
289283
for (const z of az) {
290-
gadapter.log.debug(`Program ${this.name} stopped, stopping zone ${z.name}`);
284+
gadapter.log.info(`Program ${this.name} stopped, stopping zone ${z.name}`);
291285
z.zone.stop();
292286
z.running = false;
293287
}
294288
} else {
295289
const z = this.activeZone();
296290
if (z) {
297-
gadapter.log.debug(`Program ${this.name} stopped, stopping zone ${z.name}`);
291+
gadapter.log.info(`Program ${this.name} stopped, stopping zone ${z.name}`);
298292
z.zone.stop();
299293
z.running = false;
300294
}
@@ -338,7 +332,7 @@ class Program {
338332
} else {
339333
let act_zone = zl[this.active-1];
340334
if (act_zone.name != id) {
341-
gadapter.log.info("nextZone called, but id (" + id + ") and act_zone (" + act_zone.name + ") are different, ignoring");
335+
gadapter.log.debug("nextZone called, but id (" + id + ") and act_zone (" + act_zone.name + ") are different, ignoring");
342336
return true;
343337
}
344338
if (!act_zone.running) {

‎lib/schedule.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class Schedules {
4646
const list = await this.adapter.getChannelsAsync(device_name);
4747
this.adapter.log.debug("channel list for schedules: " + JSON.stringify(list));
4848
for (let sc of list) {
49-
this.adapter.log.debug(`Getting states for channel ${sc.common.name}`);
49+
this.adapter.log.debug(`Getting states for schedule ${sc.common.name}`);
5050
const slist = await this.adapter.getStatesOfAsync(device_name, sc.common.name);
5151

5252
var a = {};
5353
for (let s of slist) {
54-
this.adapter.log.debug(`Getting value for s ${s.common.name}`);
54+
this.adapter.log.debug(`Getting value for state ${s.common.name}`);
5555
const obj = await this.adapter.getStateAsync(s._id);
5656

5757
this.adapter.log.info(`state value ${s._id}: ` + JSON.stringify(obj));
@@ -98,7 +98,6 @@ class Schedules {
9898
}
9999

100100
static async create_config(conflist) {
101-
gadapter.log.info("=============== Creating config for schedules ============");
102101
await config2object(gadapter, conflist, device_name, statelist);
103102
}
104103

‎lib/weather.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ class Weather {
4545

4646
async stateChange(id, state) {
4747

48-
gadapter.log.info(`(Weather) State change ${id}, state: ${JSON.stringify(state)}, rainsensor: ${this.rainSensor}, raining: ${this.raining}, state.val: ${state.val}, callback: ${this.rainingcallback}`);
48+
gadapter.log.debug(`(Weather) State change ${id}, state: ${JSON.stringify(state)}, rainsensor: ${this.rainSensor}, raining: ${this.raining}, state.val: ${state.val}, callback: ${this.rainingcallback}`);
4949

5050
if (!state) return;
5151

5252
if (id == this.rainSensor) {
5353

5454
if (this.raining === false && state.val === true && this.rainingcallback) {
55-
gadapter.log.info("Calling raining callback");
55+
gadapter.log.debug("Calling raining callback");
5656
// @ts-ignore
5757
this.rainingcallback();
5858
}
@@ -77,6 +77,9 @@ class Weather {
7777
const oval = JSON.parse(obj.val);
7878
ret = oval[0];
7979
}
80+
// limit value between 0% and 200%
81+
if (ret < 0) ret = 0;
82+
if (ret > 2) ret = 2;
8083
gadapter.log.debug(`rain state: ${JSON.stringify(obj)}, weatherFactor: ${this.weatherFactor} ret: ${ret}`);
8184
return ret;
8285
}

‎lib/zone.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Zones {
5454
let zone = new Zone(z.common.name);
5555
this.zonelist.push(zone);
5656
for (let s of slist) {
57-
this.adapter.log.info(`Getting value for state ${s.common.name}`);
57+
this.adapter.log.debug(`Getting value for state ${s.common.name}`);
5858
const obj = await this.adapter.getStateAsync(s._id);
5959
if (s.common.name == 'state') {
6060
await this.adapter.subscribeStatesAsync(s._id);
@@ -67,7 +67,8 @@ class Zones {
6767
}
6868
}
6969
} catch(err) {
70-
throw new Error(`Cannot initialize zones: ${err}`);
70+
this.adapter.log.error(`Cannot initialize zones: ${err}`);
71+
return;
7172
}
7273
}
7374

@@ -124,7 +125,6 @@ class Zones {
124125
}
125126

126127
static async create_config(conflist) {
127-
gadapter.log.info("=============== Creating config for zones ============");
128128
await config2object(gadapter, conflist, device_name, statelist);
129129
}
130130

@@ -196,10 +196,6 @@ class Zone {
196196
}
197197
await gadapter.setForeignStateAsync(this.state_device, false);
198198
}
199-
200-
zlog(str) {
201-
gadapter.log.debug(`########### ZLOG DEBUG (${this.name}): + ${str}`);
202-
}
203199
}
204200

205201
module.exports = { Zones, Zone };

‎main.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class IrrigationControl extends utils.Adapter {
7575
// Reset the connection indicator during startup
7676
this.setState('info.connection', false, true);
7777

78-
this.log.info('Config data: ' + JSON.stringify(this.config));
78+
this.log.debug('Config data: ' + JSON.stringify(this.config));
7979

8080
this.zones = Zones.getInstance(this);
8181
this.progs = Programs.getInstance(this);
@@ -91,20 +91,13 @@ class IrrigationControl extends utils.Adapter {
9191
await this.schedules.initialize();
9292
await this.weather.initialize();
9393

94-
//this.log.info(`Get Zone list: ${JSON.stringify(this.zones.getzonelist())}`);
95-
96-
97-
// The adapters config (in the instance object everything under the attribute "native") is accessible via
98-
// this.config:
99-
100-
101-
// Zones.create_zone(this, new Zone('Rasen hinten links', 'statedev', 'ontimedev', 60, true));
102-
// Zones.create_zone(this, new Zone('Rasen hinten rechts', 'statedev', 'ontimedev', 60, true));
94+
//Zones.create_zone(this, new Zone('Rasen hinten links', 'statedev', 'ontimedev', 60, true));
95+
//Zones.create_zone(this, new Zone('Rasen hinten rechts', 'statedev', 'ontimedev', 60, true));
10396
//Programs.create_program(this, new Program('Rasenflächen', [{ 'name': 'Rasen hinten links', 'duration' : 0 }, { 'name': 'Rasen hinten rechts', 'duration': 100} ], false, true));
10497
//Programs.create_program(this, new Program('Beete', [{ 'name': 'Rasen hinten links', 'duration' : 5 }, { 'name': 'Rasen hinten rechts', 'duration': 8} ], false, true));
10598
//Schedules.create_schedule(this, new Schedule('Test 1', '* * * * 0,10,20,30,40,50', 'Rasenflächen'));
10699
this.setState('info.connection', true, true);
107-
this.log.info('IrrigatioControl adapter started');
100+
this.log.info('IrrigationControl adapter started');
108101
}
109102

110103
/**
@@ -128,10 +121,10 @@ class IrrigationControl extends utils.Adapter {
128121
onStateChange(id, state) {
129122
if (state) {
130123
// The state was changed
131-
this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
124+
this.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
132125
} else {
133126
// The state was deleted
134-
this.log.info(`state ${id} deleted`);
127+
this.log.debug(`state ${id} deleted`);
135128
}
136129
if (!this.zones || !this.progs) return;
137130
if (id.startsWith(this.namespace)) {
@@ -153,10 +146,10 @@ class IrrigationControl extends utils.Adapter {
153146

154147
onObjectChange(id, obj) {
155148
if (obj) {
156-
this.log.info(`object ${id} changed: (${JSON.stringify(obj)})`);
149+
this.log.debug(`object ${id} changed: (${JSON.stringify(obj)})`);
157150
// Objekt geändert
158151
} else {
159-
this.log.info(`object ${id} deleted`);
152+
this.log.debug(`object ${id} deleted`);
160153
// Objekt gelöscht
161154
}
162155
}

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iobroker.irrigation-control",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "This adapter is able to define and control irrigation schedules.",
55
"author": {
66
"name": "Stefan Köhler",

0 commit comments

Comments
 (0)
Please sign in to comment.