Skip to content

Merged "Analog Sensor API", "ProgramView", "Flow Alert" and "Monitor and Control" to current (2.0!)#206

Closed
opensprinklershop wants to merge 5 commits into
OpenSprinkler:masterfrom
opensprinklershop:Branch_8118ade0
Closed

Merged "Analog Sensor API", "ProgramView", "Flow Alert" and "Monitor and Control" to current (2.0!)#206
opensprinklershop wants to merge 5 commits into
OpenSprinkler:masterfrom
opensprinklershop:Branch_8118ade0

Conversation

@opensprinklershop
Copy link
Copy Markdown
Contributor

Analog Sensor API + Program View

@opensprinklershop opensprinklershop changed the title Branch_8118ade0 Merged "Analog Sensor API", "ProgramView", "Flow Alert" and "Monitor and Control" to current (2.0!) Apr 7, 2025
@mellodev
Copy link
Copy Markdown
Contributor

mellodev commented Apr 8, 2025

linter is failing @opensprinklershop

@mellodev
Copy link
Copy Markdown
Contributor

hello @opensprinklershop looks like there is a small linting issue that still needs to be resolved:
image

Copy link
Copy Markdown
Contributor

@mellodev mellodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this is a massive PR! Lots of comments on this one:

Comment thread www/index.html
* along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<html>
<html data-appversion="2.4.175">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to double check on this attribute data-appversion. I don't see any related code to read this value, is it required? Additionally, a few months ago there were some changes to how the app versioning works. All app version references are updated automatically by the github workflows associated with builds. I'd suggest either we either remove this attribute if it's not needed, or update the workflows to set this value automatically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can remove that. It was used to query the current version number.

Comment thread www/index.html
<!-- Load OSApp modules -->
<script src="js/modules/about.js"></script>
<script src="js/modules/analog.js"></script>
<script src="js/modules/programview.js"></script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest renaming this import and the file itself to program-view.js to match the file naming convention used by the other multi-word modules.

Comment thread www/js/modules/analog.js
Comment on lines +27 to +29
CURRENT_FW : "2.3.3(172)",
CURRENT_FW_ID : 231,
CURRENT_FW_MIN : 150,
Copy link
Copy Markdown
Contributor

@mellodev mellodev Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps renaming these variables to REQUIRED_FW, REQUIRED_FW_ID and REQUIRED_FW_MIN would be more descriptive? Later on in checkFirmwareUpdate we see these variables are being used to verify a minimum supported fw version for specific features and suggest the user update to a specific supported firmware if needed.

Comment thread www/js/modules/analog.js
}
};

OSApp.Analog.checkAnalogSensorAvail = function() {
return OSApp.currentSession.controller.options && OSApp.currentSession.controller.options.feature === "ASB";
return OSApp.currentSession.controller.options && OSApp.currentSession.controller.options.feature.includes("ASB");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called from several other places in the app. I think this needs an elvis operator added to prevent an exception when options.feature is undefined.

Suggested change
return OSApp.currentSession.controller.options && OSApp.currentSession.controller.options.feature.includes("ASB");
return OSApp.currentSession.controller.options && OSApp.currentSession.controller.options.feature?.includes("ASB");

Tested this branch locally and I'm seeing this on launch:
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as the extensions of my extended firmware have been included in the standard firmware, this can be removed

Comment thread www/js/modules/analog.js
};

OSApp.Analog.checkMonitorAlerts = function() {
if (!window.cordova || !window.cordova.plugins || !OSApp.Analog.monitors || (!OSApp.currentDevice.isAndroid && !OSApp.currentDevice.isiOS))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a really good candidate to be refactored out to it's own function. Looks like we duplicate this exact/similar logic in several functions in analog.js

Comment on lines +1 to +9
/* global $, ApexCharts */

/*!
* Analog Sensor API - GUI for OpenSprinkler App
* https://github.com/opensprinklershop/
* (c) 2023 OpenSprinklerShop
* Released under the MIT License
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the new dashboard component to display programs? Is there any documentation about this functionality that needs to be updated?

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end-user documentation is easy: Press the "Start" button to start the program ;-)

Comment on lines +22 to +23
OSApp.Firmware.sendToOS("/du?pw=", "json").then( function( status ) {
var popup = "<div data-role='popup' id='debugWU' class='ui-content ui-page-theme-a'>";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Should this be gated with a checkOSVersion call? When I run this code locally and click on the 'System Diagnostics' link in the left menu, I am getting 404s for the /du endpoint via OTC. These failures mean the Systen Diagnostics' modal never appears for me.

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, looks like checkOSVersion is missing here.

Comment on lines +61 to +77
if ( typeof OSApp.currentSession.controller.settings.otcs === "number" || (status && status.hasOwnProperty("status")) ) {
popup += "<div class='debugWUHeading'>Integrations</div>" +
"<table class='debugWUTable'>";
if (typeof OSApp.currentSession.controller.settings.otcs === "number")
popup += "<tr><td>OpenThings Cloud</td><td>" + OSApp.SystemDiagnostics.resolveOTCStatus( OSApp.currentSession.controller.settings.otcs ) + "</td></tr>";
if (status.hasOwnProperty("freeBytes"))
popup += "<tr><td>Free Bytes</td><td>" + OSApp.SystemDiagnostics.format2(status.freeBytes/1024) + " KB</td></tr>";
if (status.hasOwnProperty("pingok"))
popup += "<tr><td>Ping check ok</td><td>" + status.pingok + "</td></tr>";
if (status.hasOwnProperty("mqtt"))
popup += "<tr><td>MQTT</td><td>" + (status.mqtt?"connected":"disconnected") + "</td></tr>";
if (status.hasOwnProperty("influxdb"))
popup += "<tr><td>influxdb</td><td>" + (status.influxdb ? "enabled" : "disabled") + "</td></tr>";
if (status.hasOwnProperty("ifttt"))
popup += "<tr><td>IFTTT</td><td>" + (status.ifttt?"enabled":"disabled") + "</td></tr>";
popup +="</table>";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider passing all these string literals through the language translation OSApp.Language._()

Comment thread www/js/modules/utils.js
Comment on lines +57 to +60
OSApp.Utils.escapeJSON2 = function( json ) {
return JSON.stringify( json ).replace(/#/g, "%23").replace(/=/g, "%3D").replace( /\{|\}/g, "" );
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why are we implementing this ourselves rather than using encodeURIComponent? This escapeJSON2 and it's sibling escapeJSON both feature very limited/incomplete sets of character replacements/transformations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem was, that encodeURIComponent does too much, also escapes " and = and other elements that are needed by the json format.

Comment thread www/vendor-js/apexcharts.min.js Outdated
Comment on lines 2 to 3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity why are we upgrading from v3.35.1 to v3.50.0? This jumps about 15 minor version releases they've made. If the goal is to update to the latest in the 3.x.x major version, it looks like v3.54.1 is the latest:

apexcharts/apexcharts.js@v3.54.1...v3.54.1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes latest version is ok

@mellodev
Copy link
Copy Markdown
Contributor

mellodev commented Apr 22, 2025

I checked this PR out locally, made a branch from it and resolved almost every comment above (the ones with thumbs up reactopm). There were a couple I wasn't sure about (eyeballs reaction) so I left that untouched. See the updated branch PR here: #213

Does that mean we can close this one and use my #213 going forward?

@salbahra
Copy link
Copy Markdown
Member

Closing in favor of #213

@salbahra salbahra closed this May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants