Skip to content

Conversation

@novalegra
Copy link
Collaborator

@novalegra novalegra commented Oct 22, 2020

Currently, overrides aren't visible to Siri (meaning they can't be set with Shortcuts or via voice). There also isn't a great way to view the override history in Loop; the issue report does contain the history, but it's not in a very human-readable format.

This PR:

  1. adds a Siri extension & the ability to use overrides with Siri/Shortcuts
  2. adds an override history screen
  3. makes some under-the-hood improvements to override accounting in order to correctly determine the end date of an override

Some notes about the overrides with Siri implementation:

  • I used UserDefaults so the extension could communicate with the main Loop app; the main app has a key-value observer that will watch for changes to set the appropriate override. One issue with this is that the KVO doesn't happen when Loop is in the background, so I changed the intent handler to always .continueInApp so the override will be set. Open to other ways to do this if there's something that could set the override in the background
  • I chose to use an extension so it'd be easier to expand Loop's Siri capabilities in the future

LoopKit PR: LoopKit/LoopKit#343
NightscoutService PR: ps2/NightscoutService#4


import Foundation

struct IntentExtensionInfo: RawRepresentable {
Copy link
Collaborator Author

@novalegra novalegra Oct 22, 2020

Choose a reason for hiding this comment

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

I created IntentExtensionInfo so it would be easier to pass data between the intent extension and the main app in the event someone wanted to add other things to Loop's Siri capabilities

}

func handle(intent: EnableOverridePresetIntent, completion: @escaping (EnableOverridePresetIntentResponse) -> Void) {
guard let defaults = self.defaults, let overrideName = intent.overrideName?.lowercased(), containsOverrideName(name: overrideName) else {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My (pretty simple) implementation to set overrides just looks for the preset's name (and lowercases the names when comparing to avoid capitalization-related difficulties). This will fail to distinguish between overrides if they have the same name but different capitalization.

currentEffectiveOverride = scheduleOverride
case (let preMealOverride?, let scheduleOverride?):
currentEffectiveOverride = preMealOverride.endDate > Date()
currentEffectiveOverride = preMealOverride.scheduledEndDate > Date()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a rename that I made on the LoopKit level

@novalegra novalegra marked this pull request as ready for review October 22, 2020 21:27
@ps2
Copy link
Collaborator

ps2 commented Nov 16, 2020

In the project file, PRODUCT_BUNDLE_IDENTIFIER = "com..loopkit.Loop.Loop-Intent-Extension"; needs to change to use the MAIN_APP_BUNDLE_IDENTIFIER. Something like this: PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).Loop-Intent-Extension";

@ps2 ps2 merged commit 2f675c0 into LoopKit:dev Nov 27, 2020
@novalegra novalegra deleted the novalegra/overrides-siri branch December 29, 2020 20:03
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