Announcement

Collapse
No announcement yet.

Master Device creation in C#

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

    Master Device creation in C#

    I'm trying to put together my first plugin and I'm not able to find any examples of how to create the master device. Does anyone have a code snippet that they could share?


    Sent from my SM-G988U using Tapatalk


    #2
    Have a look at the sample plugin https://github.com/HomeSeer
    Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


      #3
      That's where I started to work from. I've gathered a few good thoughts from that, but I think I'm confused. This is what I have so far:

      Code:
      DeviceFactory df = DeviceFactory.CreateDevice(Id);
      Console.WriteLine("Id: Step 1" + Id);
      df.WithName("ZoneMinder Main");
      df.AsType(EDeviceType.Generic,0);
      var ff = FeatureFactory.CreateFeature(Id);
      ff.WithName("Server Load");
      df.WithFeature(ff);
      df.PrepareForHs();
      What am I missing?

      Comment


        #4
        ref = HS.CreateDevice(df)
        -- Wim

        Plugins: JowiHue, RFXCOM, Sonos4, Jon00's Perfmon and Network monitor, EasyTrigger, Pushover 3P, rnbWeather, BLBackup, AK SmartDevice, Pushover, PHLocation, Zwave, GCalseer, SDJ-Health, Device History, BLGData

        1210 devices/features ---- 392 events ----- 40 scripts

        Comment


          #5
          Thanks Gents!

          Comment


            #6
            Hi lorenjz,

            Not saying this is perfect or the best way but here you go:

            Code:
            Sub Build_Device()
            Dim deviceinfo As HsDevice = Nothing
            If HomeSeerSystem.GetDeviceByAddress(Name & "ROOT") Is Nothing Then
            Try
            Dim newdevice As New DeviceFactory
            Dim PIED As PlugExtraData = New PlugExtraData()
            Dim hsFlags As EMiscFlag() = New EMiscFlag() {EMiscFlag.ShowValues}
            newdevice = DeviceFactory.CreateDevice(Id)
            newdevice.WithLocation(Name)
            newdevice.WithLocation2(Name)
            newdevice.AsType(EDeviceType.Generic, 0)
            newdevice.WithName(hydrawise.data.controller.name)
            newdevice.WithMiscFlags(hsFlags)
            Dim ndd As NewDeviceData = newdevice.PrepareForHs()
            Dim device As Integer = HomeSeerSystem.CreateDevice(ndd)
            Dim adddata As New Dictionary(Of EProperty, Object)
            adddata.Add(EProperty.Address, Name & "ROOT")
            HomeSeerSystem.UpdateDeviceByRef(device, adddata)
            deviceinfo = HomeSeerSystem.GetDeviceByRef(device)
            HomeSeerSystem.WriteLog(ELogType.Info, "New Device " & deviceinfo.Name & " (" & deviceinfo.Ref & "-" & deviceinfo.Address & ") has been created", Name)
            Catch ex As Exception
            HomeSeerSystem.WriteLog(ELogType.Error, "Unable to crete device: " & ex.Message, Name)
            End Try
            Else
            deviceinfo = HomeSeerSystem.GetDeviceByAddress(Name & "ROOT")
            HomeSeerSystem.WriteLog(ELogType.Debug, "Not creating device (" & deviceinfo.Name & ") as it already exists", Name)
            End If
            End Sub

            Comment


              #7
              Hi lorenjz,

              And then for adding features to the device
              (Note - I use a loop to add the features hence I've structure my code this way! I run the loop from the Device creation sub hence HS device as an input parameter which allows me to connect the feature to the correct parent)

              Code:
              Sub Check_Feature_Build(parent As HsDevice)
              Dim featureinfo As HsFeature = Nothing
              If HomeSeerSystem.GetFeatureByAddress(Name & "Status") Is Nothing Then
              Try
              Dim newfeature As New FeatureFactory
              Dim PIED As PlugExtraData = New PlugExtraData()
              Dim hsFlags As EMiscFlag() = New EMiscFlag() {EMiscFlag.ShowValues}
              newfeature = FeatureFactory.CreateFeature(Id)
              newfeature.OnDevice(parent.Ref)
              newfeature.AsType(EFeatureType.Generic, 0)
              newfeature.WithName("Status")
              newfeature.WithLocation(Name)
              newfeature.WithLocation2(Name)
              newfeature.WithDefaultValue(0)
              newfeature.AddGraphicForValue("/folder/imageA.png", 0, "Status Text")
              newfeature.AddGraphicForValue("/folder/imageB.png", 1, "Status Text")
              newfeature.WithMiscFlags(hsFlags)
              Dim nfd As NewFeatureData = newfeature.PrepareForHs()
              Dim feature As Integer = HomeSeerSystem.CreateFeatureForDevice(nfd)
              Dim adddata As New Dictionary(Of EProperty, Object)
              adddata.Add(EProperty.Address, Name & "Status")
              HomeSeerSystem.UpdateFeatureByRef(feature, adddata)
              featureinfo = HomeSeerSystem.GetFeatureByRef(feature)
              Console.WriteLine("Feature ID: " & feature & " (Name: " & featureinfo.Name & " - Device Type: " & featureinfo.TypeInfo.Type.ToString() & "-" & featureinfo.TypeInfo.SubType.ToString() & ")")
              HomeSeerSystem.WriteLog(ELogType.Info, "New Feature " & featureinfo.Name & " (" & featureinfo.Ref & "-" & featureinfo.Address & ") has been added to " & parent.Name & "(" & parent.Ref & ")", Name)
              Catch ex As Exception
              HomeSeerSystem.WriteLog(ELogType.Error, "Unable to crete device feature: " & ex.Message, Name)
              End Try
              Else
              featureinfo = HomeSeerSystem.GetFeatureByAddress(Name & "Status")
              HomeSeerSystem.WriteLog(ELogType.Debug, "Not creating device feature (" & featureinfo.Name & ") as it already exists", Name)
              End If
              End Sub

              Comment


                #8
                So , will we see new plugins made by you soon
                lorenjz russr999

                Comment


                  #9
                  Originally posted by MattL0 View Post
                  So , will we see new plugins made by you soon
                  lorenjz russr999
                  I have the Hydrawise HS4 Plugin done! So building out the HS3 version to release together! 😁
                  (For any new plugins, ideally I think people should be able to get HS3 and/or HS4 version without having to pay more! Just my view though hence releasing together!)
                  I already have a HS3 plugin in the store - rnbPlace which is Homeseers control and status of myPlace by Advantage Air
                  😉

                  Comment


                    #10
                    Originally posted by MattL0 View Post
                    So , will we see new plugins made by you soon
                    lorenjz russr999
                    Could be.... Experimenting with Zoneminder. First I have to figure out how to parse two bits of JSON data from zoneminder to features. Once that's done there are a couple of other bits.

                    Comment


                      #11
                      I think that I'm starting to understand. However, it's not clear how the features get their functionality. For instance when a button is clicked, should there be an event-listener enabled or what method is called to have it do something?

                      Thanks again for all of the help!

                      Comment


                        #12
                        Originally posted by lorenjz View Post
                        I think that I'm starting to understand. However, it's not clear how the features get their functionality. For instance when a button is clicked, should there be an event-listener enabled or what method is called to have it do something?

                        Thanks again for all of the help!
                        From memory, this is the sub where I capture the buttons action where the button is on the devices page:

                        Code:
                        Public Overrides Sub SetIOMulti(colSend As List(Of ControlEvent))
                        If the button is on a feature page then you will need to use an ajax postback

                        Comment


                          #13
                          Originally posted by russr999 View Post

                          From memory, this is the sub where I capture the buttons action where the button is on the devices page:

                          Code:
                          Public Overrides Sub SetIOMulti(colSend As List(Of ControlEvent))
                          If the button is on a feature page then you will need to use an ajax postback
                          But your plugin is done with VB correct?

                          Comment


                            #14
                            Originally posted by lorenjz View Post

                            But your plugin is done with VB correct?
                            Yes

                            If you're using C#, the equivalent is:

                            Code:
                            public override void SetIOMulti(List<ControlEvent> colSend)
                            {
                            
                            }

                            Comment


                              #15
                              Originally posted by russr999 View Post

                              Yes

                              If you're using C#, the equivalent is:

                              Code:
                              public override void SetIOMulti(List<ControlEvent> colSend)
                              {
                              
                              }
                              Perfect! Thank you

                              Comment

                              Working...
                              X