Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
salbahra committed Jul 23, 2024
1 parent c8152e6 commit 07f1f21
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 176 deletions.
57 changes: 30 additions & 27 deletions www/js/analog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

var analogSensors = {},
progAdjusts = {};
const CHARTS = 11;
const USERDEF_SENSOR = 49;
const USERDEF_UNIT = 99;
var CHARTS = 11;
var USERDEF_SENSOR = 49;
var USERDEF_UNIT = 99;

function checkAnalogSensorAvail() {
return controller.options && controller.options.feature === "ASB";
Expand Down Expand Up @@ -70,7 +70,7 @@ function updateSensorShowArea( page ) {
var sensor = analogSensors[ i ];
if ( sensor.show ) {
html += "<div id='sensor-show-" + sensor.nr + "' class='ui-body ui-body-a center'>";
html += "<label>" + sensor.name + ": " ( +( Math.round( sensor.data + "e+2" ) + "e-2" ) ) + sensor.unit + "</label>";
html += "<label>" + sensor.name + ": " + ( Number( Math.round( sensor.data + "e+2" ) + "e-2" ) ) + sensor.unit + "</label>";
html += "</div>";
}
}
Expand Down Expand Up @@ -333,8 +333,8 @@ function showSensorEditor( sensor, callback ) {
"</label>" +
"<input class='id' type='number' min='0' max='65535' value='" + sensor.id + "'>" +

((sensor.type === USERDEF_SENSOR) ?
("<label>" +
( ( sensor.type === USERDEF_SENSOR ) ?
( "<label>" +
_( "Factor" ) +
"</label>" +
"<input class='fac' type='number' min='-32768' max='32767' value='" + sensor.fac + "'>" +
Expand All @@ -348,7 +348,7 @@ function showSensorEditor( sensor, callback ) {
_( "Unit" ) +
"</label>" +
"<input class='unit' type='text' value='" + sensor.unit + "'>"
):"") +
) : "" ) +

"<label>" +
_( "Read Interval (s)" ) +
Expand Down Expand Up @@ -521,11 +521,11 @@ var showAnalogSensorConfig = ( function() {
"&port=" + sensorOut.port +
"&id=" + sensorOut.id +
"&ri=" + sensorOut.ri +
((sensorOut.type === USERDEF_SENSOR) ?
("&fac="+sensorOut.fac +
"&div="+sensorOut.div +
"&unit="+sensorOut.unit
):"") +
( ( sensorOut.type === USERDEF_SENSOR ) ?
( "&fac=" + sensorOut.fac +
"&div=" + sensorOut.div +
"&unit=" + sensorOut.unit
) : "" ) +
"&enable=" + sensorOut.enable +
"&log=" + sensorOut.log +
"&show=" + sensorOut.show
Expand Down Expand Up @@ -555,11 +555,11 @@ var showAnalogSensorConfig = ( function() {
"&port=" + sensorOut.port +
"&id=" + sensorOut.id +
"&ri=" + sensorOut.ri +
((sensorOut.type === USERDEF_SENSOR) ?
("&fac="+sensorOut.fac +
"&div="+sensorOut.div +
"&unit="+sensorOut.unit
):"") +
( ( sensorOut.type === USERDEF_SENSOR ) ?
( "&fac=" + sensorOut.fac +
"&div=" + sensorOut.div +
"&unit=" + sensorOut.unit
) : "" ) +
"&enable=" + sensorOut.enable +
"&log=" + sensorOut.log +
"&show=" + sensorOut.show
Expand Down Expand Up @@ -789,17 +789,20 @@ var showAnalogSensorCharts = ( function() {

var max = CHARTS;
for ( var j = 0; j < analogSensors.length; j++ ) {
if (!analogSensors[j].log)
if ( !analogSensors[ j ].log ) {
continue;
var unitid = analogSensors[j].unitid;
if (unitid === USERDEF_UNIT) max++;
}
var unitid = analogSensors[ j ].unitid;
if ( unitid === USERDEF_UNIT ) {
max++;
}
}

var last = "", week = "", month = "";
for ( var j = 1; j <= max; j++ ) {
last += "<div id='myChart"+j+"'></div>";
week += "<div id='myChartW"+j+"'></div>";
month += "<div id='myChartM"+j+"'></div>";
for ( j = 1; j <= max; j++ ) {
last += "<div id='myChart" + j + "'></div>";
week += "<div id='myChartW" + j + "'></div>";
month += "<div id='myChartM" + j + "'></div>";
}

var page = $( "<div data-role='page' id='analogsensorchart'>" +
Expand Down Expand Up @@ -869,10 +872,10 @@ function buildGraph( prefix, chart, csv, titleAdd, timestr ) {
var series = { name: analogSensors[ j ].name, data: logdata };

// User defined sensor:
if (unitid === USERDEF_UNIT) {
if ( unitid === USERDEF_UNIT ) {
unitid = chart.length;
chart.push(undefined);
} else if (unitid >= CHARTS) {
chart.push( undefined );
} else if ( unitid >= CHARTS ) {
unitid = 0;
}

Expand Down
4 changes: 3 additions & 1 deletion www/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@

// Insert jQuery
insertScript( assetLocation + "js/jquery.js", function() {

// Insert libraries
insertScript( assetLocation + "js/libs.js", function() {

// Insert primary application script
insertScript( assetLocation + "js/main.js", function() {
try {
Expand All @@ -153,7 +155,7 @@

// Insert charting library for analog support
insertScript( assetLocation + "js/apexcharts.min.js" );
} )
} );
} );

// Insert home page icon for iOS
Expand Down
92 changes: 46 additions & 46 deletions www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3691,19 +3691,19 @@ function showOptions( expandItem ) {
"</div>" ),
generateSensorOptions = function( index, sensorType, number ) {
return "<div class='ui-field-contain'>" +
"<fieldset data-role='controlgroup' class='ui-mini center sensor-options' data-type='horizontal'>" +
"<legend class='left'>" + _( "Sensor" ) + ( number ? " " + number + " " : " " ) + _( "Type" ) + "</legend>" +
"<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-none' value='0'" + ( sensorType === 0 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-none'>" + _( "None" ) + "</label>" +
"<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-rain' value='1'" + ( sensorType === 1 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-rain'>" + _( "Rain" ) + "</label>" +
"<fieldset data-role='controlgroup' class='ui-mini center sensor-options' data-type='horizontal'>" +
"<legend class='left'>" + _( "Sensor" ) + ( number ? " " + number + " " : " " ) + _( "Type" ) + "</legend>" +
"<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-none' value='0'" + ( sensorType === 0 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-none'>" + _( "None" ) + "</label>" +
"<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-rain' value='1'" + ( sensorType === 1 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-rain'>" + _( "Rain" ) + "</label>" +
( index === 52 ? "" : "<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-flow' value='2'" + ( sensorType === 2 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-flow'>" + _( "Flow" ) + "</label>" ) +
( checkOSVersion( 219 ) ? "<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-soil' value='3'" + ( sensorType === 3 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-soil'>" + _( "Soil" ) + "</label>" : "" ) +
( checkOSVersion( 217 ) ? "<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-program' value='240'" + ( sensorType === 240 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-program'>" + _( "Program Switch" ) + "</label>" : "" ) +
"</fieldset>" +
"<label for='o" + index + "-flow'>" + _( "Flow" ) + "</label>" ) +
( checkOSVersion( 219 ) ? "<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-soil' value='3'" + ( sensorType === 3 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-soil'>" + _( "Soil" ) + "</label>" : "" ) +
( checkOSVersion( 217 ) ? "<input class='noselect' type='radio' name='o" + index + "' id='o" + index + "-program' value='240'" + ( sensorType === 240 ? " checked='checked'" : "" ) + ">" +
"<label for='o" + index + "-program'>" + _( "Program Switch" ) + "</label>" : "" ) +
"</fieldset>" +
"</div>";
},
submitOptions = function() {
Expand Down Expand Up @@ -4501,28 +4501,28 @@ function showOptions( expandItem ) {
"</div>" +
"<div class='ui-content'>" +
"<label id='loc-warning'>" + _( "" ) + "</label>" +
"<input class='loc-entry' type='text' id='loc-entry' data-mini='true' maxlength='64' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'"
+ " placeholder='" + _( "Enter GPS Coordinates" ) + "' value='" + ( controller.settings.loc.trim() === "''" ? _( "Not specified" ) : controller.settings.loc ) + "' required />" +
"<input class='loc-entry' type='text' id='loc-entry' data-mini='true' maxlength='64' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'" +
" placeholder='" + _( "Enter GPS Coordinates" ) + "' value='" + ( controller.settings.loc.trim() === "''" ? _( "Not specified" ) : controller.settings.loc ) + "' required />" +
"<button class='locSubmit' data-theme='b'>" + _( "Submit" ) + "</button>" +
"</div>" +
"</div>" );

popup.find( ".locSubmit" ).on( "click", function() {
var input = popup.find( "#loc-entry").val();
const gpsre = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
if(gpsre.test(input)) {
var input = popup.find( "#loc-entry" ).val();
var gpsre = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
if ( gpsre.test( input ) ) {
page.find( "#loc" ).val( input ).removeClass( "green" ).find( "span" ).text( input );
page.find( "#o1" ).selectmenu( "disable" );
header.eq( 2 ).prop( "disabled", false );
page.find( ".submit" ).addClass( "hasChanges" );
popup.popup( "close" );
} else{
$("#loc-warning").text("Invalid GPS coordinates, try again");
} else {
$( "#loc-warning" ).text( "Invalid GPS coordinates, try again" );
}
} );

openPopup( popup, { positionTo: "window" } );
});
} );

page.find( ".clear-loc" ).on( "click", function( e ) {
e.stopImmediatePropagation();
Expand Down Expand Up @@ -4980,14 +4980,14 @@ function showOptions( expandItem ) {
openPopup( popup );
} );

function generateDefaultSubscribeTopic(){
let topic;
function generateDefaultSubscribeTopic() {
var topic;
if ( controller.settings.mac ) {
topic = controller.settings.mac;
topic = topic.replaceAll(":", "");
topic = topic.replaceAll( ":", "" );
topic = "OS-" + topic;
} else {
topic = "OS-mySprinkler"
topic = "OS-mySprinkler";
}

return topic;
Expand Down Expand Up @@ -5036,25 +5036,25 @@ function showOptions( expandItem ) {
"<label for='username' style='padding-top:10px'>" + _( "Username" ) + "</label>" +
"</div>" +
"<div class='ui-block-b' style='width:60%'>" +
"<input class='mqtt-input' type='text' id='username' data-mini='true' maxlength='" + (largeSOPTSupport ? "50" : "32") + "' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'" +
"<input class='mqtt-input' type='text' id='username' data-mini='true' maxlength='" + ( largeSOPTSupport ? "50" : "32" ) + "' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'" +
( options.en ? "" : "disabled='disabled'" ) + " placeholder='" + _( "username (optional)" ) + "' value='" + options.user + "' required />" +
"</div>" +
"<div class='ui-block-a' style='width:40%'>" +
"<label for='password' style='padding-top:10px'>" + _( "Password" ) + "</label>" +
"</div>" +
"<div class='ui-block-b' style='width:60%'>" +
"<input class='mqtt-input' type='password' id='password' data-mini='true' maxlength='" + (largeSOPTSupport ? "100" : "32") + "' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'" +
"<input class='mqtt-input' type='password' id='password' data-mini='true' maxlength='" + ( largeSOPTSupport ? "100" : "32" ) + "' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'" +
( options.en ? "" : "disabled='disabled'" ) + " placeholder='" + _( "password (optional)" ) + "' value='" + options.pass + "' required />" +
"</div>" +
(largeSOPTSupport ?
( largeSOPTSupport ?
"<div class='ui-block-a' style='width:40%'>" +
"<label for='pubt' style='padding-top:10px'>" + _( "Publish Topic" ) + "</label>" +
"</div>" +
"<div class='ui-block-b' style='width:60%'>" +
"<input class='mqtt-input' type='text' id='pubt' data-mini='true' maxlength='24' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'" +
( options.en ? "" : "disabled='disabled'" ) + " placeholder='" + _( "publish topic" ) + "' value='" + options.pubt + "' required />" +
"</div>" : "" ) +
(largeSOPTSupport ?
( largeSOPTSupport ?
"<div class='ui-block-a' style='width:40%'>" +
"<label for='subt' style='padding-top:10px'>" + _( "Subscribe Topic" ) + "</label>" +
"</div>" +
Expand All @@ -5072,11 +5072,11 @@ function showOptions( expandItem ) {
"</div>" );

popup.find( "#defaultsubt" ).on( "click", function() {
popup.find( "#subt" ).val(generateDefaultSubscribeTopic());
popup.find( "#subt" ).val( generateDefaultSubscribeTopic() );
} );

popup.find( "#clearsubt" ).on( "click", function() {
popup.find( "#subt" ).val("");
popup.find( "#subt" ).val( "" );
} );

popup.find( "#enable" ).on( "change", function() {
Expand Down Expand Up @@ -5113,7 +5113,7 @@ function showOptions( expandItem ) {
openPopup( popup, { positionTo: "window" } );
} );

page.find( '#email' ).on( "click", function() {
page.find( "#email" ).on( "click", function() {
var button = this, curr = button.value,
options = $.extend( {}, {
en: 0,
Expand Down Expand Up @@ -5599,7 +5599,7 @@ var showHome = ( function() {

opts.append( sel ).enhanceWithin();
} else if ( value === 4 || value === 5 ) {
data = ( type === value ) ? data.split( "," ) : (value === 4? [ "server", "80", "On", "Off" ] : [ "server", "443", "On", "Off" ]);
data = ( type === value ) ? data.split( "," ) : ( value === 4 ? [ "server", "80", "On", "Off" ] : [ "server", "443", "On", "Off" ] );

opts.append(
"<div class='ui-bar-a ui-bar'>" + _( "Server Name" ) + ":</div>" +
Expand Down Expand Up @@ -5642,10 +5642,10 @@ var showHome = ( function() {

if ( hs === 1 ) {
button.data( "specialData", select.find( "#rf-code" ).val() );
} else if ( hs === 2 || hs === 6) {
} else if ( hs === 2 || hs === 6 ) {
var ip, port, otc, station, hex = "";
station = ( select.find( "#remote-station" ).val() || 1 ) - 1;
if ( hs === 2) {
if ( hs === 2 ) {
ip = select.find( "#remote-address" ).val().split( "." );
port = parseInt( select.find( "#remote-port" ).val() ) || 80;
for ( var i = 0; i < 4; i++ ) {
Expand All @@ -5655,9 +5655,8 @@ var showHome = ( function() {
hex += pad( station.toString( 16 ) );
} else {
otc = select.find( "#remote-otc" ).val();
console.log(otc);
hex += otc;
hex += ","
hex += ",";
hex += pad( station.toString( 16 ) );
}

Expand Down Expand Up @@ -6643,15 +6642,15 @@ function showGuidedSetup() {
}

function isValidOTC( token ) {
return /^OT[a-f0-9]{30}$/i.test(token);
return /^OT[a-f0-9]{30}$/i.test( token );
}

function parseRemoteStationData( hex ) {
let fields = hex.split( "," );
let result = {};
if (fields.length === 2 && isValidOTC(fields[ 0 ])) {
var fields = hex.split( "," );
var result = {};
if ( fields.length === 2 && isValidOTC( fields[ 0 ] ) ) {
result.otc = fields[ 0 ];
result.station = parseInt( fields[1], 16 );
result.station = parseInt( fields[ 1 ], 16 );
} else {
hex = hex.split( "" );

Expand All @@ -6675,7 +6674,7 @@ function verifyRemoteStation( data, callback ) {
data = parseRemoteStationData( data );

$.ajax( {
url: (data.otc ? ( "https://cloud.openthings.io/forward/v1/" + data.otc ) : ( "http://" + data.ip + ":" + data.port ) ) + "/jo?pw=" + encodeURIComponent( currPass ),
url: ( data.otc ? ( "https://cloud.openthings.io/forward/v1/" + data.otc ) : ( "http://" + data.ip + ":" + data.port ) ) + "/jo?pw=" + encodeURIComponent( currPass ),
type: "GET",
dataType: "json"
} ).then(
Expand All @@ -6698,7 +6697,7 @@ function verifyRemoteStation( data, callback ) {

function convertRemoteToExtender( data ) {
data = parseRemoteStationData( data );
let comm;
var comm;
if ( data.otc ) {
comm = "https://cloud.openthings.io/forward/v1/" + data.otc;
} else {
Expand Down Expand Up @@ -7350,16 +7349,17 @@ var getRunonce = ( function() {
resetRunonce();
return;
} else if ( prog === "t" ) {
//test all stations
showDurationBox({

// Test all stations
showDurationBox( {
incrementalUpdate: false,
seconds: 60,
title: "Set Duration",
callback: function( result ) {
fillRunonce( Array.apply( null, Array( controller.stations.snames.length ) ).map( function() {return result;} ) );
},
maximum: 65535
});
} );
return;
}
if ( typeof rprogs[ prog ] === "undefined" ) {
Expand Down
Loading

0 comments on commit 07f1f21

Please sign in to comment.