Announcement

Collapse
No announcement yet.

HS3 Plugin Samples

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • rmasonjr
    replied
    Originally posted by happnatious1 View Post
    Well I just spent a few hours figuring out actionconfigured and handleaction and how they interact with all the other procedures and I'm shocked to say I can now run my plugin in homeseer and turn zone1 of my monoprice amp on and off using events

    My head is spinning and I need to go to bed.
    Originally posted by Moskus View Post
    I spent some hours last night piecing triggers and actions togheter. It wasn't... erm... that bad, I actually can get it to work without too much problems.
    I have become intimately familiar with setting breakpoints, stepping through code, and watch windows

    That "sample" plugin is really difficult to follow. TANumber and SubTANumber took quite a while for me to wrap my head around. I ended up only using TANumber and my custom Action class to get around it.

    Leave a comment:


  • U5tabil
    replied
    How do i even start?

    What do i need to do to use this to make something of my own?

    Leave a comment:


  • Moskus
    replied
    Originally posted by happnatious1 View Post
    I haven't looked at triggers yet but I assume they are much the same as actions based on the name strTrigActInfo.
    Yes, they are not far from each other. Actions are easier than triggers IMHO.


    But WHY OH WHY is the class called strTrigActInfo?!???
    It's not a string, and it's actually possible to write it completely. That way a user could stand a chance understanding what's going on!

    Leave a comment:


  • happnatious1
    replied
    I haven't looked at triggers yet but I assume they are much the same as actions based on the name strTrigActInfo. Not sure if the plugin I'm writing would even need triggers.

    Leave a comment:


  • Moskus
    replied
    I spent some hours last night piecing triggers and actions togheter. It wasn't... erm... that bad, I actually can get it to work without too much problems.

    Leave a comment:


  • happnatious1
    replied
    Well I just spent a few hours figuring out actionconfigured and handleaction and how they interact with all the other procedures and I'm shocked to say I can now run my plugin in homeseer and turn zone1 of my monoprice amp on and off using events

    My head is spinning and I need to go to bed.

    Leave a comment:


  • Moskus
    replied
    I'm in the middle of writing my own base plugin. It'll handle basic initialization, device creation, updating, CAPI, etc. I need a clean, general base as I have a 3 or 4 plugins I want to write. All HomeSeer functions and procedures are updated with .NET comments describing their functions (based on the SDK), which I was disappointed was missing, and I'm adding a ton o comments as there's basicly nothing now.

    I'm planning to release this here on the board when I'm done so that people don't have to go through this yet again. It'll be very simple, but hopefully a good starting point covering the basics.


    However, I haven't even touched Triggers and Actions, and I'm seriously NOT looking forward to it, as anyone that has anything to say about it, says it's rather horrible.

    However, there are plenty of plugins out there that handle it. Perhaps somebody could write a few lines to simplify it? Just walk us through some smart setup and how the different procedures work.

    Leave a comment:


  • rmasonjr
    replied
    In my first plugin, I used TANumber and SubTANumber from the sample plugin. It is confusing as heck. In my second, I only use TANumber and use my own classes to manage any sub-trigger actions. It took weeks to figure out how to use them both. VERY steep learning curve.

    Leave a comment:


  • happnatious1
    replied
    In the sample plugin their sample class is marked as serialized and then the enums within the class is also marked as serialized. Is there a reason for this? It doesn't seem to make a difference in my class.

    Leave a comment:


  • happnatious1
    replied
    After sleeping on it I realized I made another newbie mistake. It does evaluate as true, however the next line of code will also be true because of the subtanumber changing. The solution was simply to remove the second expression in every orelse because it is not needed. I already have the data I need stored in MyActionData.

    One step closer.

    Leave a comment:


  • happnatious1
    replied
    I've made a lot of progress and I think I understand the relationship between actionbuildUI, PostprocessUI, FormatUI, and configured and my plugin sort of works. however I'm profoundly stuck. see attached picture. The line of code where the break point is always evaluates as the subTAnumber even though the first expression in the OrElse statement is obviously true. According to everything I can find online the second expression shouldn't even be evaluated.
    Attached Files

    Leave a comment:


  • happnatious1
    replied
    To answer my own question, the following code needs to be in postprocessui not buildui.

    Originally posted by happnatious1 View Post
    Code:
                If MyAction IsNot Nothing Then
                    Dim bteArray() As Byte = Nothing
                    If Not SerializeObject(MyAction, bteArray) Then Throw New Exception("Not able to Serialize myaction data in actionbuildui.")
    
                    Dim Ret As New IPlugInAPI.strMultiReturn
                    Ret.sResult = ""                ' Empty return indicates success!
                    Ret.TrigActInfo = ActInfo    ' Trig info does not change, just pass through what we received...
                    Ret.DataOut = bteArray
                    Return Ret
                End If

    Leave a comment:


  • happnatious1
    replied
    Code:
                If MyAction IsNot Nothing Then
                    Dim bteArray() As Byte = Nothing
                    If Not SerializeObject(MyAction, bteArray) Then Throw New Exception("Not able to Serialize myaction data in actionbuildui.")
    
                    Dim Ret As New IPlugInAPI.strMultiReturn
                    Ret.sResult = ""                ' Empty return indicates success!
                    Ret.TrigActInfo = ActInfo    ' Trig info does not change, just pass through what we received...
                    Ret.DataOut = bteArray
                    Return Ret
                End If

    Leave a comment:


  • Kirby
    replied
    I'm struggling with trying to serialize an action in buildUI. In the below example from Rick near the bottom it shows returning stringMultiReturn (which I guess is trigactioninfo with my serialized object tacked on to it). But I get the error Ret cannot be converted to type string. What am I doing wrong?
    Where is your code?

    Leave a comment:


  • happnatious1
    replied
    I'm struggling with trying to serialize an action in buildUI. In the below example from Rick near the bottom it shows returning stringMultiReturn (which I guess is trigactioninfo with my serialized object tacked on to it). But I get the error Ret cannot be converted to type string. What am I doing wrong?


    Originally posted by Rick Tinker View Post
    For simplicity I will refer to just Triggers, but it is the same whether triggers or actions.

    If DataIn is nothing or an array of 0 bytes, then you never gave anything to HS to store in DataOut, so I would expect deserialize to fail.

    Here is how it works: When somebody changes something in TriggerBuildUI it causes TriggerProcessPostUI to be called. Let's say the user configured a trigger by entering into fields you put on the UI the values 'Widget' and 12345. You need to save those values because it is your trigger, so you have two ways you can do it. You can create YOUR own storage mechanism and use the information in strTrigActInfo such as the UID, the evRef, trigger number and sub trigger number as an index... or you can have HS3 store those values for you. To have HS3 store the values, you create some sort of object that is serializeable to hold the values the user entered, like this:
    Code:
    <Serializable()> _
    Friend Class MyTriggerData
        Friend ProductName As String = ""
        Friend ProductSKU As Integer
    End Class
    Then, you put those values in the object like this:
    Code:
            Dim MyData As New MyTriggerData
            MyData.ProductName = "Widget"
            MyData.ProductSKU = 12345
    Then you serialize that object like this:
    Code:
            Dim bteArray() As Byte = Nothing
            If Not SerializeObject(MyData, bteArray) Then Throw New Exception("Dag Nabbit, another error.")
    Then you put the serialized object into the DataOut parameter of strMultiReturn like this:
    Code:
            Dim Ret As New strMultiReturn
            Ret.sResult = ""                ' Empty return indicates success!
            Ret.TrigActInfo = TrigInfoIn    ' Trig info does not change, just pass through what we received...
            Ret.DataOut = bteArray
    
            Return Ret

    And now, each time BuildUI, TriggerFormatUI, and TriggerProcessPostUI are called, the DataIN will be populated with that byte array you stored. In TriggerProcessPostUI you can update/change it by again passing it as DataOut, but in the other functions you would deserialize it just so that you have the data to use in the function.

    Make sense?

    FYI... One other twist to deserialization which is commented in the procedure... In order for deserialization to know that the structure or object that the data is going into matches where it came from, you have to pass a non-null object TO deserialization, even though the purpose of calling that is to get an object back filled with information.

    So you would think that you could call it like this:
    Code:
            Dim MyData As MyTriggerData
            If Not DeSerializeObject(TrigInfoIn.DataIn, MyData) Then Throw New Exception("Oh Poo!")
    but the way you REALLY need to call it is like this:
    Code:
            Dim MyData As [COLOR="Red"][B]New[/B][/COLOR] MyTriggerData
            If Not DeSerializeObject(TrigInfoIn.DataIn, MyData) Then Throw New Exception("Oh Poo!")

    Leave a comment:

Working...
X