Sesch69 / LovenseBSControl

Beat Saber Mod to use toys from the Lovense company
GNU General Public License v3.0
17 stars 8 forks source link

Check for "OK" in new Lovense Connect API #10

Open jabberrock opened 3 months ago

jabberrock commented 3 months ago

The current Lovense Connect API has been updated to use OK.

{
  "code" : 200,
  "data" : {
    "881a1435c5b5" : {
      "name" : "Edge",
      "nickName" : "",
      "fVersion" : "243",
      "version" : "2",
      "status" : "1",
      "battery" : 42,
      "id" : "..."
    }
  },
  "type" : "OK"
}

To fix it, use case-insensitive compare:

diff --git a/LovenseBSControl/Classes/Request.cs b/LovenseBSControl/Classes/Request.cs
index 7292345..b2e29ab 100644
--- a/LovenseBSControl/Classes/Request.cs
+++ b/LovenseBSControl/Classes/Request.cs
@@ -31,7 +31,7 @@ namespace LovenseBSControl.Classes
                     }
                     var responseString = await client.GetStringAsync(connection.Value.CreateBaseUrl() + "/GetToys");
                     JObject toysString = JObject.Parse(responseString);
-                    if (!toysString["type"].ToString().Equals("ok"))
+                    if (!toysString["type"].ToString().Equals("ok", StringComparison.OrdinalIgnoreCase))
                     {
                         Plugin.Log.Info("Lovense Connect not active/running for connection: " + connection.Key);
                         continue;
@@ -75,7 +75,7 @@ namespace LovenseBSControl.Classes
                     var responseString = await client.GetStringAsync(connection.Value.CreateBaseUrl() + "/Battery?t=" + toy.GetId());
                     JObject toysString = JObject.Parse(responseString);

-                    if (!toysString["type"].ToString().Equals("ok"))
+                    if (!toysString["type"].ToString().Equals("ok", StringComparison.OrdinalIgnoreCase))
                     {
                         Plugin.Log.Info("Lovense Connect not active/running.");
                     }