Skip to content

Commit

Permalink
more settings
Browse files Browse the repository at this point in the history
  • Loading branch information
DTTerastar committed Dec 31, 2024
1 parent 276ccea commit 8554bd6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/Models/NodeSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

Expand All @@ -11,10 +11,24 @@ public class NodeSettings(string id)
[StringLength(64)]
public string? Id { get; set; } = id;

[JsonPropertyName("updating")]
[JsonProperty("updating")]
public UpdatingSettings Updating { get; set; } = new UpdatingSettings();

[JsonPropertyName("scanning")]
[JsonProperty("scanning")]
public ScanningSettings Scanning { get; set; } = new ScanningSettings();

[JsonPropertyName("counting")]
[JsonProperty("counting")]
public CountingSettings Counting { get; set; } = new CountingSettings();

[JsonPropertyName("filtering")]
[JsonProperty("filtering")]
public FilteringSettings Filtering { get; set; } = new FilteringSettings();

[JsonPropertyName("calibration")]
[JsonProperty("calibration")]
public CalibrationSettings Calibration { get; set; } = new CalibrationSettings();

public NodeSettings Clone()
Expand Down
85 changes: 81 additions & 4 deletions src/Services/NodeSettingsStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using ESPresense.Models;

namespace ESPresense.Services
Expand All @@ -15,6 +15,40 @@ public NodeSettings Get(string id)
public async Task Set(string id, NodeSettings ds)
{
var old = Get(id);

// Updating settings
if (ds.Updating.AutoUpdate == null || ds.Updating.AutoUpdate != old.Updating.AutoUpdate)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/auto_update/set", $"{ds.Updating.AutoUpdate}");
if (ds.Updating.PreRelease == null || ds.Updating.PreRelease != old.Updating.PreRelease)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/pre_release/set", $"{ds.Updating.PreRelease}");

// Scanning settings
if (ds.Scanning.ForgetAfterMs == null || ds.Scanning.ForgetAfterMs != old.Scanning.ForgetAfterMs)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/forget_after_ms/set", $"{ds.Scanning.ForgetAfterMs}");

// Counting settings
if (ds.Counting.IdPrefixes == null || ds.Counting.IdPrefixes != old.Counting.IdPrefixes)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/id_prefixes/set", $"{ds.Counting.IdPrefixes}");
if (ds.Counting.StartCountingDistance == null || ds.Counting.StartCountingDistance != old.Counting.StartCountingDistance)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/start_counting_distance/set", $"{ds.Counting.StartCountingDistance:0.00}");
if (ds.Counting.StopCountingDistance == null || ds.Counting.StopCountingDistance != old.Counting.StopCountingDistance)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/stop_counting_distance/set", $"{ds.Counting.StopCountingDistance:0.00}");
if (ds.Counting.IncludeDevicesAge == null || ds.Counting.IncludeDevicesAge != old.Counting.IncludeDevicesAge)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/include_devices_age/set", $"{ds.Counting.IncludeDevicesAge}");

// Filtering settings
if (ds.Filtering.IncludeIds == null || ds.Filtering.IncludeIds != old.Filtering.IncludeIds)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/include_ids/set", $"{ds.Filtering.IncludeIds}");
if (ds.Filtering.ExcludeIds == null || ds.Filtering.ExcludeIds != old.Filtering.ExcludeIds)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/exclude_ids/set", $"{ds.Filtering.ExcludeIds}");
if (ds.Filtering.MaxDistance == null || ds.Filtering.MaxDistance != old.Filtering.MaxDistance)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/max_distance/set", $"{ds.Filtering.MaxDistance:0.00}");
if (ds.Filtering.EarlyReportDistance == null || ds.Filtering.EarlyReportDistance != old.Filtering.EarlyReportDistance)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/early_report_distance/set", $"{ds.Filtering.EarlyReportDistance:0.00}");
if (ds.Filtering.SkipReportAge == null || ds.Filtering.SkipReportAge != old.Filtering.SkipReportAge)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/skip_report_age/set", $"{ds.Filtering.SkipReportAge}");

// Calibration settings
if (ds.Calibration.Absorption == null || ds.Calibration.Absorption != old.Calibration.Absorption)
await mqtt.EnqueueAsync($"espresense/rooms/{id}/absorption/set", $"{ds.Calibration.Absorption:0.00}");
if (ds.Calibration.RxAdjRssi == null || ds.Calibration.RxAdjRssi != old.Calibration.RxAdjRssi)
Expand All @@ -32,6 +66,51 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
var ns = Get(arg.NodeId);

Check warning on line 66 in src/Services/NodeSettingsStore.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'id' in 'NodeSettings NodeSettingsStore.Get(string id)'.
switch (arg.Setting)
{
// Updating settings
case "auto_update":
ns.Updating.AutoUpdate = bool.Parse(arg.Payload);
break;
case "pre_release":
ns.Updating.PreRelease = bool.Parse(arg.Payload);
break;

// Scanning settings
case "forget_after_ms":
ns.Scanning.ForgetAfterMs = int.Parse(arg.Payload);
break;

// Counting settings
case "id_prefixes":
ns.Counting.IdPrefixes = arg.Payload;
break;
case "start_counting_distance":
ns.Counting.StartCountingDistance = double.Parse(arg.Payload);
break;
case "stop_counting_distance":
ns.Counting.StopCountingDistance = double.Parse(arg.Payload);
break;
case "include_devices_age":
ns.Counting.IncludeDevicesAge = int.Parse(arg.Payload);
break;

// Filtering settings
case "include_ids":
ns.Filtering.IncludeIds = arg.Payload;
break;
case "exclude_ids":
ns.Filtering.ExcludeIds = arg.Payload;
break;
case "max_distance":
ns.Filtering.MaxDistance = double.Parse(arg.Payload);
break;
case "early_report_distance":
ns.Filtering.EarlyReportDistance = double.Parse(arg.Payload);
break;
case "skip_report_age":
ns.Filtering.SkipReportAge = int.Parse(arg.Payload);
break;

// Calibration settings
case "absorption":
ns.Calibration.Absorption = double.Parse(arg.Payload);
break;
Expand All @@ -41,9 +120,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
case "tx_ref_rssi":
ns.Calibration.TxRefRssi = int.Parse(arg.Payload);
break;
case "max_distance":
ns.Filtering.MaxDistance = double.Parse(arg.Payload);
break;

default:
return Task.CompletedTask;
}
Expand Down

0 comments on commit 8554bd6

Please sign in to comment.