From 8335149f57a9ba3774c9cb3718e67d0fe13f9479 Mon Sep 17 00:00:00 2001 From: HeavenVR Date: Fri, 3 Jul 2026 11:03:50 +0200 Subject: [PATCH 1/3] feat: emit DeviceUpdateType.Paired when a device consumes a pair code Add a Paired value to DeviceUpdateType and emit it to the device owner after a pair code is consumed, so clients are notified when a device pairs. --- API/Controller/Device/Pair.cs | 8 +++++--- API/Controller/Device/_ApiController.cs | 5 ++++- Common/Models/DeviceUpdateType.cs | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/API/Controller/Device/Pair.cs b/API/Controller/Device/Pair.cs index 7b04ad77..c8f2fe37 100644 --- a/API/Controller/Device/Pair.cs +++ b/API/Controller/Device/Pair.cs @@ -54,9 +54,11 @@ private async Task PairInternal(string pairCode) if (pair is null) return Problem(PairError.PairCodeNotFound); await devicePairs.DeleteAsync(pair); - var deviceToken = await _db.Devices.Where(x => x.Id == pair.Id).Select(x => x.Token).FirstOrDefaultAsync(); - if (deviceToken is null) throw new Exception("Device not found for pair code"); + var device = await _db.Devices.Where(x => x.Id == pair.Id).Select(x => new { x.Token, x.OwnerId }).FirstOrDefaultAsync(); + if (device is null) throw new Exception("Device not found for pair code"); - return LegacyDataOk(deviceToken); + await _deviceUpdateService.UpdateDevice(device.OwnerId, pair.Id, DeviceUpdateType.Paired); + + return LegacyDataOk(device.Token); } } \ No newline at end of file diff --git a/API/Controller/Device/_ApiController.cs b/API/Controller/Device/_ApiController.cs index 74c7a249..270b6a40 100644 --- a/API/Controller/Device/_ApiController.cs +++ b/API/Controller/Device/_ApiController.cs @@ -1,6 +1,7 @@ using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using OpenShock.API.Services.DeviceUpdate; using OpenShock.Common; using OpenShock.Common.Authentication; using OpenShock.Common.OpenShockDb; @@ -21,12 +22,14 @@ public sealed partial class DeviceController : OpenShockControllerBase { private readonly OpenShockContext _db; private readonly IRedisConnectionProvider _redis; + private readonly IDeviceUpdateService _deviceUpdateService; private readonly ILogger _logger; - public DeviceController(OpenShockContext db, IRedisConnectionProvider redis, ILogger logger) + public DeviceController(OpenShockContext db, IRedisConnectionProvider redis, IDeviceUpdateService deviceUpdateService, ILogger logger) { _db = db; _redis = redis; + _deviceUpdateService = deviceUpdateService; _logger = logger; } } \ No newline at end of file diff --git a/Common/Models/DeviceUpdateType.cs b/Common/Models/DeviceUpdateType.cs index 9b5f337f..f2e77ddf 100644 --- a/Common/Models/DeviceUpdateType.cs +++ b/Common/Models/DeviceUpdateType.cs @@ -5,6 +5,6 @@ public enum DeviceUpdateType Created, // Whenever a new device is created Updated, // Whenever name or something else directly related to the device is updated ShockerUpdated, // Whenever a shocker is updated, name or limits for a person - Deleted // Whenever a device is deleted - + Deleted, // Whenever a device is deleted + Paired // Whenever a device consumes a pair code } \ No newline at end of file From 754c6caa3b4912a9b34f85b7a04bebb4be9c87fa Mon Sep 17 00:00:00 2001 From: HeavenVR Date: Fri, 3 Jul 2026 12:05:07 +0200 Subject: [PATCH 2/3] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- API/Controller/Device/Pair.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/API/Controller/Device/Pair.cs b/API/Controller/Device/Pair.cs index c8f2fe37..54ef98a3 100644 --- a/API/Controller/Device/Pair.cs +++ b/API/Controller/Device/Pair.cs @@ -57,8 +57,15 @@ private async Task PairInternal(string pairCode) var device = await _db.Devices.Where(x => x.Id == pair.Id).Select(x => new { x.Token, x.OwnerId }).FirstOrDefaultAsync(); if (device is null) throw new Exception("Device not found for pair code"); - await _deviceUpdateService.UpdateDevice(device.OwnerId, pair.Id, DeviceUpdateType.Paired); +try +{ + await _deviceUpdateService.UpdateDevice(device.OwnerId, pair.Id, DeviceUpdateType.Paired); +} +catch (Exception ex) +{ + _logger.LogWarning(ex, "Failed to emit paired update for device {DeviceId}", pair.Id); +} - return LegacyDataOk(device.Token); +return LegacyDataOk(device.Token); } } \ No newline at end of file From b221847d27bfdefc9773939be9b2ecee118ba364 Mon Sep 17 00:00:00 2001 From: HeavenVR Date: Fri, 3 Jul 2026 12:13:21 +0200 Subject: [PATCH 3/3] fix whitespaces --- API/Controller/Device/Pair.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/API/Controller/Device/Pair.cs b/API/Controller/Device/Pair.cs index 54ef98a3..061f9ebe 100644 --- a/API/Controller/Device/Pair.cs +++ b/API/Controller/Device/Pair.cs @@ -57,15 +57,15 @@ private async Task PairInternal(string pairCode) var device = await _db.Devices.Where(x => x.Id == pair.Id).Select(x => new { x.Token, x.OwnerId }).FirstOrDefaultAsync(); if (device is null) throw new Exception("Device not found for pair code"); -try -{ - await _deviceUpdateService.UpdateDevice(device.OwnerId, pair.Id, DeviceUpdateType.Paired); -} -catch (Exception ex) -{ - _logger.LogWarning(ex, "Failed to emit paired update for device {DeviceId}", pair.Id); -} + try + { + await _deviceUpdateService.UpdateDevice(device.OwnerId, pair.Id, DeviceUpdateType.Paired); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Failed to emit paired update for device {DeviceId}", pair.Id); + } -return LegacyDataOk(device.Token); + return LegacyDataOk(device.Token); } -} \ No newline at end of file +}