• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

mergeConfig() function

Scheduled Pinned Locked Moved Development
11 Posts 2 Posters 1.5k 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.
  • ? Offline
    A Former User
    last edited by Aug 1, 2020, 1:05 PM

    configMerge

    Hi, this kind of script can help developer to merge userconfig and default module config.
    I use it in my ALL modules !
    I make it public in a way to help you ;)

    Using:

    In main module core, you can put it in start() function

    this.config = configMerge({}, this.defaults, this.config)
    

    your default config will be merge with defined user config !
    If the defined user config don’t define all config value (minimal config for exemple), this script will merge it to do an entire config
    So you can send your config to node_helper.js without fear of having undefined values

    Arg Number Function
    Arg 1 Initial objet
    Arg 2 Config model
    Arg 3 Config to merge

    Load the script in MagicMirror

    You have to load the script on the main core of your module

    getScripts: function () {
      return [
        "configMerge.js"
      ]
    },
    

    Why using it ?

    Object.assign() function don’t to all job

    it don’t merge all thing in depth

    -> object in object and array is not merging

    Note:

    You can also use the Minified code version mergeConfig.min.js

    How download it:

    In your terminal use the wget command

    wget https://raw.githubusercontent.com/bugsounet/configMerge/master/configMerge.js
    

    or for Minified version

    wget https://raw.githubusercontent.com/bugsounet/configMerge/master/configMerge.min.js
    
    S 1 Reply Last reply Aug 1, 2020, 1:22 PM Reply Quote 0
    • S Away
      sdetweil @Guest
      last edited by Aug 1, 2020, 1:22 PM

      @Bugsounet I don’t understand

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • ? Offline
        A Former User
        last edited by A Former User Aug 1, 2020, 1:45 PM Aug 1, 2020, 1:26 PM

        I will code a sample wait ;)

        LoOOooL, now this script is not needed :)
        now MM v2.12.0 have solve this issue :)
        but still in v2.11.x

        I understand why you say i don't understand

        I see this at now, pfff i don’t read ChangeLog lol

        S 1 Reply Last reply Aug 1, 2020, 2:30 PM Reply Quote 0
        • S Away
          sdetweil @Guest
          last edited by sdetweil Aug 1, 2020, 2:30 PM Aug 1, 2020, 2:30 PM

          @Bugsounet also, _loadash lib is previously loaded, and loadash.merge does the deep merge, while Object.Assign does not.

          and it only matters for modules with big deep config structures. like GA

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • ? Offline
            A Former User
            last edited by Aug 1, 2020, 2:35 PM

            it’s new because in v2.11.x, I have to use mergeConfig()

            S 1 Reply Last reply Aug 1, 2020, 2:36 PM Reply Quote 0
            • S Away
              sdetweil @Guest
              last edited by Aug 1, 2020, 2:36 PM

              @Bugsounet lodash.merge loaded before 2.12.

              just saying it’s easy, if u need to do this, without another script

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • ? Offline
                A Former User
                last edited by Aug 10, 2020, 3:35 PM

                So I do some another test and not worked without configMerge()

                Module name : MMM-Freebox (in dev for new version)
                in MMM-Freebox.js:

                  defaults: {
                    updateDelay:  5 * 1000,
                    token: "",
                    activeOnly: false,
                    showIcon: true,
                    showButton: true,
                    showBandWidth: true,
                    showRate: true,
                    showClient: true,
                    showClientRate: true,
                    showClientCnxType: true,
                    showFreePlayer: true,
                    showMissedCall: true,
                    showVPNUsers: true,
                    maxMissed: 3,
                    showIP: true,
                    showPing: true,
                    pingAdress: "google.fr",
                    textWidth: 250,
                    excludeMac: [],
                    sortBy: null,
                    debug: false,
                    verbose: false,
                    dev: false,
                    debitText: "Débit total utilisé : ",
                    player : {
                      showPlayerInfo: false,
                      // depuis le firmware 4.2.3, problemes d'affichage des logos
                      // essayez avec les ips :  "192.168.0.254" (l'ip du freebox server)
                      //                         "mafreebox.free.fr" ou le resultat de l'ip de mafreebox.free.fr
                      //                         "212.27.38.253" l'ip de mafreebox.free.fr (a voir si cela fonctionne pour vous)
                      ServerIP: "212.27.38.253",
                      UseEPGDayURL: true,
                      EPGDelay: 2* 60 *60 *1000
                    }
                  },
                

                I try to merge config with MMM-Freebox.js :

                  start: function () {
                    this.config = Object.assign({}, this.defaults, this.config)
                

                I send config to node_helper.js with:

                  notificationReceived: function (notification, payload) {
                    switch(notification) {
                      case "DOM_OBJECTS_CREATED":
                        this.sendSocketNotification("INIT", this.config)
                        break
                    }
                  },
                

                module configuration in config.js:

                {
                  module: "MMM-Freebox",
                  disabled: false,
                  header: "INFO Freebox",
                  position: "top_center",
                  config: {
                    token: "xxxx",
                    updateDelay:  5 * 1000,
                    activeOnly: false,
                    sortBy: "type",
                    showButton: true,
                    debug: true,
                    //dev: true,
                    //verbose: true,
                    showVPNUsers: true,
                    textWidth: 250,
                    player: {
                      showPlayerInfo: true
                    }
                  }
                },
                

                result in node_helper.js:

                [2020-08-10 16:53:52.705] [LOG]    {
                  updateDelay: 5000,
                  token: 'xxxx',
                  activeOnly: false,
                  showIcon: true,
                  showButton: true,
                  showBandWidth: true,
                  showRate: true,
                  showClient: true,
                  showClientRate: true,
                  showClientCnxType: true,
                  showFreePlayer: true,
                  showMissedCall: true,
                  showVPNUsers: true,
                  maxMissed: 3,
                  showIP: true,
                  showPing: true,
                  pingAdress: 'google.fr',
                  textWidth: 250,
                  excludeMac: [],
                  sortBy: 'type',
                  debug: true,
                  verbose: false,
                  dev: false,
                  debitText: 'Débit total utilisé : ',
                  player: { showPlayerInfo: true }
                }
                

                so config is not merged !

                now … Let’s try with configMerge() with SAME configuration
                just modify :

                  start: function () {
                    this.config = configMerge({}, this.defaults, this.config)
                

                result in node_helper.js:

                [2020-08-10 17:08:14.984] [LOG]    {
                  updateDelay: 5000,
                  token: 'xxxx',
                  activeOnly: false,
                  showIcon: true,
                  showButton: true,
                  showBandWidth: true,
                  showRate: true,
                  showClient: true,
                  showClientRate: true,
                  showClientCnxType: true,
                  showFreePlayer: true,
                  showMissedCall: true,
                  showVPNUsers: true,
                  maxMissed: 3,
                  showIP: true,
                  showPing: true,
                  pingAdress: 'google.fr',
                  textWidth: 250,
                  excludeMac: [],
                  sortBy: 'type',
                  debug: true,
                  verbose: false,
                  dev: false,
                  debitText: 'Débit total utilisé : ',
                  player: {
                    showPlayerInfo: true,
                    ServerIP: '212.27.38.253',
                    UseEPGDayURL: true,
                    EPGDelay: 7200000
                  }
                }
                

                You can’t see that player: {} value is now set and merged with default value

                @MichMich :

                in MM core js/module.js

                	/* setConfig(config)
                	 * Set the module config and combine it with the module defaults.
                	 *
                	 * argument config object - Module config.
                	 */
                	setConfig: function (config) {
                		this.config = Object.assign({}, this.defaults, config);
                	},
                

                Can I send you a patch with configMerge() script for solve this developer issue (It take head !) ?

                S 1 Reply Last reply Aug 10, 2020, 3:52 PM Reply Quote 0
                • S Away
                  sdetweil @Guest
                  last edited by Aug 10, 2020, 3:52 PM

                  @Bugsounet open a PR, describe the problem, and your solution

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • ? Offline
                    A Former User
                    last edited by Aug 12, 2020, 4:38 PM

                    sure, i just open it

                    1 Reply Last reply Reply Quote 1
                    • ? Offline
                      A Former User
                      last edited by Sep 13, 2020, 5:26 PM

                      Ok, so, after one month

                      1. No news on this topic (I have mentionned @MichMich but …)
                      2. I have open an issue, no news
                      3. i have make a PR, euh no news too ??

                      So i decide I close Issue and PR
                      it’s not a problem for me… i use my own tools :)

                      In this forum,
                      There are not many developers left …
                      So avoid listening to them, you would have even less :)
                      I don’t know what you are looking for :)

                      For the moment, you have one motivated!
                      This is not likely to continue for long …

                      @bugsounet for @MichMich

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 1 / 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