Fix: Delete Glucose entries in Nightscout API#980
Fix: Delete Glucose entries in Nightscout API#980ryceg wants to merge 9 commits intonightscout:devfrom
Conversation
|
@kristinkand this PR should fix deletions of manual glucose readings of NS. Tbf, I'm not entirely sure if that was actually broken before. What is still "missing" is deletion of normal readings ( I believe adding the following snippet to func deleteGlucose(withId id: String) async throws {
var components = URLComponents()
components.scheme = url.scheme
components.host = url.host
components.port = url.port
components.path = "/api/v1/entries/"
components.queryItems = [
URLQueryItem(name: "find[_id][$eq]", value: id)
]
guard let url = components.url else {
throw URLError(.badURL)
}
var request = URLRequest(url: url)
request.allowsConstrainedNetworkAccess = false
request.timeoutInterval = Config.timeout
request.httpMethod = "DELETE"
if let secret = secret {
request.addValue(secret.sha1(), forHTTPHeaderField: "api-secret")
}
let (_, response) = try await URLSession.shared.data(for: request)
guard let httpResponse = response as? HTTPURLResponse, (200 ... 299).contains(httpResponse.statusCode) else {
throw URLError(.badServerResponse)
}
debugPrint("Delete glucose from NS successful for entry with ID \(id)")
}and this snippet to func deleteGlucose(withID id: String) async {
guard let nightscout = nightscoutAPI, isUploadEnabled else { return }
do {
try await nightscout.deleteGlucose(withId: id)
} catch {
debug(
.nightscout,
"\(DebuggingIdentifiers.failed) Failed to delete CGM Glucose Reading from Nightscout with error: \(error.localizedDescription)"
)
}
}plus adding as well as these changes to the func deleteGlucoseFromNightscout(withID id: String) {
Task.detached { [weak self] in
guard let self = self else { return }
await self.nightscoutManager.deleteGlucose(withID: id)
}
}
// add to protocol pattern
func deleteGlucoseFromNightscout(withID id: String)In // Delete from Nightscout
if let id = glucoseToDelete.id?.uuidString {
self.provider.deleteGlucoseFromNightscout(withID: id)
self.provider.deleteManualGlucoseFromNightscout(withID: id)
}should probably solve this :) If you feel confident giving this a try, please do. Edit to fix |
|
I rebuild successfully after editing the different files. However the red dot of the manual bg is still there. |
|
One more comment: After the helpful hand from @dnzxy , I reverted the first two commits @ryceg , but left in place all the "snippets" as posted by @dnzxy . Now when I delete a manual bg in Trio, it's being deleted from NS too (refresh NS or wait for a loop). |
|
I attempted to build after your last commits @ryceg However every build comes back with two errors: missing url path to submodule..xdrip and something about homebrew. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
I built again, now it builds successfully after the removal of the submodule. However the normal bg values are still not deleted from NS. If I build without @dnzxy's suggestions, nothing is being deleted neither manual nor normal bg values. |
|
Has anyone been able to test this since the last changes? |
This PR amends the Nightscout API to correctly target the entries collection, and uses the
_idfor discrimination since Trio's glucose entries have an_idinstead of anid