mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-01 01:25:38 -05:00
Add alerts when devices reconnect after stopping
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -0,0 +1,6 @@
|
||||
UPDATE
|
||||
device
|
||||
SET
|
||||
stopped_reporting = @StoppedReporting
|
||||
WHERE
|
||||
name = @Name;
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE
|
||||
device
|
||||
ADD COLUMN
|
||||
stopped_reporting boolean NOT NULL DEFAULT false;
|
||||
Reference in New Issue
Block a user