diff --git a/CShocker/Shockers/APIS/OpenShockSerial.cs b/CShocker/Shockers/APIS/OpenShockSerial.cs index 38f1b13..756fd4b 100644 --- a/CShocker/Shockers/APIS/OpenShockSerial.cs +++ b/CShocker/Shockers/APIS/OpenShockSerial.cs @@ -7,6 +7,7 @@ namespace CShocker.Shockers.APIS; public class OpenShockSerial : SerialShocker { + // ReSharper disable once MemberCanBePrivate.Global external usage public readonly Dictionary Model; private const int BaudRate = 115200; public OpenShockSerial(Dictionary shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, ILogger? logger = null) : base(shockerIds.Keys.ToList(), intensityRange, durationRange, serialPortI, BaudRate, ShockerApi.OpenShockSerial, logger) @@ -23,7 +24,7 @@ public class OpenShockSerial : SerialShocker $"\"intensity\":{intensity}," + $"\"durationMs\":{duration}" + "}"; - serialPort.WriteLine(json); + SerialPort.WriteLine(json); } public Dictionary GetShockers() @@ -31,8 +32,8 @@ public class OpenShockSerial : SerialShocker Dictionary ret = new(); Regex shockerRex = new (@".*FetchDeviceInfo\(\): \[GatewayConnectionManager\] \[[a-z0-9\-]+\] rf=([0-9]{1,5}) model=([0,1])"); this.Logger?.Log(LogLevel.Debug, "Restart"); - serialPort.WriteLine("restart"); - while (serialPort.ReadLine() is { } line && !line.Contains("Successfully verified auth token")) + SerialPort.WriteLine("restart"); + while (SerialPort.ReadLine() is { } line && !line.Contains("Successfully verified auth token")) { this.Logger?.Log(LogLevel.Trace, line); Match match = shockerRex.Match(line); @@ -50,7 +51,7 @@ public class OpenShockSerial : SerialShocker Petrainer = 1 } - private string ControlActionToString(ControlAction action) + private static string ControlActionToString(ControlAction action) { return action switch { diff --git a/CShocker/Shockers/APIS/PiShockHttp.cs b/CShocker/Shockers/APIS/PiShockHttp.cs index 214b62a..766d09c 100644 --- a/CShocker/Shockers/APIS/PiShockHttp.cs +++ b/CShocker/Shockers/APIS/PiShockHttp.cs @@ -8,7 +8,9 @@ namespace CShocker.Shockers.APIS; public class PiShockHttp : HttpShocker { - public String Username, ShareCode; + // ReSharper disable twice MemberCanBePrivate.Global external usage + public readonly string Username, ShareCode; + public PiShockHttp(List shockerIds, IntensityRange intensityRange, DurationRange durationRange, string apiKey, string username, string shareCode, string endpoint = "https://do.pishock.com/api/apioperate", ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiKey, endpoint, ShockerApi.PiShockHttp, logger) { this.Username = username; diff --git a/CShocker/Shockers/APIS/PiShockSerial.cs b/CShocker/Shockers/APIS/PiShockSerial.cs index 1ac4fd3..ad95012 100644 --- a/CShocker/Shockers/APIS/PiShockSerial.cs +++ b/CShocker/Shockers/APIS/PiShockSerial.cs @@ -23,7 +23,7 @@ public class PiShockSerial : SerialShocker $"\"id\": " + "}" + "}"; - serialPort.WriteLine(json); + SerialPort.WriteLine(json); } private static string ControlActionToOp(ControlAction action) diff --git a/CShocker/Shockers/Abstract/HttpShocker.cs b/CShocker/Shockers/Abstract/HttpShocker.cs index 9de0d14..0df4535 100644 --- a/CShocker/Shockers/Abstract/HttpShocker.cs +++ b/CShocker/Shockers/Abstract/HttpShocker.cs @@ -6,6 +6,7 @@ namespace CShocker.Shockers.Abstract; public abstract class HttpShocker : Shocker { protected readonly HttpClient HttpClient = new(); + // ReSharper disable twice MemberCanBeProtected.Global external usage public string Endpoint { get; init; } public string ApiKey { get; init; } diff --git a/CShocker/Shockers/Abstract/SerialShocker.cs b/CShocker/Shockers/Abstract/SerialShocker.cs index b7e44c3..6eb0e18 100644 --- a/CShocker/Shockers/Abstract/SerialShocker.cs +++ b/CShocker/Shockers/Abstract/SerialShocker.cs @@ -10,13 +10,13 @@ namespace CShocker.Shockers.Abstract; public abstract class SerialShocker : Shocker { public SerialPortInfo SerialPortI; - protected SerialPort serialPort; + protected readonly SerialPort SerialPort; protected SerialShocker(List shockerIds, IntensityRange intensityRange, DurationRange durationRange, SerialPortInfo serialPortI, int baudRate, ShockerApi apiType, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiType, logger) { this.SerialPortI = serialPortI; - this.serialPort = new SerialPort(serialPortI.PortName, baudRate); - this.serialPort.Open(); + this.SerialPort = new SerialPort(serialPortI.PortName, baudRate); + this.SerialPort.Open(); } [SupportedOSPlatform("windows")] diff --git a/CShocker/Shockers/Abstract/Shocker.cs b/CShocker/Shockers/Abstract/Shocker.cs index 7dad3bb..7d86b00 100644 --- a/CShocker/Shockers/Abstract/Shocker.cs +++ b/CShocker/Shockers/Abstract/Shocker.cs @@ -6,6 +6,7 @@ namespace CShocker.Shockers.Abstract; public abstract class Shocker { + // ReSharper disable 4 times MemberCanBePrivate.Global external use public readonly List ShockerIds; public readonly IntensityRange IntensityRange; public readonly DurationRange DurationRange;