Add onTileLoad and onTileUnload hooks to run commands of the sensor device #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was hoping to start a discussion with this pull request, this works as-is but possibly you have a better way?
What I am after is to provide before/after hooks for when a tile is rendered and when it goes away, directly correlates to window.onLoad and window.onBeforeUnload.
Backstory: I have a power meter that has an MQTT topic for instantaneous demand, it is published every three seconds. I have written a device driver for it and I have commands to start/stop the subscription to that topic. I was looking for a way to start the subscription when the tile renders, then stop it when the tile is no longer showing on a page. This way the hub is not doing unnecessary work every three seconds.
So these changes provide a select in the app settings where you can choose a command (offered by the sensor device) to run right before the tile loads, then you can choose another command to run right before it unloads.
There are two new endpoints exposed - onTileLoad and onTileUnload and two associated groovy methods by the same name that do the work.
I haven't looked at any of the other apps yet, just figured out where to splice this in on the guage for now.
Let me know any thoughts.
Thanks!
Ben
PS, I also fixed the window.onBeforeUnload while I was at it (I don't think this was working?)