No announcement yet.

Action OnConfigItemUpdate - how is this supposed to work?

  • Filter
  • Time
  • Show
Clear All
new posts

    Action OnConfigItemUpdate - how is this supposed to work?

    I have a dropdown in my action configpage with 2 choices - "All Devices" and "Specific Device", and I built it with OptionKeys using values of "1" and "2" respectively.

    When this event fires and the configChangeView is examined, there are no OptionKeys, and the Options are just "0" and "1". And if I use "GetSelectedOptionKey", it comes back blank, but "GetSelectedOption" returns "1", even though I've selected "Sepcific Device" (2).

    Anybody have experience with this? The documentation is practically non-existent on what these functions do or how to use them...

    I had no difficulty with the update logic. I found the Sample plugin to be sufficient for me to understand how to migrate. I also did a post in this forum that contained a step by step of migrating action (and triggers) from HS3 to HS4.


      I've run into two defects that are preventing both normal functionality and migration, so I beg to differ!


        Originally posted by Michael McSharry View Post
        I also did a post in this forum that contained a step by step of migrating action (and triggers) from HS3 to HS4.

        And yes, I've seen (and studied that) so thanks!


          I am not totally following the terminology on your original post. I assume that event fires means a call is made to OnRunAction of the class where there action is defined. configChangeView and OptionKeys is not something I am familiar. To get the action parameters that the user setup I use the class's Id's. Once I get the view's/control's values I then just use the logic I ported from HS3 code. In my example I have a select list and a text box that user configures in the event action setup.

             Public Overrides Function OnRunAction() As Boolean
                  Dim iActionType As Integer = If((TryCast(ConfigPage?.GetViewById(ActionTypeSelectListId), SelectListView))?.Selection, 1)
                  Dim sInput As String = If((TryCast(ConfigPage?.GetViewById(ActionInputId), InputView))?.Value, "")
                  Return plugin.HandleActionX(iActionType, sInput)
              End Function
              Private ReadOnly Property ActionTypeSelectListId As String
                      Return $"{PageId}-ActionType"
                  End Get
              End Property
          I also show a select list and a toggle at

          In this case it is executed following the "Save" button on the HS4 replacement for HS3 ConfigDevice, but getting the view's values processing is the same as if it was a result of a event action OnRunAction.

          I dont remember if I posted the OnConfigItemUpdate code in my step-by-step for action. It is
          Protected Overrides Function OnConfigItemUpdate(ByVal configViewChange As AbstractView) As Boolean
                  Dim selectList As SelectListView = TryCast(ConfigPage.GetViewById(ActionTypeSelectListId), SelectListView)
                  Dim iActionType As Integer = selectList.Selection
                  Dim inputView As InputView = TryCast(ConfigPage.GetViewById(ActionInputId), InputView)
                  Dim sMessage As String = configViewChange.GetStringValue 'inputView.GetStringValue
                  Dim changedActionType As SelectListView = TryCast(configViewChange, SelectListView)
                  If changedActionType IsNot Nothing Then
                      'change made to the selector?
                      If selectList.Selection <> changedActionType.Selection AndAlso selectList.Selection <> -1 Then
                          ConfigPage = InitNewConfigPage(changedActionType.Selection).Page
                          Return False
                      End If
                  End If
                  With New System.Text.StringBuilder
                      If iActionType = 0 Then
                          'send mqtt message
                          Dim i As Integer = InStr(sMessage, "=")
                          If i = 0 Then
                              ConfigPage = InitConfigPageWithFeedback("No action will be performed because message not entered as Topic=Payload").Page
                              Return False
                          End If
                      ElseIf iActionType = 1 Then
                          If Not System.IO.File.Exists(gDataPath & sMessage & ".pub") Then
                              ConfigPage = InitConfigPageWithFeedback("Publist publication list " * sMessage & " will not execute as an event action until " & sMessage & " is created.").Page
                              Return True
                          End If
                      End If
                  End With
                  Return True
              End Function


            Sorry, I meant when that method (OnConfigItemUpdate) is executed. But I think the issue I originally posted about (not having insight about what was selected) was corrected in the latest PluginSDK, since I haven't had that problem since I udpated.

            There's still no way to do a multi-select dropdown, though, and text entered into an InputView get lost if you change a dropdown (and presumably other types that do a postback like toggles). And RemoveViewByID also doesn't work, so dynamically changing the configpage can only be done by a hack of a workaround to forcibly recreate the whole ConfigPage.