Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnos3 committed Nov 9, 2019
1 parent ea74c8f commit f26afb9
Show file tree
Hide file tree
Showing 13 changed files with 6,113 additions and 5,909 deletions.
3,655 changes: 1,822 additions & 1,833 deletions nodes/blind-control.html

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions nodes/lib/suncalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ const util = require('util'); // eslint-disable-line no-unused-vars
name: 'solarNoon',
// elevation: 90,
julian: Jnoon,
valid: !isNaN(Jnoon)
valid: !isNaN(Jnoon),
index: sunTimes.length
},
nadir: {
value: nadirVal,
Expand All @@ -411,10 +412,10 @@ const util = require('util'); // eslint-disable-line no-unused-vars
name: 'nadir',
// elevation: 270,
julian: Jnoon + 0.5,
valid: !isNaN(Jnoon)
valid: !isNaN(Jnoon),
index: (sunTimes.length * 2) + 1
}
};

for (let i = 0, len = sunTimes.length; i < len; i += 1) {
const time = sunTimes[i];
const sa = time[0];
Expand Down Expand Up @@ -443,7 +444,8 @@ const util = require('util'); // eslint-disable-line no-unused-vars
name: time[2],
elevation: sa,
julian: Jset,
valid
valid,
index : len + i + 1
};
result[time[1]] = {
value: v2,
Expand All @@ -452,18 +454,19 @@ const util = require('util'); // eslint-disable-line no-unused-vars
name: time[1],
elevation: sa, // (180 + (sa * -1)),
julian: Jrise,
valid
valid,
index: len - i - 1
};
}

if (!noDeprecated) {
// for backward compatibility
for (let i = 0, len = sunTimesAlternate.length; i < len; i += 1) {
const time = sunTimesAlternate[i];
result[time[0]] = result[time[1]];
result[time[0]] = Object.assign({}, result[time[1]]);
result[time[0]].index = -2;
}
}

return result;
};

