Skip to content

Commit f961985

Browse files
committed
Roku: Basic command test
1 parent 9198dc8 commit f961985

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

modConverse.vb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ Module modConverse
531531
Case "notifications"
532532
modMail.Send("Test Notification", "Test Notification")
533533
strCommandResponse = "Acknowledged"
534+
Case "roku"
535+
strCommandResponse = modRoku.SimpleRokuCommand("family room roku", "Home")
534536
Case "syncmesg"
535537
modSync.SendMessage(inputData(2), "message", "hello!")
536538
strCommandResponse = "Acknowledged"

modRoku.vb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Public Module modRoku
1616

1717
Function AddRokuDeviceDb(ByVal strAddress As String, ByVal strFriendlyName As String, ByVal strModel As String) As String
1818
If CheckDbForRoku(strModel) = 0 Then
19-
modDatabase.Execute("INSERT INTO DEVICES (Name, Type, Model, Location, Address) VALUES('" & strFriendlyName & " Roku', 'Roku', '" & strModel & "', '" & strFriendlyName & "', '" & strAddress & "')")
19+
modDatabase.Execute("INSERT INTO DEVICES (Name, Type, Model, Location, Address) VALUES('" & strFriendlyName.ToLower() & " roku', 'Roku', '" & strModel & "', '" & strFriendlyName & "', '" & strAddress & "')")
2020
Return "Device added"
2121
Else
2222
modDatabase.Execute("UPDATE DEVICES SET Address = """ & strAddress & """ WHERE Type = ""Roku"" AND Model = """ & strModel & """")
@@ -36,4 +36,34 @@ Public Module modRoku
3636
Return 0
3737
End If
3838
End Function
39+
40+
''' <summary>
41+
''' This function returns the address of a given Roku.
42+
''' </summary>
43+
''' <param name="strNickname">Nickname of device to look for</param>
44+
''' <returns>Roku API address</returns>
45+
Function GetRokuAddressFromNickname(ByVal strNickname) As String
46+
Dim result As String = ""
47+
48+
modDatabase.ExecuteReader("SELECT Address FROM DEVICES WHERE Name = '" + strNickname + "' AND Type = 'Roku'", result)
49+
Return result
50+
End Function
51+
52+
Function SimpleRokuCommand(ByVal strNickname As String, ByVal strCommand As String) As String
53+
Try
54+
Dim strAddress As String = GetRokuAddressFromNickname(strNickname)
55+
Dim RokuCmdRequest As System.Net.HttpWebRequest = System.Net.WebRequest.Create(strAddress & "keypress/" & strCommand)
56+
RokuCmdRequest.Method = "POST"
57+
RokuCmdRequest.GetResponse()
58+
Return "Command Sent"
59+
Catch WebEx As System.Net.WebException
60+
If WebEx.Status = Net.WebExceptionStatus.ProtocolError Then
61+
Dim response As System.Net.HttpWebResponse = TryCast(WebEx.Response, System.Net.HttpWebResponse)
62+
If response.StatusCode = System.Net.HttpStatusCode.Forbidden Then
63+
Return "Roku control by apps is disabled"
64+
End If
65+
End If
66+
Return "Unknown error"
67+
End Try
68+
End Function
3969
End Module

0 commit comments

Comments
 (0)