Remote PR Set #2: Introduce RemoteCommands#33
Conversation
b24744e to
a2f0285
Compare
a2f0285 to
cfd8ecd
Compare
| } | ||
| return _uploader | ||
| } | ||
|
|
There was a problem hiding this comment.
We will have 2 command sources eventually... One for Remote 1.0 and another for Remote 2.0. There will be different formats, validation mechanism and status reporting for each -- so it is nice to make dedicated classes for these types.
| @@ -331,25 +335,24 @@ extension NightscoutService: RemoteDataService { | |||
| uploader.uploadProfiles(stored.compactMap { $0.profileSet }, completion: completion) | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
When a Push Notification arrives, we will try to identify which source it was generated from. Then use that source to extract a RemoteCommand.
| enum NightscoutServiceRemoteCommandError: Error { | ||
| case missingCommandSource | ||
| } | ||
|
|
There was a problem hiding this comment.
This will be a case for commandSourceV2 in a future PR.
| @@ -0,0 +1,28 @@ | |||
| // | |||
There was a problem hiding this comment.
We need to translate between our Nightscout codable DTOs to RemoteCommand types that Loop can use. These extensions will provide the translation between these domains.
| @@ -0,0 +1,39 @@ | |||
| // | |||
There was a problem hiding this comment.
This is Nightscout's implementation of the RemoteCommand protocol. This will be used for both Remote 1.0 and Remote 2.0.
| // | ||
|
|
||
| import LoopKit | ||
|
|
There was a problem hiding this comment.
The source here will help us switch between Remote 1.0 and Remote 2.0 in the NightscoutService. This will get more methods in future PRs such as methods that fetch pending remote commands that we poll for.
|
|
||
|
|
||
| //MARK: RemoteCommandSource | ||
|
|
There was a problem hiding this comment.
I need a way to distinguish Remote 1. 0 and Remote 2.0 push notifications. I'm planning to add a "version" string to the push notification in Remote 2.0 which will unambiguously tell us which schema we have.
| } | ||
|
|
||
| func validate() throws { | ||
|
|
There was a problem hiding this comment.
Maintaining the existing behavior in Loop of making this optional.
cfd8ecd to
5f73e66
Compare
29375cd to
490cb6f
Compare
| @@ -0,0 +1,45 @@ | |||
| // | |||
There was a problem hiding this comment.
These are the Codable models used for Nightscout. They conform to the RemoteNotification protocol, a NightscoutServiceKit protocol, which allows for these notifications to convert to RemoteCommands, something Loop will be familiar with.
| // | ||
|
|
||
| import Foundation | ||
|
|
There was a problem hiding this comment.
Common Protocol for the aforementioned Codable remote notifications.
| } | ||
|
|
||
| extension RemoteNotification { | ||
|
|
There was a problem hiding this comment.
A unique id will be more useful with remote 2.0. For now, trying to extract something that helps with uniqueness for a remote 1.0 push notification.
| } | ||
|
|
||
| extension Dictionary<String, AnyObject> { | ||
|
|
There was a problem hiding this comment.
This pattern of checking certain keys to identify the push notification type, already happens in Loop now in a similar way. I'm just making a convenience method for that.
| // Created by Bill Gestrich on 2/25/23. | ||
| // Copyright © 2023 LoopKit Authors. All rights reserved. | ||
| // | ||
|
|
There was a problem hiding this comment.
A remote command may have multiple validators (ex: OTP, expiration, ...) And what we validate may vary by the command type. Wrapping each validation in a protocol makes the process a bit more flexible.
| @@ -0,0 +1,59 @@ | |||
| // | |||
There was a problem hiding this comment.
The tests in the next few files just take some data samples and ensures I can still create notifications from it.
70a8303 to
114046e
Compare
LOOP-4190 DIY Sync
This PR is part of the below set that should be merged together. This one will use "RemoteCommands", a protocol for interacting with the remote services that is the source of the RemoteCommand. This will lay the groundwork for remote 2.0 commands.