Skip to content

Remote PR Set #3#41

Merged
ps2 merged 19 commits into
ps2:devfrom
gestrich:feature/2023/06/bg/remote-command-service-refactor
Jul 2, 2023
Merged

Remote PR Set #3#41
ps2 merged 19 commits into
ps2:devfrom
gestrich:feature/2023/06/bg/remote-command-service-refactor

Conversation

@gestrich

@gestrich gestrich commented Jun 13, 2023

Copy link
Copy Markdown

This is part of a collection of foundational PRs that need to merge at the same time.

Loop
LoopKit
NightscoutService
TidepoolService

Comment thread NightscoutServiceKit/NightscoutService.swift
Comment thread NightscoutServiceKit/NightscoutService.swift
Comment thread NightscoutServiceKit/RemoteCommands/Actions/Action.swift
@@ -0,0 +1,18 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

@@ -0,0 +1,186 @@
//

@gestrich gestrich Jun 16, 2023

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

This class still needs some work.

@@ -0,0 +1,53 @@
//

@gestrich gestrich Jun 16, 2023

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

Actually this is a hack I just use personally. This was how I used to use the override system to control Loop settings.

@gestrich gestrich force-pushed the feature/2023/06/bg/remote-command-service-refactor branch 2 times, most recently from 808e0ff to a9ac5a8 Compare June 17, 2023 15:52
@@ -59,6 +60,7 @@ public final class NightscoutService: Service {
}

private let commandSourceV1: RemoteCommandSourceV1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

All the commandSourceV2 will be removed.

let commandSource = try commandSource(notification: notification)
await commandSource.handleRemoteNotification(notification)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

}

}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A delegate for the command source V1 (pre Remote 2.0 source). It really just handles incoming push notifications.

try await self.serviceDelegate?.handleRemoteClosedLoop(activate: closedLoopComand.active)
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will upload the NS note. A screenshot of the result is in the main Loop PR.


let notificationJSON = try JSONSerialization.data(withJSONObject: notification)
let notificationJSONString = String(data: notificationJSON, encoding: .utf8) ?? ""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON is included in the note which may not be desired. I added it just in case we want to use that JSON in Caregiver for the interim (rather than users needing to look in NS), while the Remote 2.0 pieces are being worked out.

@gestrich gestrich force-pushed the feature/2023/06/bg/remote-command-service-refactor branch from a9ac5a8 to 2313dec Compare June 17, 2023 16:39
@@ -254,7 +254,7 @@ public class OTPManager {
dateFormatter.dateFormat = "h:mm"
return String(format: "Error: Password sent at %@ has expired. Only the last %u passwords are accepted. See LoopDocs for troubleshooting.", dateFormatter.string(from: deliveryDate), maxOTPsToAccept)
} else {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed an unused parameter here.

@@ -0,0 +1,18 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

@@ -0,0 +1,18 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from LoopKit

@@ -0,0 +1,24 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from LoopKit

@@ -0,0 +1,23 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from LoopKit

@@ -0,0 +1,19 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from LoopKit

@@ -1,36 +0,0 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the refactor, now there are the following objects:

V1 (Loop now): RemoteNotification: An incoming push notification.
V2 (remote 2.0): NSRemoteCommandPayload: Payload for a incoming push notification and also when making REST calls to NS for pending commands

Both V1 and V2 will use the same Actions which are above.

public let remoteAddress: String
public let expiration: Date?
public let sentAt: Date?
public let otp: String

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we were missing the enteredBy field which may be helpful to leverage.

case expiration = "expiration"
case sentAt = "sent-at"
case otp = "otp"
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer converting to NightscoutRemoteCommand since that was eliminated.

func toRemoteAction() -> Action {
return .bolusEntry(BolusAction(amountInUnits: amount))
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validate method on each notification will do both the OTP validation, if required, and validate the expiration date.

@@ -19,6 +19,7 @@ public struct CarbRemoteNotification: RemoteNotification, Codable {
public let expiration: Date?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same pattern in these classes as BolusRemoteNotification above.

let action = OverrideCancelAction(remoteAddress: remoteAddress)
return .cancelTemporaryOverride(action)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No OTP validation needed for overrides so there is where we omit that.

@@ -7,15 +7,19 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used for Remote 1.0 (Loop today). It represents the payload for an incoming push notification.

@@ -0,0 +1,41 @@
//

@gestrich gestrich Jun 17, 2023

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2 commands sources, for Remote 1.0 vs Remote 2.0, allow us to support both paradigms simultaneously

@@ -0,0 +1,47 @@
//

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOTE 2.0: WILL REMOVE PRE-MERGE

@gestrich gestrich marked this pull request as ready for review June 17, 2023 16:54
@ps2

ps2 commented Jun 18, 2023

Copy link
Copy Markdown
Owner

Probably beyond the scope of this PR, but this does make me think Loop should probably have a RemoteCommsLog, similar to the DeviceCommsLog.

@gestrich gestrich force-pushed the feature/2023/06/bg/remote-command-service-refactor branch from 2313dec to bc282c0 Compare June 19, 2023 09:33
public let sentAt: Date?
public let otp: String
public let otp: String?
public let enteredBy: String?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer to "who sent this command?" should ideally be determined by knowing which OTP code was matched, and showing the Loop user a name that the Loop user entered for that OTP pairing when the authorization was initially created.

So when Riley shares her Loop data with me, she puts in "Dad", and then the qrcode is shown and associated with "Dad". I pair that in LCG and when a remote bolus is received by Loop, if it matches my OTP, then Riley gets a notification that "Dad" sent a bolus command.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it's possible for caregivers to spoof.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense. This is currently a field in NS but we could eliminate field someday with the support you mentioned. I'm actually not using this field here at the moment but just noticed it was part of the payload.

@ps2 ps2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ps2 ps2 merged commit 7021c9b into ps2:dev Jul 2, 2023
ps2 added a commit to LoopKit/NightscoutService that referenced this pull request Oct 5, 2024
loopkitdev pushed a commit to loopkitdev/NightscoutService that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants