Announcement

Collapse
No announcement yet.

Retrieving Settings from INI file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Retrieving Settings from INI file

    Is there away to retrieve my settings when the plugin loads without creating Protected Overloads Sub LoadSettingsFromIni() ? The settings page reads in the values fine, but how do I access them in my plugin?
    -Larry

    A member of "The HA Pioneer Group", MyWebSite

    Plugins:
    VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

    Hardware:
    Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

    #2
    +1 following...
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      Use HomeseerSystem.GetIniSetting
      The section is “Settings” but you can see that if you open the ini file

      Comment


        #4
        duh, I should have figured that one out...I guess I'm a little frazzled trying to get this plugin done.
        -Larry

        A member of "The HA Pioneer Group", MyWebSite

        Plugins:
        VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

        Hardware:
        Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

        Comment


          #5
          do you guys trusts the hs3/4 built-in ini routines? i gave up on them in HS3, and implemented a third party ini class. My HS3 ini file kept getting truncated/corrupted when hs3 crashed or was shutdown in correctly
          Mark

          HS3 Pro 4.2.19.5
          Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
          Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
          Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

          Comment


            #6
            Originally posted by mnsandler View Post
            do you guys trusts the hs3/4 built-in ini routines? i gave up on them in HS3, and implemented a third party ini class. My HS3 ini file kept getting truncated/corrupted when hs3 crashed or was shutdown in correctly
            I've never had an issue with the built-in routines. I am writing a new plugin that will 'cache' the INI settings instead of reading them for every device event. I've even thought about a built-in timer to get any new settings every 'x' minutes or so.
            HS4Pro on a Raspberry Pi4
            54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
            Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

            HSTouch Clients: 1 Android

            Comment


              #7
              Originally posted by mnsandler View Post
              do you guys trusts the hs3/4 built-in ini routines? i gave up on them in HS3, and implemented a third party ini class. My HS3 ini file kept getting truncated/corrupted when hs3 crashed or was shutdown in correctly
              Never had any issue with it but I don't use it as a streaming database, just for settings and they are easily a few hundred entries.

              Comment


                #8
                Originally posted by mnsandler View Post
                do you guys trusts the hs3/4 built-in ini routines? i gave up on them in HS3, and implemented a third party ini class. My HS3 ini file kept getting truncated/corrupted when hs3 crashed or was shutdown in correctly
                I used my own and not HS3's
                -Larry

                A member of "The HA Pioneer Group", MyWebSite

                Plugins:
                VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

                Hardware:
                Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

                Comment


                  #9
                  Originally posted by dcorsus View Post
                  Use HomeseerSystem.GetIniSetting
                  The section is “Settings” but you can see that if you open the ini file
                  1.) GetIniSetting works great to retrieve settings for my subs/functions.

                  2.) But the settings page doesn't read anything in except toggles, and seems to ignore my text input.

                  3.) The settings page does save any changes I make to the correct pluginname.ini file, but on startup it only reads the toggles???

                  So I still am forced to use my routine to retrieve the data reliably.
                  -Larry

                  A member of "The HA Pioneer Group", MyWebSite

                  Plugins:
                  VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

                  Hardware:
                  Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

                  Comment


                    #10
                    Originally posted by lpitman View Post

                    1.) GetIniSetting works great to retrieve settings for my subs/functions.

                    2.) But the settings page doesn't read anything in except toggles, and seems to ignore my text input.

                    3.) The settings page does save any changes I make to the correct pluginname.ini file, but on startup it only reads the toggles???

                    So I still am forced to use my routine to retrieve the data reliably.
                    I store booleans, text and integers as part of the settings page. They do require use of different kind of:

                    withToggle
                    withInput
                    withDropDownSelect

                    .....

                    Seems to work for me but text is simple not chapters long with potential conflict in characters like "=" or crlf

                    Comment


                      #11
                      Originally posted by rmasonjr View Post
                      I am writing a new plugin that will 'cache' the INI settings instead of reading them for every device event. I've even thought about a built-in timer to get any new settings every 'x' minutes or so.
                      That's how I do it for PED, but you can also apply it to ini settings

                      Code:
                      public bool use_status_device
                      {
                          get
                          {
                              if(_use_status_device == null)
                                  _use_status_device = GetPED<bool>(Utils.FuncName());
                              return (bool)_use_status_device;
                          }
                          set
                          {
                              _use_status_device = value;
                              SavePED(Utils.FuncName(), _use_status_device);
                          }
                      }
                      
                      bool? _use_status_device;

                      Comment


                        #12
                        Originally posted by dcorsus View Post

                        I store booleans, text and integers as part of the settings page. They do require use of different kind of:

                        withToggle
                        withInput
                        withDropDownSelect

                        .....

                        Seems to work for me but text is simple not chapters long with potential conflict in characters like "=" or crlf
                        Thats the same as I'm using?

                        'Add a TEXT INPUTVIEW to the page
                        settingsPage.WithInput(Constants.Settings.FourthAnnounceId, Constants.Settings.FourthAnnounceName, HomeSeer.Jui.Types.EInputType.Text)
                        '---------------------------------------------------------------------------------------------------------
                        'Add a TEXT INPUTVIEW to the page
                        settingsPage.WithInput(Constants.Settings.FromEmailId, Constants.Settings.FromEmailName, HomeSeer.Jui.Types.EInputType.Email)
                        '---------------------------------------------------------------------------------------------------------
                        'Add a TEXT INPUTVIEW to the page
                        settingsPage.WithInput(Constants.Settings.EmailServerId, Constants.Settings.EmailServerName, HomeSeer.Jui.Types.EInputType.Text)
                        '---------------------------------------------------------------------------------------------------------
                        'Add a TEXT INPUTVIEW to the page
                        settingsPage.WithInput(Constants.Settings.EmailPasswordId, Constants.Settings.EmailPasswordName, HomeSeer.Jui.Types.EInputType.Password)

                        'Add the page to the list of plugin settings pages
                        Settings.Add(settingsPage.Page)
                        -Larry

                        A member of "The HA Pioneer Group", MyWebSite

                        Plugins:
                        VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

                        Hardware:
                        Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

                        Comment


                          #13
                          Originally posted by lpitman View Post

                          Thats the same as I'm using?
                          Check the parameters. Parameter 3 is a value and 4 is some type. I don't see you setting the value and in my code I don't set the type which is optional

                          HTML Code:
                                      settingsPage1.WithDropDownSelectList(Constants.Settings.Sp1DebugLevelOptionsId, Constants.Settings.Sp1DebugLevelOptionsName, Constants.Settings.Sp1DebugLevelOptions, DebugLevel.dlErrorsOnly)
                                      settingsPage1.WithDropDownSelectList(Constants.Settings.Sp1UPNPDebugLevelOptionsId, Constants.Settings.Sp1UPNPDebugLevelOptionsName, Constants.Settings.Sp1UPNPDebugLevelOptions, DebugLevel.dlErrorsOnly)
                                      settingsPage1.WithToggle(Constants.Settings.Sp1DebugToggleLogtoDiskToggleId, Constants.Settings.Sp1LogtoDiskToggleName)
                          
                                      'Add the Music DB Setting Label to the page
                                      settingsPage1.WithLabel(Constants.Settings.Sp1MusicDBLabelId, Nothing, Constants.Settings.Sp1MusicDBLabelValue)
                          
                                      settingsPage1.WithToggle(Constants.Settings.Sp1AutoUpdateFlagId, Constants.Settings.Sp1AutoUpdateFlagName, True)
                                      settingsPage1.WithToggle(Constants.Settings.Sp1ImmediateUpdateFlagId, Constants.Settings.Sp1ImmediateUpdateFlagName, False)
                                      settingsPage1.WithToggle(Constants.Settings.Sp1LearnRadioStationsFlagId, Constants.Settings.Sp1LearnRadioStationsFlagName, True)
                                      settingsPage1.WithInput(Constants.Settings.Sp1AutoUpdateTimeId, Constants.Settings.Sp1AutoUpdateTimeInputBoxName, "02:10")

                          Comment


                            #14
                            Settings Page does save settings in INI file, but does not load them on startup. I have to toggle off then toggle on things like Debug Checkbox and other configuration items.
                            -Larry

                            A member of "The HA Pioneer Group", MyWebSite

                            Plugins:
                            VWS, AB8SS, lrpSpeak, Calendar, Arduino, Harmony, BlueIris, Sprinklers, ZipBackup...

                            Hardware:
                            Intel NUC8i7BEH1 running Windows 10 Pro headless, HS3 Pro, Plex running on Synology dual High Availability DS-1815+ NAS (24Tb each), Synology Surveillance Station running on DS-416 Slim (8Tb), Samsung SmartThings, Google Home, Alexa, Hubitat Elevation, ZNET, Ubiquiti UniFi Network, Davis Vantage Pro II Weather Station. Whole house speaker system using a couple of AB8SS switches. Vantage Pro II Weather Station, Rain8Net Sprinklers, Hubitat Elevation, Google Home, Alexa, DSC Security System, Ubiquiti UniFi Network.

                            Comment


                              #15
                              During initialization I load my settings into local variables

                              Code:
                                      public void Load()
                                      {
                                          Location = _hs.GetINISetting("Settings", "Location", "Hubitat", Utils.IniFile);//I Like it When I can Set a Default location myself
                                          Location2 = _hs.GetINISetting("Settings", "Location2", "Hubitat", Utils.IniFile);
                                          DebugLog = bool.Parse(_hs.GetINISetting("Settings", "DebugLog", "false", Utils.IniFile));
                                          MakerURI = _hs.GetINISetting("Settings", "MakerURI", "", Utils.IniFile);
                                      }
                              I then use them to initialize my settings page and also in response to the setting page save

                              Code:
                                      private void InitializeSettingsPages()
                                      {
                              
                                          //Start a PageFactory to construct the Page
                                          var settingsPage1 = PageFactory.CreateSettingsPage("idConfig", "Config");
                              
                                          //Add a LabelView to the page
                                          settingsPage1.WithLabel("idlblMakerAPIURL", null, "Hubitat Maker API URL:"); //"Config");
                              
                                          //Add a text InputView for the Maker API text
                                          settingsPage1.WithInput("idtxtMakerAPIURL", "MakerAPI URL", _settings.MakerURI, HomeSeer.Jui.Types.EInputType.Text);
                                          settingsPage1.WithInput("idtxtLocation", "Floor (Location2)", _settings.Location2, HomeSeer.Jui.Types.EInputType.Text);
                                          settingsPage1.WithInput("idtxtLocation2", "Room (Location)", _settings.Location, HomeSeer.Jui.Types.EInputType.Text);
                              
                                          //Add a checkbox to the page for Debug
                                          settingsPage1.WithCheckBox("idchkDebug", "Debug", _settings.DebugLog);
                              
                                          //Add the first page to the list of plugin settings pages HomeSeer.Jui.Views.SettingsCollection.
                                          Settings.Add(settingsPage1.Page);
                                      }
                              Code:
                                      protected override bool OnSettingChange(string pageId, AbstractView currentView, AbstractView changedView)
                                      {
                                          Console.WriteLine("OnSettingChange");
                              
                                          if (changedView.Id == "idtxtMakerAPIURL") _settings.MakerURI = changedView.GetStringValue();
                                          else if (changedView.Id == "idtxtLocation") _settings.Location = changedView.GetStringValue();
                                          if (changedView.Id == "idtxtLocation2") _settings.Location2 = changedView.GetStringValue();
                                          else if (changedView.Id == "idchkDebug") _settings.DebugLog = (changedView.GetStringValue() == "True");
                              
                                          return true;
                                      }

                              Comment

                              Working...
                              X