Description
I've created some code (links below) to allow Loop to receive temporary BG correction targets remotely (from nightscout, though using IFTTT etc is fine) using Loop's override functionality for glucose targets. Instead of writing over user created preMeal and workout ranges, I created a new override called remoteTempTarget. It functions in the same way. I am very new to Swift, Xcode and Loop and Im far from a professional programmer so I'm sure this will need quite a lot of code review from the experts here, if the community wants such a feature in the first place. This opens up the usual security issues, but as far as I know no one has had any negative situations on the openAPS side which has this same feature. I think this feature will be particularly useful for those with small kids in a variety of situations, and for those of us who simply want to set some new targets remotely (ie not getting out of bed) if our PWD is trending high or low and we want to increase or decrease insulin for a period of time via changing the target. Again, the community obviously needs to decide if we want to open the door to allowing remote commands to be sent. So Ill put the idea out there for debate and discussion.
I've been running it for a few days now and @Kdisimone has tried it as well. Ive been setting temp targets via NightScout and so far so good. Im 100% sure the code could be cleaner and Im wide open to advice and criticism as Im using this to learn Loop. This same idea of course can be applied to other remote commands, but I think this one is the most basic.
Right now the code ignores the "type" of override sent from NS - eating soon etc - any Temporary Target events that are sent to Treatments are applied to remoteTempTarget and do not overwrite preMeal or workout, but that was just my thought. The requirements on this also need a lot of input from the community. This is a first cut.
https://github.com/kenstack/Loop/tree/nstemptarget
https://github.com/kenstack/LoopKit/tree/nstemptarget
if you want to try it you need to update carthage as there are a few small changes to loopkit which I couldn't figure out how to avoid - see #3 below - Im hopeful someone can point me in the right direction on how to keep all the changes in loop. The cartfile should point correctly to my github branch but let me know if there are issues.
There are some issues Id like to discuss if people are interested in the feature
-
I could not find a clean way to set the ranges of an override - I can set duration, etc but I could not set the range without editing the "rawValues" directly. Im guessing either I missed how to do this with the available methods or its probably better to create an extension to do this cleanly. I tried the latter but failed...
-
Once an override expires, ie duration has ended, the UI doesn't remove the blue bar. The actual correction target returns to normal (so the math is fine), but until the code does a clearOverride the blue bar remains. I tried hard to follow this but I couldnt figure out how the charts know the override has expired. Im happy to investigate this but I probably need some direction.
-
I had to add the new override in loopkit because I couldnt figure out how to do an extension in Loop, which is clearly a cleaner way to do it to avoid loopkit / carthage issues, but like above I failed (though I tried a few times..). If this is indeed possible and anyone can spend a few minutes pointing me in the right direction it would be much appreciated.
-
I struggled to decide where to call this functionality from. At the moment its in device manager and its called every time you loop (so once every 5 min) but Im wide open to moving it and if there is a more appropriate way/time/place to call it please suggest it.
Thanks to @Kdisimone for testing and lots of input and help with getting to know Loop and github. Thanks for reading :)