Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    Reloading config defaults or module

    Development
    2
    10
    48
    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.
    • hango
      hango Module Developer last edited by

      Please help me with simple answer.
      There is a way to reload config defaults or module, not just the dom?

      S 1 Reply Last reply Reply Quote 0
      • S
        sdetweil @hango last edited by

        @hango what do u mean reload?

        S 1 Reply Last reply Reply Quote 0
        • S
          sdetweil @sdetweil last edited by sdetweil

          @sdetweil the mm startup takes what you have in config for a module and merges it with the defaults section in the module_name.js, with the config replacing the same named default value.

          so, if u make the config section for a module
          config:{}
          then u will get all the module defaults the next time the mirror is started.

          because of this design, there is never any reason to edit the module source code, unless you are extending he functionality or correcting a coding problem

          1 Reply Last reply Reply Quote 0
          • hango
            hango Module Developer last edited by hango

            I need to reload just one module with defaults, not all mirror.
            Yes, I want to extend the functionality.
            More explicit, in compliments I have

            anytime: [
            moment().locale("ro").format("dddd, D MMMM")
            ]
            

            and on the midnight the date has no change

            S 1 Reply Last reply Reply Quote 0
            • S
              sdetweil @hango last edited by sdetweil

              @hango because u coded the value in the array, it is calculated at the time the array is built, NOT at the time it is USED

              so, start the mirror at 2pm, and the value will be calculated as of 2pm.

              what u will want is a function that returns a value , calculated by the function.

              I don’t think the default compliments module can do that, but havent read the code much beyond fixing the embedded \n problem last year sometime.

              1 Reply Last reply Reply Quote 0
              • hango
                hango Module Developer last edited by hango

                This post is deleted!
                S 1 Reply Last reply Reply Quote 0
                • S
                  sdetweil @hango last edited by

                  @hango you will have to write code to allow a function instead of a string, then detect to function and call it to get the string to display

                  hango 1 Reply Last reply Reply Quote 0
                  • hango
                    hango Module Developer @sdetweil last edited by hango

                    This post is deleted!
                    S 1 Reply Last reply Reply Quote 0
                    • S
                      sdetweil @hango last edited by

                      @hango the code was less than i thought
                      replace this (last line of randomCompliment)

                              return   compliments[index] || '';
                      

                      with this

                      		var f = compliments[index];
                      		if ( typeof f == 'function') f= f()
                      		return f || "";
                      

                      a compliment config entry would look like this

                        module: "compliments",
                        config: { 
                            compliments : {
                                 'anytime': [ function(){return "this is a  test "+ moment().format('MM DD HH:MM:SS')}
                                                        ]
                             }
                      }
                      

                      all of the things can be functions, or any combo down to just 1 entry as a function.
                      the function must return a string

                      hango 1 Reply Last reply Reply Quote 0
                      • hango
                        hango Module Developer @sdetweil last edited by

                        @sdetweil said in Reloading config defaults or module:

                        function(){return "this is a test "+ moment().format(‘MM DD HH:MM:SS’)}

                        thank you very much, works like charm!

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy