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

stop polling when module is hidden #9

Open
E3V3A opened this issue Mar 1, 2018 · 4 comments
Open

stop polling when module is hidden #9

E3V3A opened this issue Mar 1, 2018 · 4 comments
Labels
enhancement New feature or request ToDo Things that will be done, eventually. PR welcome!

Comments

@E3V3A
Copy link
Owner

E3V3A commented Mar 1, 2018

No need to poll when the module is hidden. This functionality is controlled by two functions in the main module, according to:

  • suspend() - When a module is hidden (using the module.hide() method), the suspend() method will be called. By subclassing this method you can perform tasks like halting the update timers.

  • resume() - When a module is requested to be shown (using the module.show() method), the resume() method will be called. By subclassing this method you can perform tasks restarting the update timers.

We need to implement this functionality.

@E3V3A E3V3A added enhancement New feature or request ToDo Things that will be done, eventually. PR welcome! labels Mar 1, 2018
@ncmilhouse
Copy link

ncmilhouse commented Jan 26, 2019

Actually, please don't implement this.

I live near the flight path for RDU. Planes go overhead frequently under 2000ft. I have hacked this module in the following ways to meet my needs:

  • I filtered the radar.js file to filter out the flights that aren't too or from RDU. I don't care about the ones that are at 30,000ft.
            if (!Array.isArray(d)) continue
            if (d[11] == "RDU" || d[12] == "RDU") {
                aircraft.push({
  • In the first method called by FlightsAbove, if the returned array of flights is empty, it hides the module. If it isn't empty, then it shows it.
    setTableData: function(data) {
        if (!Array.isArray(data) || !data.length) {
            this.hide(1000);
        } else {
            this.show(1000);
        }
        $("#flightsabove").tabulator("setData", data);
    }

End effect is that if I hear a plane, Magic Mirror tells me what the flight is. Otherwise it's hidden. If the polling stopped when hidden, it would never get un-hidden by new flight data.

annotation 2019-01-26 144701

@E3V3A
Copy link
Owner Author

E3V3A commented Jan 29, 2019

@ncmilhouse
Nice hack! 👍

So just to make sure for me to understand what it does:
If there are no planes close to you (by radar results), then the module is hidden, otherwise it is shown?

Certainly seem more efficient to filter the radar results rather than the data/table results.

The only problems with this as I can see are:

  1. It make the configuration settings a little less user-friendly.
  2. It prevents power/cpu saving for voice activated modules. (If people want to hide module, they probably don't want it to run.)

But perhaps we could consider adding the radar hack somehow...

Possible work around implementation:
Use two ways to disable module:

  1. Hide module, but keep polling
  2. Hide module, and disable polling

@ncmilhouse
Copy link

Correct - if there's no planes within the radar box that are departing from or landing at RDU, then the module is hidden. I think a configuration option to "only show flights to/from home airport" wouldn't be too daunting, especially since there is already a homeIata configuration item.

As far as hiding the entire module when there are no flights in the rather tight radar box...this was very much a hack, and I certainly can see that there are potential problems, especially with regards to power saving. An alternative approach might be instead of truly hiding the module essentially replace the whole return code with "". Including the headers/footers, and never calling the tabulator at all. Essentially exit the function instead of hiding. That would preserve the intent of the show and hide capability in MM, and still let me hide the entire module when no flights are overhead.

I am not a developer, and have never even seen js before I started with MM last week, so give me a couple days and I'll see if I can come up with a way to quasi-hide the module. I can reply to this thread with my findings, but have no idea whatsoever how to do a pull request. I will leave it for your consideration only.

On another note, I also added in another hack. Not being very familair with airport codes, I found the airport-codes npm package, and now translate the airport codes to city name inside the radar.js. Unless it's my home airport. So I can see from Boston, to RDU. I know my own airport code, but not necessarily all the others. If you are interested in that, I can document that in another issue thread. Here's a slightly older pic, before I changed Raleigh-durham back to RDU.
image

    const aircraft = []
    for (let id in data) {
        const d = data[id]
        if (!Array.isArray(d)) continue
        if ((d[11] == "RDU" || d[12] == "RDU") && d[11] && d[12]) {
            if (d[11] !== "RDU") {
                var cityfrom = airports.findWhere({ iata: d[11] }).get('city')
            } else {
                var cityfrom = d[11]
            }
            if (d[12] !== "RDU") {
                var cityto = airports.findWhere({ iata: d[12] }).get('city')
            } else {
                var cityto = d[12]
            }
            aircraft.push({
                id,                         // Unique F24 id ?
                modes: d[0] || null,        // Mode-S Transponder code: 6-digit [hex] is a 24-bit ICAO issued code
                latitude: d[1],             // in decimal degrees
                longitude: d[2],            // in decimal degrees
                bearing: d[3],              // in [degrees]
                altitude: d[4],             // in [feet]
                speed: d[5],                // in [knots]
                squawk: d[6],               // Mode-3/A Transponder code: 4-digit [octal] is the "Squawk" ATC assigned code
                radar: d[7],                // F24 "radar" data source (ADS-B, MLAT, RADAR (ATC feed), FLARM, "ESTIMATED") designator
                model: d[8] || null,        // ICAO Aircraft Type Designator
                registration: d[9] || null, // ICAO Aircraft (tail) registration number
                timestamp: d[10] || null,   // Timestamp [Unix/POSIX/epoch]
                //origin: d[11] || null,      // Departure Airport IATA
                origin: cityfrom,
                //destination: d[12] || null, // Destination Airport IATA
                destination: cityto,
                flight: d[13] || null,      // IATA Flight Id
                ground: d[14],              // Airplane is "onGround": [0|1]
                climb: d[15],               // "Rate of Climb" (RoC) is a vertical speed [ft/m]
                callsign: d[16] || null,    // ICAO ATC call signature

Maybe I should figure out how to do a pull request like a big boy? :)

ncmilhouse

@E3V3A
Copy link
Owner Author

E3V3A commented Feb 2, 2019

Wow, great hack there!

I like the real name thing, but I decided not to use look into that (when I developed this), since it took up too much screen space on my portrait screen. But there are other way we could use it...

There are 2 way to do PR's.

  1. Directly from githib: fork - edit - and PR
  2. Using git for real life experience

Unfortunately these two methods are not very compatible and creates huge headaches.
Chose one, then play with the other...just like with your wife/husband.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ToDo Things that will be done, eventually. PR welcome!
Projects
None yet
Development

No branches or pull requests

2 participants