MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    My module stops MMM-Pages working

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    13 Posts 2 Posters 489 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sdetweil @Scott-M
      last edited by sdetweil

      @Scott-M not quite…

      i avoid this state setting (this.loaded) by always waiting til ALL_MODULES_STARTED
      before asking my helper to work, then I KNOW its good on socketNotificationReceived to use updateDom

      notificationReceived: function(notification, payload, sender) {
      		// once everybody is loaded up
      		if(notification==="ALL_MODULES_STARTED"){
      			// send our config to our node_helper
      			this.sendSocketNotification("CONFIG",this.config)
      		}
      

      note: you CAN still get getDom() called BEFORE your socketNotification has been called by your node_helper sending data
      so you need to check for data and return an empty DIV… (getDom MUST return SOMETHING)

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        Scott-M @sdetweil
        last edited by

        @sdetweil
        I think I understand, am I getting closer with something like this:

        Module.register("MMM-TravelLine", {
          start() {
            this.timesReturned = [];
          },
        
          notificationReceived(notification, payload, sender) {
            if (notification === "ALL_MODULES_STARTED") {
              console.log("All modules started; fetching routes now");
              this.sendSocketNotification("FETCH_ROUTES", {
                username: this.config.username,
                password: this.config.password,
                apiBase: this.config.apiBase,
                stopIDs: this.config.stopIDs,
                timestamp: new Date().toISOString()
              });
        
              // Schedule refresh
              setInterval(() => {
                this.sendSocketNotification("FETCH_ROUTES", {
                  username: this.config.username,
                  password: this.config.password,
                  apiBase: this.config.apiBase,
                  stopIDs: this.config.stopIDs,
                  timestamp: new Date().toISOString()
                });
              }, this.config.updateFrequency * 60 * 1000);
            }
          },
        
          socketNotificationReceived(notification, payload) {
            if (notification === "UPDATED_ROUTES") {
              this.timesReturned = payload;
              this.updateDom();
            }
          },
        
          getDom() {
            const container = document.createElement("div");
            container.className = "travelline-container";
        
            if (!Array.isArray(this.timesReturned) || this.timesReturned.length === 0) {
              container.innerHTML = "<div class='no-data'>Loading bus times…</div>";
              return container;
            }
        
            // ...builds table etc.......
        
            return container;
          }
        });
        
        

        Again, I have lost my remote conection to the PI so I can’t try it until tomorrow!

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @Scott-M
          last edited by sdetweil

          @Scott-M said in My module stops MMM-Pages working:

          yes, looks good…

          container.className = “travelline-container”;

          you don’t have to set a class on the wrapper/container,
          as MagicMirror has set your module name as a class on the module entry

          open the developers window, and examine the html layout for a module in the elements tab
          see the second link in my signature below

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            Scott-M @sdetweil
            last edited by

            @sdetweil Great, will hopefully get my mirror on the wall next week!#

            S 1 Reply Last reply Reply Quote 1
            • S Offline
              sdetweil @Scott-M
              last edited by

              @Scott-M awesome!

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • 1
              • 2
              • 2 / 2
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy