@@ -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
3969End Module
0 commit comments