Announcement

Collapse
No announcement yet.

Error in trigger

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

  • Error in trigger

    Hello,

    I am trying to consolidate my plugin's triggers into one single trigger that lets the user set each of the specific parameters that should fire the trigger if there is a match on any of them. However for the life of me I cannot work out what I have done wrong below. There are no syntax errors that I can see, and each of the Title_ and so on are correct but when I try to create a trigger in the events page although the page is generated, when I make a change to the dropdown box which triggers the postback I get an object or reference not set error.

    Is there anything that stands out with the below code, or better what is the best way to debug this kind of error when to be 100% honest I assume it is coming from one of the functions that is called when the fields are checked, or the events page is trying to build the string but I really have no idea.

    I should clarify too, that the plugin is not actually crashing, but rather just reporting the error in the console window.


    Code:
    #Region "Trigger Interface"
    
        Public ReadOnly Property TriggerConfigured(ByVal TrigInfo As HomeSeerAPI.IPlugInAPI.strTrigActInfo) As Boolean
            Get
                Dim Configured As Boolean = False
                Dim sKey As String
                Dim UID As String
                UID = TrigInfo.UID.ToString
    
                Dim itemsConfigured As Integer = 0
                Dim itemsToConfigure As Integer = 4
                If Not (TrigInfo.DataIn Is Nothing) Then
                    DeSerializeObject(TrigInfo.DataIn, trigger)
                    For Each sKey In trigger.Keys
                        Select Case True
                            Case InStr(sKey, "Priority_" & UID) > 0 AndAlso trigger(sKey) <> ""
                                itemsConfigured += 1
                            Case InStr(sKey, "Title_" & UID) > 0 AndAlso trigger(sKey) <> ""
                                itemsConfigured += 1
                            Case InStr(sKey, "Message_" & UID) > 0 AndAlso trigger(sKey) <> ""
                                itemsConfigured += 1
                            Case InStr(sKey, "App_" & UID) > 0 AndAlso trigger(sKey) <> ""
                                itemsConfigured += 1
                        End Select
                    Next
                    If itemsConfigured = itemsToConfigure Then Configured = True
                End If
                Return Configured
    
            End Get
        End Property
    
        Public Function TriggerBuildUI(ByVal sUnique As String, ByVal TrigInfo As HomeSeerAPI.IPlugInAPI.strTrigActInfo) As String
            Dim UID As String
            UID = TrigInfo.UID.ToString
            Dim stb As New StringBuilder
            Dim sKey As String
            Dim Priority As String = ""
            Dim Title As String = ""
            Dim Message As String = ""
            Dim App As String = ""
    
    
            Dim POApp As New clsJQuery.jqTextBox("App_" & UID & sUnique, "text", "Any", "Events", 50, False)
            stb.Append("&nbsp;&nbsp;")
            stb.Append("Enter App to be Searched: " & POApp.Build & "<Br>")
    
            Dim POTitle As New clsJQuery.jqTextBox("Title_" & UID & sUnique, "text", "Any", "Events", 50, False)
            stb.Append("&nbsp;&nbsp;")
            stb.Append("Enter Title to be Searched: " & POTitle.Build & "<Br>")
    
            Dim POMessage As New clsJQuery.jqTextBox("Message_" & UID & sUnique, "text", "Any", "Events", 50, False)
            stb.Append("&nbsp;&nbsp;")
            stb.Append("Enter Message to be Searched: " & POMessage.Build & "<Br>")
    
    
            Dim dd2 As New clsJQuery.jqDropList("Priority_" & UID & sUnique, Pagename, True)
            dd2.autoPostBack = True
            dd2.AddItem("--Please Select--", "", False)
            dd2.AddItem("Any Priority", "Any Priority", ("Any Priority" = Priority))
            dd2.AddItem("Lowest Priority", "Lowest Priority", ("Lowest Priority" = Priority))
            dd2.AddItem("Low Priority", "Low Priority", ("Low Priority" = Priority))
            dd2.AddItem("Normal Priority", "Normal Priority", ("Normal Priority" = Priority))
            dd2.AddItem("High Priority", "High Priority", ("High Priority" = Priority))
            dd2.AddItem("Emergency Priority", "Emergency Priority", ("Emergency Priority" = Priority))
            stb.Append("Enter Priority to trigger event:")
            stb.Append(dd2.Build)
    
            
    
    
                If Not (TrigInfo.DataIn Is Nothing) Then
                    DeSerializeObject(TrigInfo.DataIn, trigger)
                Else 'new event, so clean out the trigger object
                    trigger = New trigger
                End If
    
                For Each sKey In trigger.Keys
                    Select Case True
                    Case InStr(sKey, "Priority_" & UID) > 0
                        Priority = trigger(sKey)
                    Case InStr(sKey, "App_" & UID) > 0
                        POApp = trigger(sKey)
                    Case InStr(sKey, "Title_" & UID) > 0
                        POTitle = trigger(sKey)
                    Case InStr(sKey, "Message_" & UID) > 0
                        POMessage = trigger(sKey)
                End Select
                Next
    
                Return stb.ToString
    
        End Function
    
        Public Function TriggerProcessPostUI(ByVal PostData As System.Collections.Specialized.NameValueCollection, _
                                                         ByVal TrigInfo As HomeSeerAPI.IPlugInAPI.strTrigActInfo) As HomeSeerAPI.IPlugInAPI.strMultiReturn
            Dim Ret As New HomeSeerAPI.IPlugInAPI.strMultiReturn
            Dim UID As String
            UID = TrigInfo.UID.ToString
    
            Ret.sResult = ""
            ' We cannot be passed info ByRef from HomeSeer, so turn right around and return this same value so that if we want, 
            '   we can exit here by returning 'Ret', all ready to go.  If in this procedure we need to change DataOut or TrigInfo,
            '   we can still do that.
            Ret.DataOut = TrigInfo.DataIn
            Ret.TrigActInfo = TrigInfo
    
            If PostData Is Nothing Then Return Ret
            If PostData.Count < 1 Then Return Ret
    
            If Not (TrigInfo.DataIn Is Nothing) Then
                DeSerializeObject(TrigInfo.DataIn, trigger)
            End If
    
            Dim parts As Collections.Specialized.NameValueCollection
    
            Dim sKey As String
    
            parts = PostData
            Try
                For Each sKey In parts.Keys
                    If sKey Is Nothing Then Continue For
                    If String.IsNullOrEmpty(sKey.Trim) Then Continue For
                    Select Case True
                        Case InStr(sKey, "Priority_" & UID) > 0, InStr(sKey, "App_" & UID) > 0, InStr(sKey, "Title_" & UID) > 0, InStr(sKey, "Message_" & UID) > 0
                            trigger.Add(CObj(parts(sKey)), sKey)
                    End Select
                Next
    
                If Not SerializeObject(trigger, Ret.DataOut) Then
                    Ret.sResult = IFACE_NAME & " Error, Serialization failed. Signal Trigger not added."
                    Return Ret
                End If
            Catch ex As Exception
                Ret.sResult = "ERROR, Exception in Trigger UI of " & IFACE_NAME & ": " & ex.Message
                Return Ret
            End Try
    
            ' All OK
            Ret.sResult = ""
            Return Ret
        End Function
    
        Public Function TriggerFormatUI(ByVal TrigInfo As HomeSeerAPI.IPlugInAPI.strTrigActInfo) As String
            Dim stb As New StringBuilder
            Dim sKey As String
            Dim POPriority As String = ""
            Dim POTitle As String = ""
            Dim POMessage As String = ""
            Dim POApp As String = ""
            Dim UID As String
            UID = TrigInfo.UID.ToString
    
            Try
    
    
                If Not (TrigInfo.DataIn Is Nothing) Then
                    DeSerializeObject(TrigInfo.DataIn, trigger)
                End If
    
                For Each sKey In trigger.Keys
                    Select Case True
                        Case InStr(sKey, "Priority_" & UID) > 0
                            POPriority = trigger(sKey)
                        Case InStr(sKey, "Title_" & UID) > 0
                            POTitle = trigger(sKey)
                        Case InStr(sKey, "Message_" & UID) > 0
                            POMessage = trigger(sKey)
                        Case InStr(sKey, "App_" & UID) > 0
                            POApp = trigger(sKey)
                    End Select
                Next
    
                stb.Append("Trigger on a message recieved, where the title contains:" & POTitle)
                stb.Append(" and message contains:" & POMessage)
                stb.Append(" and priority is:" & POPriority)
                stb.Append(" from app:" & POApp)
    
                Return stb.ToString
    
            Catch ex As Exception
                Console.WriteLine(ex.Message)
                hs.WriteLog("TriggerFormatUI_ERR", ex.Message)
            End Try
    
        End Function
    
    
    #End Region

    Many Thanks
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

  • #2
    Hoping someone might be able to help me with this, I will give you the background if it helps.

    I am working on a Pushover plugin which will be released free to the HS3 community, the plugin is not a duplication and is not designed to sent pushover messages (as the IFTTT, and Pushover (3P) plugins both achieve this) but rather this plugin connects to the Pushover.net servers as a Pushover Open Client.

    Basically this opens up a websocket connection with the Pushover.net server, and when a message is sent to the pushover device, the websocket connection gets a message to basically say download the new message, to which it does.

    That part is working fine, but before I can open it up for beta testing I need to try and get this trigger issue working so people can trigger events based on which app it was sent from, if the body contains specific text, and if the title contains specific text, however I can't get it to accept the trigger information to save in the form.

    In my testing it works fine on Mono as well as windows, it accepts the users email address and password (once) and then retrieves their client secret which is stored and used to create a new Pushover.net device, and also to connect to the websocket server as that device.

    Appreciate anyone's help, since I am self taught I tend to work fine until I hit an error which I try to debug but don't always have the best of luck doing so.
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    Comment

    Working...
    X