I've seen several examples, but none of them have fully answered all my questions, and Lord knows the documentation has ZERO descriptive value, so I've just finished my attempt at the "CreateParent" and "CreateChild" functions from my Tesla plugin. Here's what I have right now:
From what I can tell, the idea is to use FeatureFactory to setup the basic device in memory, then use "PrepareForHS" to explode that shell out into a NewDeviceData object with even more details, then once you've set all the properties you want, you use "HomeseerSystem.CreateDevice(<NewDeviceData thing you got earlier>)". (And then substitute "Device" for "Feature" and use "HomeseerSystem.CreateFeatureForDevice" instead for children).
My main question is: is this the way it's supposed to be done?
Also:
I'm sure I'll have more, since the doc is SO bad (did I mention that?) and since the examples I've seen weren't nearly as robust as what I used to do with my plugins anyway, and I'm sure others used similar stuff...
Code:
'Setup Parent dfParent = New DeviceFactory() With dfParent .WithName(Me.VehicleName) If g_blnLocation2 And g_blnLocation1First Then .WithLocation("Vehicles") .WithLocation2(Me.VehicleName) Else If g_blnLocation2 Then .WithLocation2("Vehicles") .WithLocation(Me.VehicleName) End If .WithMiscFlags(EMiscFlag.ShowValues) End With objType = New Identification.TypeInfo() objType.ApiType = EApiType.Device objType.SubTypeDescription = ChildCategory.Tesla_Vehicle.ToString.Replace("_", " ") 'TODO: NOT SURE WHAT THIS IS OR HOW TO USE IT 'objType.SubType = 1 'set all the new device properties objParentData = dfParent.PrepareForHs() With objParentData Me.ParentRef = .Device(EProperty.Ref) .Device(EProperty.Relationship) = ERelationship.Device .Device(EProperty.CanDim) = False .Device(EProperty.DeviceType) = EDeviceType.Generic .Device(EProperty.Address) = Me.VehicleID .Device(EProperty.Interface) = HSPI.Id .Device(EProperty.LastChange) = Date.Now .Device(EProperty.Value) = m_intUNKNOWN_VALUE .Device(EProperty.DeviceType) = objType 'TODO: NOT SURE WHAT THIS IS FOR OR HOW TO RECREATE IT 'devParent.Status_Support = True End With 'now create the device Me.ParentRef = hs.CreateDevice(objParentData)
Code:
'set up the feature ffChild = FeatureFactory.CreateFeature(HSPI.Id, Me.ParentRef) With ffChild .WithName(strChildName) .WithDefaultValue(m_intUNKNOWN_VALUE) .WithLocation(devParent.Location) .WithLocation2(devParent.Location2) .WithMiscFlags(EMiscFlag.ShowValues) objPED = New PlugExtraData() objPED.AddNamed("ChildType", enmChildType) .WithExtraData(objPED) End With objType = New Identification.TypeInfo() objType.ApiType = EApiType.Feature objType.SubTypeDescription = enmChildCategory.ToString().Replace("_", " ") 'TODO: NOT SURE WHAT THIS IS OR HOW TO USE IT 'objType.SubType = 1 objChildData = ffChild.PrepareForHsDevice(devParent.Ref) With objChildData .Feature(EProperty.Interface) = HSPI.Id .Feature(EProperty.Relationship) = ERelationship.Feature .Feature(EProperty.CanDim) = False .Feature(EProperty.LastChange) = DateTime.Now 'TODO: NOT SURE WHAT THIS IS FOR OR HOW TO RECREATE IT 'devChild.Status_Support = False End With intRef = hs.CreateFeatureForDevice(objChildData)
My main question is: is this the way it's supposed to be done?
Also:
- What are the possible values for "SubType" - why isn't this an enum?
- What about the old "AssociatedDevice_Add" methods? I assume they're not needed since devices and features seem to be inherently related - you pass the ref of your parent in to the featurefactory (right?) so this shouldn't be needed, but the NewFeatureData still has an EProperty of AssociatedDevices, but I have no idea when/why I would use that.
- The "SaveEventsDevices" method isn't there - can I assume I don't need this? (not sure I ever did, but whenever I created a device, I used it...)
I'm sure I'll have more, since the doc is SO bad (did I mention that?) and since the examples I've seen weren't nearly as robust as what I used to do with my plugins anyway, and I'm sure others used similar stuff...
Comment