Skip to content

Remote PR Set #2: Introduce RemoteCommands#33

Merged
ps2 merged 3 commits into
ps2:devfrom
gestrich:feature/2023/02/bg/remote-command-service
Apr 21, 2023
Merged

Remote PR Set #2: Introduce RemoteCommands#33
ps2 merged 3 commits into
ps2:devfrom
gestrich:feature/2023/02/bg/remote-command-service

Conversation

@gestrich

@gestrich gestrich commented Feb 25, 2023

Copy link
Copy Markdown

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.

@gestrich gestrich force-pushed the feature/2023/02/bg/remote-command-service branch from b24744e to a2f0285 Compare March 11, 2023 10:43
@gestrich gestrich force-pushed the feature/2023/02/bg/remote-command-service branch from a2f0285 to cfd8ecd Compare March 11, 2023 15:03
}
return _uploader
}

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.

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)
}

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.

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
}

@gestrich gestrich Mar 11, 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.

This will be a case for commandSourceV2 in a future PR.

@@ -0,0 +1,28 @@
//

@gestrich gestrich Mar 11, 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.

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 @@
//

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 Nightscout's implementation of the RemoteCommand protocol. This will be used for both Remote 1.0 and Remote 2.0.

//

import LoopKit

@gestrich gestrich Mar 11, 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 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

@gestrich gestrich Mar 11, 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.

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 {

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.

Maintaining the existing behavior in Loop of making this optional.

@gestrich gestrich changed the title Remote 2: RemoteCommands in RemoteDataService Remote PR Set #2: RemoteCommands in RemoteDataService Mar 11, 2023
@gestrich gestrich force-pushed the feature/2023/02/bg/remote-command-service branch from cfd8ecd to 5f73e66 Compare March 11, 2023 15:35
@gestrich gestrich changed the title Remote PR Set #2: RemoteCommands in RemoteDataService Remote PR Set #2: Introduce RemoteCommands Mar 11, 2023
@gestrich gestrich marked this pull request as ready for review March 11, 2023 15:44
@gestrich gestrich force-pushed the feature/2023/02/bg/remote-command-service branch from 29375cd to 490cb6f Compare March 12, 2023 09:57
@@ -0,0 +1,45 @@
//

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.

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

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.

Common Protocol for the aforementioned Codable remote notifications.

}

extension RemoteNotification {

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 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> {

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 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.
//

@gestrich gestrich Mar 12, 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.

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 @@
//

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 tests in the next few files just take some data samples and ensures I can still create notifications from it.

@gestrich gestrich force-pushed the feature/2023/02/bg/remote-command-service branch from 70a8303 to 114046e Compare March 12, 2023 13:18
@ps2 ps2 merged commit 4c15d90 into ps2:dev Apr 21, 2023
ps2 added a commit to LoopKit/NightscoutService that referenced this pull request May 5, 2023
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