Expand Down
2 changes: 1 addition & 1 deletion nodes/locales/de/position-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dayofmonth": "Monatstag",
"dayofweek": "Wochentag",
"timesun": "Uhrzeit Sonnenstand",
"timesunnow": "Uhrzeit Sonnenstand aktuell",
"timesunnow": "nächste Uhrzeit Sonnenstand",
"suninsky":"Sonne am Himmel (Prozent)",
"timemoon": "Uhrzeit Mond Auf/Untergang",
"suncalc": "Sonnenposition",
Expand Down
7 changes: 4 additions & 3 deletions nodes/locales/en-US/position-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"json": "json",
"jsonata": "json expr.",
"timestamp":"timestamp",
"suntimeObj": "{suntime}",
"suntimeObj": "{next suntime}",
"blank": "\"\"",
"nothing": "nothing",
"checkall": "stopping after first match (if)",
Expand All @@ -22,7 +22,7 @@
"dayofmonth":"day of month",
"dayofweek":"day of week",
"timesun":"sun time",
"timesunnow": "last suntime",
"timesunnow": "next sun time",
"timemoon":"moon time",
"suncalc":"sun calculation",
"suninsky":"sun in the sky (percent)",
Expand All @@ -33,7 +33,8 @@
"moonPhaseCheck": "moon phase",
"levelfix":"Level",
"levelfree": "Level entered",
"levelND": "N/D - use default, sun control or reset"
"levelND": "N/D - use default, sun control or reset",
"PlTRes":"msg.payload if topic contains \"__value__\""
},
"typeOptions": {
"moonRise": "moon rise",
Expand Down
123 changes: 66 additions & 57 deletions nodes/position-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ module.exports = function (RED) {
*/

/**
* gets sun time
* gets sun time by Name
* @param {Date} now current time
* @param {string} value name of the sun time
* @param {number} [offset] the offset (positive or negative) which should be added to the date. If no multiplier is given, the offset must be in milliseconds.
Expand All @@ -185,19 +185,19 @@ module.exports = function (RED) {
* @param {string} [days] days for which should be calculated the sun time
* @return {timeresult|erroresult} result object of sunTime
*/
getSunTime(now, value, offset, multiplier, next, days) {
getSunTimeByName(now, value, offset, multiplier, next, days) {
let result;
const dayid = this._getDayId(now); // this._getUTCDayId(now);
const today = this._sunTimesCheck(); // refresh if needed, get dayId
// this.debug(`getSunTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
// this.debug(`getSunTimeByName value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
this.debug('getSunTime sunTimesToday');
this.debug('getSunTimes sunTimesToday');
result = Object.assign({}, this.sunTimesToday[value]); // needed for a object copy
} else if (dayid === (today.dayId + 1)) {
this.debug('getSunTime sunTimesTomorow');
this.debug('getSunTimes sunTimesTomorow');
result = Object.assign({},this.sunTimesTomorow[value]); // needed for a object copy
} else {
this.debug('getSunTime calc extra time');
this.debug('getSunTimes calc extra time');
result = Object.assign({},sunCalc.getSunTimes(now, this.latitude, this.longitude, false)[value]); // needed for a object copy
}

Expand Down Expand Up @@ -225,14 +225,57 @@ module.exports = function (RED) {
result = Object.assign(result, sunCalc.getSunTimes(date, this.latitude, this.longitude, false)[value]);
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
} else if (dayx < 0) {
// this.debug('getSunTime - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getSunTimeByName - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
result.error = 'No valid day of week found!';
}
}

// this.debug('getSunTime result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getSunTimeByName result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
return result;
}

/**
* gets previous and next sun time
* @param {Date} now current time
* @return {array} result object of sunTime
*/
getSunTimePrevNext(now) {
const dayid = this._getDayId(now); // this._getUTCDayId(now);
const today = this._sunTimesCheck(); // refresh if needed, get dayId
let result;
// this.debug(`getSunTimePrevNext value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
result = this.sunTimesToday; // needed for a object copy
} else if (dayid === (today.dayId + 1)) {
result = this.sunTimesTomorow; // needed for a object copy
} else {
result = sunCalc.getSunTimes(now, this.latitude, this.longitude, false); // needed for a object copy
}
const sortable = [];
for (const key in result) {
if (result[key].index >=0) {
sortable.push(result[key]);
}
}
sortable.sort((a, b) => {
return a.ts - b.ts;
});
const nowTs = now.getTime();
let last = sortable[0];
if (last.ts > nowTs) {
return [result['nadir'], last];
}
for (let index = 1; index < sortable.length; index++) {
const element = sortable[index];
if (last.ts < element.ts) {
if (element.ts > nowTs) {
return [last, element];
}
last = element;
}
}
return [last, sortable[0]];
}
/*******************************************************************************************************/
/**
* @typedef {Object} moontime
Expand All @@ -249,12 +292,12 @@ module.exports = function (RED) {
* @param {string} [days] days for which should be calculated the moon time
* @return {moontime|erroresult} result object of moon time
*/
getMoonTime(now, value, offset, multiplier, next, days) {
getMoonTimeByName(now, value, offset, multiplier, next, days) {
const result = {};
const datebase = new Date(now);
const dayid = this._getDayId(now); // this._getUTCDayId(now);
const today = this._moonTimesCheck(); // refresh if needed, get dayId
// this.debug(`getMoonTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${today}`);
// this.debug(`getMoonTimeByName value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${today}`);

if (dayid === today.dayId) {
result.value = this.moonTimesToday[value]; // needed for a object copy
Expand Down Expand Up @@ -293,12 +336,12 @@ module.exports = function (RED) {
result.value = new Date(sunCalc.getMoonTimes(date, this.latitude, this.longitude, false)[value]);
result.value = hlp.addOffset(new Date(result.value), offset, multiplier);
} else if (dayx < 0) {
// this.debug('getSunTime - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getMoonTimeByName - no valid day of week found value=' + value + ' - next=' + next + ' - days=' + days + ' result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
result.error = 'No valid day of week found!';
}
}

// this.debug('getMoonTime result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
// this.debug('getMoonTimeByName result=' + util.inspect(result, { colors: true, compact: 10, breakLength: Infinity }));
return result;
}
/*******************************************************************************************************/
Expand Down Expand Up @@ -414,53 +457,17 @@ module.exports = function (RED) {
} else if ((data.type === 'pdsTime') || (data.type === 'pdmTime')) {
if (data.type === 'pdsTime') { // sun
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getSunTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getSunTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
} else if (data.type === 'pdmTime') { // moon
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getMoonTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getMoonTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
}
if (result && result.value && !result.error) {
return hlp.getFormattedDateOut(result.value, data.format, (this.tzOffset === 0), this.tzOffset);
}
return null;
} else if (data.type === 'pdsTimeNow') {
const dayid = this._getDayId(now); // this._getUTCDayId(now);
const today = this._sunTimesCheck(); // refresh if needed, get dayId
// this.debug(`getSunTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
this.debug('getSunTime sunTimesToday');
result = this.sunTimesToday; // needed for a object copy
} else if (dayid === (today.dayId + 1)) {
this.debug('getSunTime sunTimesTomorow');
result = this.sunTimesTomorow; // needed for a object copy
} else {
this.debug('getSunTime calc extra time');
result = sunCalc.getSunTimes(now, this.latitude, this.longitude, false); // needed for a object copy
}
const sortable = [];
for (const key in result) {
sortable.push(result[key]);
}
sortable.sort((a, b) => {
return a.ts - b.ts;
});
const nowTs = now.getTime();
let i = 0;
let last = Object.assign({index: i}, sortable[0]);
if (last.ts > nowTs) {
return [Object.assign({index: -1}, result['nadir']), last];
}
for (let index = 1; index < sortable.length; index++) {
const element = sortable[index];
if (last.ts < element.ts) {
i++;
if (element.ts > nowTs) {
return [last, Object.assign({index: i},element)];
}
last = Object.assign({index: i},element);
}
}
return [last,Object.assign({index: -1}, sortable[0])];
return Object.assign({}, this.getSunTimePrevNext(now));
} else if (data.type === 'entered' || data.type === 'dateEntered') {
result = hlp.getDateOfText(String(data.value), (this.tzOffset === 0), this.tzOffset);
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
Expand Down Expand Up @@ -558,19 +565,21 @@ module.exports = function (RED) {
} else if (data.type === 'pdsTime') {
// sun
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getSunTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getSunTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);
}
result.fix = true;
} else if (data.type === 'pdmTime') {
// moon
const offsetX = this.getFloatProp(_srcNode, msg, data.offsetType, data.offset, 0);
result = this.getMoonTime(now, data.value, offsetX, data.multiplier, data.next, data.days);
result = this.getMoonTimeByName(now, data.value, offsetX, data.multiplier, data.next, data.days);
if (this.tzOffset) {
result.value = hlp.convertDateTimeZone(result.value, this.tzOffset);
}
result.fix = true;
} else if (data.type === 'pdsTimeNow') {
return this.getSunTimePrevNext(now)[1];
} else if (data.type === 'str') {
result.fix = true;
if (data.format) {
Expand Down Expand Up @@ -800,17 +809,17 @@ module.exports = function (RED) {

const dayid = this._getDayId(date); // this._getUTCDayId(now);
const today = this._sunTimesCheck(); // refresh if needed, get dayId
// this.debug(`getSunTime value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
// this.debug(`getSunTimes value=${value} offset=${offset} multiplier=${multiplier} next=${next} days=${days} now=${now} dayid=${dayid} today=${util.inspect(today, { colors: true, compact: 10, breakLength: Infinity })}`);
if (dayid === today.dayId) {
this.debug('getSunTime sunTimesToday');
this.debug('getSunTimes sunTimesToday');
result.times =this.sunTimesToday; // needed for a object copy
result.positionAtSolarNoon = this.sunSolarNoonToday;
} else if (dayid === (today.dayId + 1)) {
this.debug('getSunTime sunTimesTomorow');
this.debug('getSunTimes sunTimesTomorow');
result.times = this.sunTimesTomorow; // needed for a object copy
result.positionAtSolarNoon = this.sunSolarNoonTomorow;
} else {
this.debug('getSunTime calc extra time');
this.debug('getSunTimes calc extra time');
result.times = sunCalc.getSunTimes(date, this.latitude, this.longitude, false); // needed for a object copy
if (sunInSky && result.times.solarNoon.valid) {
result.positionAtSolarNoon = sunCalc.getPosition(result.times.solarNoon.value, this.latitude, this.longitude);
Expand Down
2 changes: 1 addition & 1 deletion nodes/static/htmlglobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function getTypes(node) { // eslint-disable-line no-unused-vars
},
TimeSunNow: {
value: 'pdsTimeNow',
label: node._('node-red-contrib-sun-position/position-config:common.types.timesunnow','sun time'),
label: node._('node-red-contrib-sun-position/position-config:common.types.timesunnow'),
icon: 'icons/node-red-contrib-sun-position/inputTypeSunTime.png',
hasValue: false
},
Expand Down
Loading

0 comments on commit f26afb9

Please sign in to comment.