Originally posted by Rick Tinker
View Post
I'll do a second posting on a "status device" with a picture of how it renders
PHP Code:
Private Function SonosCreatePlayerDevice(ByVal HSRef As Integer, ByVal ZoneName As String, ZoneModel As String, NewDevice As Boolean) As Integer
SonosCreatePlayerDevice = -1
Dim dv As Scheduler.Classes.DeviceClass
Dim DevName As String = ZoneName & " - Player"
Dim dvParent As Scheduler.Classes.DeviceClass = Nothing
Try
If HSRef = -1 Then
HSRef = hs.NewDeviceRef(DevName)
Log("SonosCreatePlayerDevice: Created device " & DevName & " with reference " & HSRef.ToString & " and ZoneModel = " & ZoneModel, LogType.LOG_TYPE_INFO)
' Force HomeSeer to save changes to devices and events so we can find our new device
hs.SaveEventsDevices()
End If
dv = hs.GetDeviceByRef(HSRef)
dv.Interface(hs) = tIFACE_NAME
If NewDevice Then
dv.Location(hs) = "Sonos" 'IFACE_NAME
dv.Location2(hs) = ZoneName 'IFACE_NAME & InstanceFriendlyName.ToString
dv.Device_Type_String(hs) = SonosHSDevices.Player.ToString
dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
dv.Can_Dim(hs) = False
dv.Image(hs) = ""
dv.Buttons(hs) = ""
dv.OLD_Values(hs) = ""
Dim DT As New DeviceTypeInfo
DT.Device_API = DeviceTypeInfo.eDeviceAPI.Media
DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Root
DT.Device_SubType_Description = "Sonos Player Master Control"
dv.DeviceType_Set(hs) = DT
dv.Status_Support(hs) = True
hs.SetDeviceString(HSRef, "", False)
' This device is a child device, the parent being the root device for the entire security system.
' As such, this device needs to be associated with the root (Parent) device.
dvParent = hs.GetDeviceByRef(MasterHSDeviceRef)
If dvParent.AssociatedDevices_Count(hs) < 1 Then
' There are none added, so it is OK to add this one.
dvParent.AssociatedDevice_Add(hs, HSRef)
Else
Dim Found As Boolean = False
For Each ref As Integer In dvParent.AssociatedDevices(hs)
If ref = HSRef Then
Found = True
Exit For
End If
Next
If Not Found Then
dvParent.AssociatedDevice_Add(hs, HSRef)
Else
' This is an error condition likely as this device's reference ID should not already be associated.
End If
End If
' Now, we want to make sure our child device also reflects the relationship by adding the parent to
' the child's associations.
dv.AssociatedDevice_ClearAll(hs) ' There can be only one parent, so make sure by wiping these out.
dv.AssociatedDevice_Add(hs, dvParent.Ref(hs))
hs.DeviceVSP_ClearAll(HSRef, True)
End If
hs.DeviceVSP_ClearAll(HSRef, True)
Dim ValuePairs As Integer = hs.DeviceVGP_Count(HSRef)
Log("Test in SonosCreatePlayerDevice counting value/graphics pairs. Count = " & ValuePairs.ToString, LogType.LOG_TYPE_INFO)
hs.DeviceVGP_ClearAll(HSRef, True)
Dim Pair As VSPair
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 1
Pair.Status = "Play"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 0
Pair.ButtonRender_Column = 0
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 2
Pair.Status = "Stop"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 0
Pair.ButtonRender_Column = 1
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 3
Pair.Status = "Pause"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 0
Pair.ButtonRender_Column = 2
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 5
Pair.Status = "Prev"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 0
Pair.ButtonRender_Column = 3
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 4
Pair.Status = "Next"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 0
Pair.ButtonRender_Column = 4
hs.DeviceVSP_AddPair(HSRef, Pair)
If ZoneModel.ToUpper = "WD100" Then
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 6
Pair.Status = "BuildDB"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 0
Pair.ButtonRender_Column = 5
hs.DeviceVSP_AddPair(HSRef, Pair)
End If
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 7
Pair.Status = "Shuffle"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 1
Pair.ButtonRender_Column = 0
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 8
Pair.Status = "Repeat"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 1
Pair.ButtonRender_Column = 1
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 9
Pair.Status = "Up"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 2
Pair.ButtonRender_Column = 0
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 10
Pair.Status = "Dn"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 2
Pair.ButtonRender_Column = 1
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 11
Pair.Status = "Mute"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 2
Pair.ButtonRender_Column = 2
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 12
Pair.Status = "Left"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 2
Pair.ButtonRender_Column = 3
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 13
Pair.Status = "Right"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 2
Pair.ButtonRender_Column = 4
hs.DeviceVSP_AddPair(HSRef, Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
Pair.PairType = VSVGPairType.SingleValue
'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
Pair.Value = 14
Pair.Status = "Loudness"
Pair.Render = VSVGPairRender.Button
Pair.ButtonRender_Row = 2
Pair.ButtonRender_Column = 5
hs.DeviceVSP_AddPair(HSRef, Pair)
Return HSRef
Catch ex As Exception
Log("Error in SonosCreatePlayerDevice with Error = " & ex.Message, LogType.LOG_TYPE_ERROR)
End Try
End Function
Comment