Vi er vel bang smack on topic.
Jeg hadde delt det opp i forskjellige klasser for å håndtere det, men det er SetIOMulti() som håndterer alle knappetrykker på devicer som tilhører plugin'en.
Du får sendt en deviceRef og en kommando, og bruker da dette videre. Hvordan du håndterer det er opp til deg. Her er SetIOMulti() fra TibberSeer:
Mye av teksten ligger i MoskusSample...
Public Sub SetIOMulti(ByVal colSend As List(Of HomeSeerAPI.CAPI.CAPIControl))
'Multiple CAPIcontrols might be sent at the same time, so we need to check each one
For Each CC In colSend
Log("SetIOMulti triggered, checking CAPI '" & CC.Label & "' on device " & CC.Ref, LogType.Debug)
'CAPI doesn't magically store the new devicevalue, and I believe there's good reason for that:
' The status of the device migth depend on some hardware giving the response that it has received the command,
' and perhaps with an other value (indicating a status equal to "Error" or whatever). In that case; send the command,
' wait for the answer (in a new thread) and THEN update the device value
'But here, we just update the value for the device
hs.SetDeviceValueByRef(CC.Ref, CC.ControlValue, False)
'Get the device sending the CAPIcontrol
Dim device As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(CC.Ref)
Select Case device.DeviceType_Get(hs).Device_SubType_Description.ToLower
Case "root_price"
Log("Pressing update on price root...", LogType.Debug)
Dim ref As Integer = CC.Ref
Dim t As New Thread(AddressOf UpdateTibberData)
t.Start(ref)
Case "root_consumption"
Log("Pressing update on consumption root...", LogType.Debug)
Dim ref As Integer = CC.Ref
Dim t As New Thread(AddressOf UpdateTibberData)
t.Start(ref)
Case "root_realtime"
Log("Pressing restart on realtime root...", LogType.Debug)
Dim ref As Integer = CC.Ref
RestartRealtime(ref)
End Select
Next
End Sub
Her fra TrådfriSeer:
Public Sub SetIOMulti(ByVal colSend As List(Of HomeSeerAPI.CAPI.CAPIControl))
'Multiple CAPIcontrols might be sent at the same time, so we need to check each one
For Each CC In colSend
Log("SetIOMulti triggered, checking CAPI '" & CC.Label & "' on device " & CC.Ref, LogType.Debug)
'Get the device sending the CAPIcontrol
Dim device As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(CC.Ref)
Select Case GetTypeFromDevice(device)
Case "Hub"
'There's nothing here
Case "Bulb"
Dim b As TrådfriBulb = (From bs In Trådfri.Bulbs Where bs.MainDeviceRef = CC.Ref).FirstOrDefault
If b IsNot Nothing Then
b.SetDimLevelAsync(CC.ControlValue)
End If
Case "Group"
Dim g As TrådfriGroup = (From bs In Trådfri.Groups Where bs.MainDeviceRef = CC.Ref).FirstOrDefault
If g IsNot Nothing Then
g.SetDimLevelAsync(CC.ControlValue)
End If
Case "Scene"
Dim g As TrådfriGroup = (From bs In Trådfri.Groups Where bs.SceneDeviceRef = CC.Ref).FirstOrDefault
If g IsNot Nothing Then
g.SetSceneAsync(CC.ControlValue)
End If
Case "ColorTemperature"
Dim b As TrådfriBulb = (From bs In Trådfri.Bulbs Where bs.TemperatureDeviceRef = CC.Ref).FirstOrDefault
If b IsNot Nothing Then
b.SetColorAsync(CC.ControlValue)
End If
Case "TransitionTime"
hs.SetDeviceValueByRef(CC.Ref, Math.Round(CC.ControlValue, 1), True)
End Select
Next
End Sub