Add alerts when devices reconnect after stopping

This commit is contained in:
2025-10-20 19:08:21 -04:00
parent 98fa161eb1
commit 2f25286c21
10 changed files with 73 additions and 22 deletions

View File

@@ -100,12 +100,23 @@ public class Database(IConfiguration configuration)
return await connection.QueryFirstOrDefaultAsync<Device>(query, new { Name = deviceName }).ConfigureAwait(false);
}
public async Task SetDeviceLastUpdatedAsync(string deviceName, DateTimeOffset? lastUpdated)
public async Task<bool> SetDeviceLastUpdatedAsync(string deviceName, DateTimeOffset? lastUpdated)
{
await using var connection = CreateConnection();
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Environment.Service.Data.Queries.SetDeviceLastUpdated.psql");
await connection.ExecuteAsync(query, new { Name = deviceName, LastUpdated = lastUpdated }).ConfigureAwait(false);
var stoppedReporting = await connection.QueryFirstAsync<bool>(query, new { Name = deviceName, LastUpdated = lastUpdated }).ConfigureAwait(false);
return stoppedReporting;
}
public async Task SetDeviceStoppedReportingAsync(string deviceName, bool stoppedReporting)
{
await using var connection = CreateConnection();
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Environment.Service.Data.Queries.SetDeviceStoppedReporting.psql");
await connection.ExecuteAsync(query, new { Name = deviceName, StoppedReporting = stoppedReporting }).ConfigureAwait(false);
}
}

View File

@@ -1,11 +1,16 @@
INSERT INTO device(
name,
last_updated
last_updated,
stopped_reporting
)
VALUES (
@Name,
@LastUpdated
@LastUpdated,
false
)
ON CONFLICT (name)
DO UPDATE
SET last_updated = EXCLUDED.last_updated
SET last_updated = EXCLUDED.last_updated,
stopped_reporting = false
RETURNING
(SELECT stopped_reporting FROM device WHERE name = @Name);

View File

@@ -0,0 +1,6 @@
UPDATE
device
SET
stopped_reporting = @StoppedReporting
WHERE
name = @Name;

View File

@@ -0,0 +1,4 @@
ALTER TABLE
device
ADD COLUMN
stopped_reporting boolean NOT NULL DEFAULT false;