From 8554bd6a71bea2a9df87698ee533847fc95ef06c Mon Sep 17 00:00:00 2001 From: DTTerastar Date: Mon, 30 Dec 2024 19:45:47 -0500 Subject: [PATCH] more settings --- src/Models/NodeSettings.cs | 16 +++++- src/Services/NodeSettingsStore.cs | 85 +++++++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 5 deletions(-) diff --git a/src/Models/NodeSettings.cs b/src/Models/NodeSettings.cs index 4b101b97..3b8c16ab 100644 --- a/src/Models/NodeSettings.cs +++ b/src/Models/NodeSettings.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using Newtonsoft.Json; @@ -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() diff --git a/src/Services/NodeSettingsStore.cs b/src/Services/NodeSettingsStore.cs index e17c3ca3..38c0593b 100644 --- a/src/Services/NodeSettingsStore.cs +++ b/src/Services/NodeSettingsStore.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using ESPresense.Models; namespace ESPresense.Services @@ -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) @@ -32,6 +66,51 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) var ns = Get(arg.NodeId); 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; @@ -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; }