Announcement

Collapse
No announcement yet.

Sample Plugin: Basic Sample

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

    Sample Plugin: Basic Sample

    Here is a sample HS3 plug-in that can be used as a starting point for new plugins or for modifying existing plugins.

    Version 1.0.0.0:

    ftp://ftp.homeseer.com/updates/Beta/...IC_1_0_0_0.zip

    This sample shows examples of:

    Multiple web page interaction.
    A small list of controls and possible ways of interfacing with them.
    Code for device creation.
    Code for basic action and trigger interfacing.

    This sample does not explore the more diverse possibilities that HS3 offers plugin developers, but gives them a basic starting point for understanding plugin interaction with HS3.
    For more in-depth examples, please look at the original sample.

    I am more than happy to answer questions.
    Wade

    "I know nothing... nothing!"

    #2
    Very nice. Thanks for sharing
    Cheers,
    Bob
    Web site | Help Desk | Feature Requests | Message Board

    Comment


      #3
      Wow, fantastic!
      I'll look into this.

      I'm sure I will have questions...
      HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
      Running on Windows 10 (64) virtualized
      on ESXi (Fujitsu Primergy TX150 S8).
      WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

      Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

      Comment


        #4
        I have made a couple small updates to the sample.

        Version 1.0.0.1:

        ftp://ftp.homeseer.com/updates/Beta/...IC_1_0_0_1.zip

        Checkbox example has been updated to reflect code changes in the javascript. (Name is now returned when SubmitForm is True) This will work with the next build of HS3.

        A new tab with a slider example was added.
        Wade

        "I know nothing... nothing!"

        Comment


          #5
          I took another shot by a plugin. I really like this sample. It's cleaner than the original sample plugin.
          And there is ALOT of functionality in there. I like that!
          (And it even works right out of the box.)

          But I still find it somewhat confusing. There are very few comments in the code, and when they are, they are explaining something I don't understand (see "DeSerializeObject" as an example, I'll get back to that).

          Here's an excellent opportunity to both add to the online help library and make a better sample! For instance I had to look up the function "HandleAction" in the online help, to see if it was a plugin specific function or a HomeSeer "required" function (and I suspected the latter). I found it in the library here.


          But here's the clue: There's no way of knowing what it actually does when you just open the sample code! It would be EXTREMELY nice if this was explained, and yet again I suggest the use of XML comments (just press ' three times and off you go):

          Code:
              ''' <summary>
              ''' When an event is triggered, this function is called to carry out the selected action.
              ''' Use the ActInfo parameter to determine what action needs to be executed, then execute this action.
              ''' </summary>
              ''' <param name="ActInfo">An information string about the action to be triggered !??!???!!</param>
              ''' <returns>TRUE if the action was executed successfully, FALSE if there was an error.</returns>
              ''' <remarks></remarks>
              Public Function HandleAction(ByVal ActInfo As IPlugInAPI.strTrigActInfo) As Boolean
          Look familiar? Most of it is "copy-and-paste" from the help file. But with just a little more efford in the plugin, you gain:
          - Code that is much more readable and understandable (you can just hoover the mouse over a function to see what it is and what it does).
          - A generated XML file ready to be parsed into the online help, where all functions are already written and documented.

          (HandleAction does actually not only return False if it encounters an error. For that to happen, the Catch-EndCatch lines should look like this:
          Code:
                  Catch ex As Exception
                      hs.WriteLog(IFACE_NAME, "Error executing action: " & ex.Message)
                      Return False
                  End Try
          ...)


          ... so let's get back to DeSerializeObject.
          I actually had to look up "deserialize" in the dictionary to get started. The first thing I notice is that it takes bytes as input, and spits out an "Object".
          But what else does it do? I have no idea.
          I guess it returns True if something is a success, and False if not. But other than that the comment and the code really does not make sense to me. I don't even know why it is needed.



          But still! I like that it is cleaner and and simplier. We are so close!
          HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
          Running on Windows 10 (64) virtualized
          on ESXi (Fujitsu Primergy TX150 S8).
          WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

          Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

          Comment


            #6
            I'll give you a quick rundown on actions and trigger now, and add these comments to the sample when I get a chance.

            Actions and triggers have four common parts, with actions having a fifth.

            These are:

            Build
            Post
            Configure
            Format

            The fifth part of an action is : Handle


            The build is where you construct your UI for display in the events page.

            The post is where you get your postback upon user submission.

            The configure is a boolean response to determine if the action or trigger has been fully configured.

            If that boolean returns false, then the build is run again.

            If that boolean returns true, then the format code is run, and your action/trigger is complete.

            Upon expansion of an action or trigger (minus sign showing), the process is started again, with the build and post being the only things run.

            Upon collapse of the action/trigger(plus sign showing) configure is run.

            If that boolean returns false, then the build is run again.

            If that boolean returns true, then the format code is run, and your action/trigger is complete.

            The Handle action is run when that action has been evoked, either manually, or by an event. It will not run while the action/trigger is expanded, or configure is false.


            Okay, on to the Deserialize function.

            I prefer keeping my data with the action/trigger. It frees me from having to keep track of any of it in the plugin.

            If data is stored in the strTrigActInfo object, it must be in byte form. This is to allow a variety of data types to be stored there.

            In the post of an action/trigger, the data object is serialized(converted to bytes) and stored in the strTrigActInfo.

            When the strTrigActInfo is passed to the plugin from HS3 in any of the functions, the data held by that object must first be deserialized(converted from bytes) in order to be used.
            Wade

            "I know nothing... nothing!"

            Comment


              #7
              Anyone having problems downloading the sample?

              Originally posted by Sgt. Shultz View Post
              I have made a couple small updates to the sample.

              Version 1.0.0.1:

              ftp://ftp.homeseer.com/updates/Beta/...IC_1_0_0_1.zip

              Checkbox example has been updated to reflect code changes in the javascript. (Name is now returned when SubmitForm is True) This will work with the next build of HS3.

              A new tab with a slider example was added.
              Don

              Comment


                #8
                Originally posted by donstephens View Post
                Anyone having problems downloading the sample?
                I was able to download it ok here - what message are you getting?
                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


                  #9
                  No error message.... just stalls. Will try IE.
                  Don

                  Comment


                    #10
                    I have made a couple small updates to the sample.

                    Version 1.0.0.2:

                    ftp://ftp.homeseer.com/updates/Beta/...IC_1_0_0_2.zip

                    Listbox example has been updated to reflect code changes in the javascript.
                    (Entering a value with an apostrophe no longer crashes the object)
                    This will work with the next build of HS3.

                    Two new multi-select controls were added to the listbox tab.
                    A new size property was added to the multi-select control (this will work in the next build)

                    A new Selector control was added to the listbox tab.
                    The control had double click functionality added to the control.
                    The control had postback functionality added to the control.
                    These modifications will be available in the next build.
                    Wade

                    "I know nothing... nothing!"

                    Comment


                      #11
                      Error 8 'ButtonPress' cannot implement 'ButtonPress' because there is no matching sub

                      is anyone else getting this error with the sample \HSPI_SAMPLE_BASIC_1_0_0_2

                      Error 8 'ButtonPress' cannot implement 'ButtonPress' because there is no matching sub on interface 'HomeSeerAPI.IPlugInAPI'. D:\HS3PLUGINS\HSPI_SAMPLE_BASIC_1_0_0_2\hspi.vb 137 92 HSPI_SAMPLE_BASIC

                      Comment


                        #12
                        i believe buttenpress is removed in the last version

                        Comment


                          #13
                          I have updated the sample to take care of this.

                          Version 1.0.0.3:

                          ftp://ftp.homeseer.com/updates/Beta/...IC_1_0_0_3.zip
                          Wade

                          "I know nothing... nothing!"

                          Comment


                            #14
                            Thanks

                            Comment


                              #15
                              Thread safe code

                              Originally posted by Sgt. Shultz View Post
                              I have updated the sample to take care of this.

                              Version 1.0.0.3:

                              ftp://ftp.homeseer.com/updates/Beta/...IC_1_0_0_3.zip

                              I am using this code as a base to a CS Plugin Sample ( My plugins are written in CS).
                              Works well for now.
                              Two things i have noted so far :
                              • I get error messages about processor architecture : Warning 5 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Scheduler", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your projecthttp://msdn.microsoft.com/en-us/libr...ollection.aspx
                              • It could easyly be replaced by :
                              Public Class KeyIndex
                              Inherits System.Collections.CollectionBase
                              End Class
                              and add the Remove method :

                              Public Sub Remove(ByVal index as Integer)
                              ' Check to see if there is a widget at the supplied index.
                              If index > Count - 1 Or index < 0 Then
                              ' If no widget exists, forget it

                              Else
                              ' Invokes the RemoveAt method of the List object.
                              List.RemoveAt(index)
                              End If
                              End Sub

                              http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx


                              Had to do this in CS.

                              Claude


                              Comment

                              Working...
                              X