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

numericPrecision option added to pws-current files #10

Merged
merged 2 commits into from
Mar 28, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pws-current.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
name: { value:""},
stationid: { value:""},
units: { value:"e"},
precision: { value:"i"},
apikey: {value:"", type:"pwsapikey",required: true}
},
label: function() {
Expand All @@ -76,6 +77,13 @@
<option value="h">Hybrid units (UK)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-precision"><i class="fa fa-thermometer-half"></i> Numeric Precision</label>
<select id="node-input-precision">
<option value="i">Integer</option>
<option value="d">Decimal</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
Expand All @@ -96,6 +104,8 @@ <h3>Inputs:</h3>
<dd>If specified, override edit panel. Station ID as registered by wunderground.com</dd>
<dt class="optional">msg.twcparams.units <span class="property-type">string</span></dt>
<dd>If specified, override edit panel. 'e' - English units, 'm' - Metric units, 'h' - Hybrid units</dd>
<dt class="optional">msg.twcparams.precision <span class="property-type">string</span></dt>
<dd>If specified, override edit panel. 'i' - Integer values, 'd' - Decimal values</dd>
</dl>
<h3>Outputs:</h3>
<dl class="message-properties">
Expand Down
18 changes: 17 additions & 1 deletion pws-current.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function(RED) {
var node = this;
var StationId = n.stationid;
var units = n.units;
var precision = n.precision;
var name = n.name;
var pwsConfigNode;
var apiKey;
Expand All @@ -27,6 +28,9 @@ module.exports = function(RED) {
if (!units) {
units = 'm';
}
if (!precision) {
precision = 'i';
}

node.on('input', function (msg) {
msg.twcparams = msg.twcparams || {};
Expand All @@ -40,6 +44,18 @@ module.exports = function(RED) {
msg.twcparams.units = units; // take the default or the node setting
}

if( typeof msg.twcparams.precision == 'undefined' ) {
msg.twcparams.precision = precision;
} else {
msg.twcparams.precision = precision;
}

if ( msg.twcparams.precision == 'd') {
var numericPrecision = '&numericPrecision=decimal';
} else {
var numericPrecision = '';
}

var curStationId = StationId;
if( typeof msg.twcparams.StationID != 'undefined' ) {
curStationId = msg.twcparams.StationID.toUpperCase();
Expand All @@ -52,7 +68,7 @@ module.exports = function(RED) {
msg.twcparams.StationID = curStationId;
(async () => {
try {
const response = await axios.get('https://api.weather.com/v2/pws/observations/current?stationId=' + curStationId +'&format=json&units='+msg.twcparams.units+'&apiKey='+apiKey);
const response = await axios.get('https://api.weather.com/v2/pws/observations/current?stationId=' + curStationId +'&format=json&units='+msg.twcparams.units+'&apiKey='+apiKey+numericPrecision);
//console.log(response.data)
msg.payload = response.data;
node.send(msg);
Expand Down