Announcement

Collapse
No announcement yet.

How to save/commit feature changes?

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

    How to save/commit feature changes?

    Hi,

    I am confused. I know that I can update a value by using UpdateFeatureValueByRef(feature.ref). However, when updating other fields (like name) it should be done by using UpdatePropertyByRef(feature.ref, EProperty.Name, "Whatever"). But this doesn't get saved automatically.

    I tried hs.UpdateFeatureByRef(feature.Ref, feature.Changes) but that is giving me a "'Invalid type for property Service Version: NO_VERSION' error.

    Any help is appreciated! Thanks!
    stefxx

    #2
    Steffxx,

    The hs.UpdateFeatureByRef Is very, very buggy. It throws NO VERSION errors for almost every update here. I am only using UpdatePropertyByRef here now. It needs rereading the HSFeature again, as this is a more static representation of the moment you read it - it is not dynamic. So I combine both and it then works reliable. But it is wasting cycles for sure..

    Wim
    -- Wim

    Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
    650 devices ---- 336 events ----- 40 scripts

    Comment


      #3
      Thanks for your response Wim! What do you mean by "rereading the HsFeature again"? Do you have an example of how it works for you?

      Thanks again!
      stefxx

      Comment


        #4
        Stef,

        It is really simple what I am doing here, just a block of updates and - when needed - a reread of the object to make sure changes are reflected again in the object:

        Code:
         
        HS.UpdatePropertyByRef(ref, Devices.EProperty.DeviceType, DT)
        HS.UpdatePropertyByRef(ref, Devices.EProperty.PlugExtraData, PED)
        HS.UpdatePropertyByRef(ref, Devices.EProperty.Address, If(IsLight, lightrow.Uniqueid & "-L", grouprow.Uniqueid & "-L"))
        HsFeature=HS.GetFeatureByRef(ref)
        Wim
        -- Wim

        Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
        650 devices ---- 336 events ----- 40 scripts

        Comment


          #5
          Thanks, that is clear. However, it doesn't solve my issue.

          If I update several devices like this, most of it doesn't get saved. Especially setting the Device Status gets lost.

          stefxx

          Comment


            #6
            Stef,

            I have it working this way here, no separate saving needed? Wonder why it would not work. As far I can remember I did not do anything else.....
            -- Wim

            Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
            650 devices ---- 336 events ----- 40 scripts

            Comment


              #7
              If seems to happen when I update several devices quickly after each other. If I update the hsfeature first, it seems to work. Like this:

              feature.Status = "Whatever"
              UpdatePropertyByRef(feature.ref, EProperty.Status, "Whatever")

              If this remains stable, I leave it for now until someone from HomeSeer gives us a better way.
              stefxx

              Comment


                #8
                Originally posted by stefxx View Post
                If I update the hsfeature first, it seems to work.
                Never mind, it still doesn't work.

                stefxx

                Comment


                  #9
                  Confusing as heck, I know, but to update the status I use:
                  UpdateFeatureValueStringByRef(FeatureRef, NewValue.ToString)

                  For most other things I use UpdatePropertyByReference

                  Updating featureByRef with a feature object I just retrieved, update a field and subsequently use feature.changes doesn't work. In fact, if I retrieve a feature from HS and I inspect the property "Changes", it pretty much shows all attributes as "changed". I'm only assuming what this property "changes" is supposed to do, but retrieving it from HS seems to SET all attributes of the instantiated object as "changed" and therefore if you now use it to do an UpdateFeatureByRef and use feature.changes in many cases it will fail because not all properties can be changed that way.

                  Comment


                    #10
                    Originally posted by stefxx View Post
                    If seems to happen when I update several devices quickly after each other. If I update the hsfeature first, it seems to work. Like this:

                    feature.Status = "Whatever"
                    UpdatePropertyByRef(feature.ref, EProperty.Status, "Whatever")

                    If this remains stable, I leave it for now until someone from HomeSeer gives us a better way.
                    Stef,

                    Did you try as I did? First use the UpdatePropertyByRef, then reread the feature with GetFeatureByRef. This should get you the just updated Feature. What you were doing is adding an update to the changes object, like Dirk was mentioning. And indeed, this is just as buggy as UpdateFeatureByRef , throwing very vague errors that does not explain anything.

                    Wim
                    -- Wim

                    Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
                    650 devices ---- 336 events ----- 40 scripts

                    Comment


                      #11
                      Again, thank for the help! Here is some code from my plugin to test/replicate the issue. As I copied some stuff and put everything in 1 sub it might not be the best or most optimized code, but it does show the issue. Perhaps you can copy this in your plugin and run the "Test" sub?

                      Code:
                          Sub test()
                      
                              ' Create the device
                              Dim df As DeviceFactory = DeviceFactory.CreateDevice(PI_Id)
                              df.WithName("Device")
                              df.AsType(Identification.EDeviceType.Generic, 0)
                              Dim ndd As NewDeviceData = df.PrepareForHs()
                              Dim dv As HsDevice = GetDeviceByRef(hs.CreateDevice(ndd))
                              dv.Interface() = PI_Id
                              dv.Address() = "Device"
                              hs.UpdateDeviceByRef(dv.Ref, dv.Changes)
                      
                              ' Create some features
                              For i = 1 To 5
                                  Dim ff As FeatureFactory = FeatureFactory.CreateFeature(PI_Id)
                                  ff.WithName("Feature " & i)
                                  ff.WithLocation(dv.Location)
                                  ff.WithLocation2(dv.Location2)
                                  ff.AsType(Identification.EFeatureType.Generic, 0)
                                  Dim nfd As NewFeatureData = ff.PrepareForHsDevice(dv.Ref)
                                  Dim dvf As HsFeature = hs.GetFeatureByRef(hs.CreateFeatureForDevice(nfd))
                                  hs.UpdatePropertyByRef(dvf.Ref, EProperty.Interface, PI_Id)
                                  hs.UpdatePropertyByRef(dvf.Ref, EProperty.Address, "Feature" & i)
                                  ' Add Graphics range
                                  Dim StatusGraphic As StatusGraphic = New StatusGraphic("/images/HomeSeer/status/nostatus.gif", 0)
                                  StatusGraphic.IsRange = True
                                  StatusGraphic.RangeMin = 0
                                  StatusGraphic.RangeMax = 10
                                  hs.AddStatusGraphicToFeature(dvf.Ref, StatusGraphic)
                              Next
                      
                              ' Update features
                              For i = 1 To 5
                                  Dim dvf As HsFeature = hs.GetFeatureByAddress("Feature" & i)
                                  hs.UpdateFeatureValueByRef(dvf.Ref, i) ' This works fine
                                  hs.UpdatePropertyByRef(dvf.Ref, EProperty.Status, "New status " & i) ' This does not work except for the last feature
                                  dvf = hs.GetFeatureByRef(dvf.Ref) ' rereading the hsfeature doesn't seem to have any effect
                                  'hs.UpdateFeatureByRef(dvf.Ref, dvf.Changes) ' NO VERSION error
                              Next
                      
                          End Sub
                      This is the result. Only the status of the last feature is saved.

                      Click image for larger version

Name:	Annotation 2020-03-21 051656.png
Views:	186
Size:	80.4 KB
ID:	1371586

                      BTW, I know that when I use UpdateFeatureStatusByRef instead it will work, but then the issue persists for other properties.
                      stefxx

                      Comment

                      Working...
                      X