Objective is to reassign a feature from Device 1 to Device 2 and since Device 1 no longer has any features then Device 1 is deleted.
What now happens in 4.2.8.0 is that Device 2 does not hold onto the updated association property unless Device 2 is not deleted in the code sequence following the remapping of associations.
It behaves as if the association is being updated in a different thread and when that thread runs it observes that the feature no longer exists because Device 1 has been deleted. The feature object has been lost so cannot be part of Device 2 associations.
Code sequence to showing the issue
Dim parentList As New Generic.List(Of Integer)
parentList.Add(iRef)
'give parent the child list
hs.UpdatePropertyByRef(iRef, HomeSeer.PluginSdk.Devices.EProperty.AssociatedDevices, childList)
hs.UpdatePropertyByRef(iRef, HomeSeer.PluginSdk.Devices.EProperty.Relationship, HomeSeer.PluginSdk.Devices.Identification.ERelationship.Device)
'clean up old associations
For Each iChildRef As Integer In childList
Dim oldList As Generic.HashSet(Of Integer) = hs.GetPropertyByRef(iChildRef, HomeSeer.PluginSdk.Devices.EProperty.AssociatedDevices)
Dim iOldParent As Integer = -1
For Each ioldRef As Integer In oldList
iOldParent = ioldRef
Exit For
Next
If iRef <> iOldParent Then
hs.UpdatePropertyByRef(iChildRef, HomeSeer.PluginSdk.Devices.EProperty.AssociatedDevices, parentList)
hs.UpdatePropertyByRef(iChildRef, HomeSeer.PluginSdk.Devices.EProperty.Relationship, HomeSeer.PluginSdk.Devices.Identification.ERelationship.Feature)
'remove the reassigned child from the old parent
Dim oChildList As Generic.HashSet(Of Integer) = hs.GetPropertyByRef(iOldParent, HomeSeer.PluginSdk.Devices.EProperty.AssociatedDevices)
If oChildList.Contains(iChildRef) Then
oChildList.Remove(iChildRef)
End If
'If oChildList.Count = 0 Then
'hs.DeleteDevice(iOldParent) 'Feature is lost when parent is deleted
'Else
hs.UpdatePropertyByRef(iOldParent, HomeSeer.PluginSdk.Devices.EProperty.AssociatedDevices, oChildList)
hs.UpdatePropertyByRef(iOldParent, HomeSeer.PluginSdk.Devices.EProperty.Relationship, HomeSeer.PluginSdk.Devices.Identification.ERelationship.Device)
'End If
End If
Next
This issue can be closed. It appears that updating the Associations in the parent device before deleting the parent device will overcome the issue reported.
HS4 4.2.8.0
Objective is to reassign a feature from Device 1 to Device 2 and since Device 1 no longer has any features then Device 1 is deleted.
What now happens in 4.2.8.0 is that Device 2 does not hold onto the updated association property unless Device 2 is not deleted in the code sequence following the remapping of associations.
It behaves as if the association is being updated in a different thread and when that thread runs it observes that the feature no longer exists because Device 1 has been deleted. The feature object has been lost so cannot be part of Device 2 associations.
Code sequence to showing the issue