JsonSerializer

This commit is contained in:
2024-01-17 22:16:40 +01:00
parent 66ffd99ae5
commit d9b7b09978
13 changed files with 87 additions and 24 deletions

View File

@ -9,7 +9,7 @@ public abstract class HttpShocker : Shocker
public string Endpoint { get; init; }
public string ApiKey { get; init; }
protected HttpShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, string endpoint, string apiKey, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
protected HttpShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, string endpoint, string apiKey, ShockerApi apiType, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiType, logger)
{
Endpoint = endpoint;
ApiKey = apiKey;

View File

@ -5,7 +5,7 @@ namespace CShocker.Shockers.Abstract;
public abstract class SerialShocker : Shocker
{
protected SerialShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
protected SerialShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ShockerApi apiType, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, apiType, logger)
{
}
}

View File

@ -1,4 +1,5 @@
using CShocker.Ranges;
using System.Reflection.Metadata;
using CShocker.Ranges;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers.Abstract;
@ -9,6 +10,7 @@ public abstract class Shocker
public readonly IntensityRange IntensityRange;
public readonly DurationRange DurationRange;
protected ILogger? Logger;
public readonly ShockerApi ApiType;
public void Control(ControlAction action, string? shockerId = null, int? intensity = null, int? duration = null)
{
@ -26,11 +28,12 @@ public abstract class Shocker
protected abstract void ControlInternal(ControlAction action, string shockerId, int intensity, int duration);
protected Shocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null)
protected Shocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ShockerApi apiType, ILogger? logger = null)
{
this.ShockerIds = shockerIds;
this.IntensityRange = intensityRange;
this.DurationRange = durationRange;
this.ApiType = apiType;
this.Logger = logger;
}

View File

@ -0,0 +1,9 @@
namespace CShocker.Shockers.Abstract;
public enum ShockerApi
{
OpenShockHttp = 0,
OpenShockSerial = 1,
PiShockHttp = 2,
PiShockSerial = 3
}