HomeSeer / Plugin-SDK

Plugin development kit for the 4th major edition of the HomeSeer platform.
https://www.nuget.org/packages/HomeSeer-PluginSDK/
GNU Affero General Public License v3.0
20 stars 4 forks source link

Devices created in HS3 do not return DeviceType property in HS4 #48

Closed mcsSolutions closed 4 years ago

mcsSolutions commented 4 years ago

The objective is to determine if a device created in HS3 is a parent or child. The Child/Parent property of HS3 is not longer available and this information is now in DeviceType in HS4. When DeviceType is viewed in HS4 for a device created in HS3, the Api field is not populated. This is expected to contain info as to it being a child or parent. The function below illustrates with some lines commented out because of the HS4 issue reading HS3-created devices.

Public Function GetDeviceRefWithFeature(ByVal iFeatureRef As Integer) As Integer
    Dim iList As HashSet(Of Integer) = hs.GetPropertyByRef(iFeatureRef, Devices.EProperty.AssociatedDevices)
    If iList.Count > 0 Then 
        For Each iRef As Integer In iList 'need to assume it is a parent type because HS3 created associations do not have Api property set
            'Dim DeviceType As HomeSeer.PluginSdk.Devices.Identification.TypeInfo = hs.GetPropertyByRef(iRef, Devices.EProperty.DeviceType)
            'If DeviceType.ApiType = Devices.Identification.EApiType.Device Then
            Return iRef
            'End If
        Next
    End If
    Return -1
End Function
jldubz commented 4 years ago

To determine if a device is a parent or a child call hs.IsRefDevice()

Parents are devices, and children are features. I am going to close this issue as I believe that solves your objective, but I understand the depth of the reported issue.

You are correct that you will be unable to read the new DeviceType property as if it is an HS4 device when it was created using an HS3 plugin. We may implement a way to go between the two type definitions in the near future, but, as of right now, there are no plans to change this.

Is there a specific reason why you are seeking to analyze whether an item is a device or a feature this way as opposed to using the Relationship property?

mcsSolutions commented 4 years ago

Using IsRefDevice() is an acceptable means to achieve the desired objective. For what I see now there is no other reason to need a bridge for ApiType.