Skip to content

Commit

Permalink
Merge pull request #683 from hello/jimmy/fixes
Browse files Browse the repository at this point in the history
Fix issue where voice tutorial stops polling after error
  • Loading branch information
jimmymlu authored Sep 26, 2016
2 parents 5f1711b + bc0baa8 commit a6d8984
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.5.3.9

Fixes:

* Fix voice tutorial so it continues to poll after an error

## 1.5.3.8

New:
Expand Down
2 changes: 1 addition & 1 deletion Extensions/RoomConditions/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.5.3.8</string>
<string>1.5.3.9</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
Expand Down
1 change: 0 additions & 1 deletion SleepModel/HEMDeviceService.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
NSString* const HEMDeviceServiceErrorDomain = @"is.hello.app.service.device";

static NSInteger const HEMPillDfuPillMinimumRSSI = -70;
static NSString* const HEMPillDfuBinURL = @"https://s3.amazonaws.com/hello-firmware/kodobannin/mobile/pill.hex";
static NSString* const HEMPillDfuPrefLastUpdate = @"HEMPillDfuPrefLastUpdate";
static NSUInteger const HEMPillDfuSuppressionReq = 2; // will not show dfu updates if done within the hour
static CGFloat const HEMPillDfuMinPhoneBattery = 0.2f;
Expand Down
2 changes: 1 addition & 1 deletion SleepModel/HEMRoomConditionsPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ - (void)configureSensorCell:(HEMSensorCollectionViewCell*)sensorCell forSensor:(
[[sensorCell descriptionLabel] setText:[sensor localizedMessage]];
[[sensorCell nameLabel] setText:[[sensor localizedName] uppercaseString]];

CGFloat minValue = MAX(0.0f, [chartView chartYMin]);
CGFloat minValue = [chartView chartYMin];
CGFloat maxValue = [chartView chartYMax];
[[self formatter] setIncludeUnitSymbol:YES];

Expand Down
28 changes: 23 additions & 5 deletions SleepModel/HEMSensorDetailPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ @interface HEMSensorDetailPresenter() <
@property (nonatomic, weak) HEMSensorValueCollectionViewCell* valueCell;
@property (nonatomic, assign) SENSensorType type;

@property (nonatomic, assign) CGFloat chartMinValue;
@property (nonatomic, assign) CGFloat chartMaxValue;

@end

@implementation HEMSensorDetailPresenter
Expand All @@ -75,6 +78,8 @@ - (instancetype)initWithSensorService:(HEMSensorService*)sensorService
_sensorService = sensorService;
_sensor = sensor;
_type = [sensor type];
_chartMinValue = MAXFLOAT;
_chartMaxValue = 0.0f;
_xAxisLabelFormatter = [NSDateFormatter new];
_exactTimeFormatter = [NSDateFormatter new];
_formatter = [[HEMSensorValueFormatter alloc] initWithSensorUnit:[sensor unit]];
Expand Down Expand Up @@ -225,6 +230,15 @@ - (void)prepareChartDataAndReload {
[labelData addObject:[[strongSelf xAxisLabelFormatter]
stringFromDate:[time date]]];
}

if (entryValue < [strongSelf chartMinValue]) {
[strongSelf setChartMinValue:entryValue];
}

if (entryValue > [strongSelf chartMaxValue]) {
[strongSelf setChartMaxValue:entryValue];
}

index++;
}
[strongSelf setChartData:chartData];
Expand All @@ -242,6 +256,8 @@ - (void)clearData {
[self setSensorData:nil];
[self setXLabelData:nil];
[self setStatus:nil];
[self setChartMaxValue:0.0f];
[self setChartMinValue:MAXFLOAT];
}

- (void)setPollScope:(HEMSensorServiceScope)scope {
Expand Down Expand Up @@ -367,7 +383,6 @@ - (LineChartView*)chartViewForSensor:(SENSensor*)sensor
LineChartView* lineChartView = (id) [[cell chartContentView] chartView];
if (!lineChartView) {
lineChartView = [[LineChartView alloc] initForSensorWithFrame:[[cell chartContentView] bounds]];
[lineChartView setHighlightPerDragEnabled:NO];
}

NSArray *gradientColors = [lineChartView gradientColorsWithColor:sensorColor];
Expand Down Expand Up @@ -453,13 +468,16 @@ - (void)configureChartCell:(HEMSensorChartCollectionViewCell*)chartCell {
[[[chartCell chartContentView] botLimitLabel] setText:nil];
} else {
chartView = [self chartViewForSensor:[self sensor] inCell:chartCell];
CGFloat minValue = MAX(0.0f, [chartView chartYMin]);
CGFloat maxValue = [chartView chartYMax];
[chartContainer showLoadingActivity:NO];
[[chartContainer noDataLabel] setHidden:YES];
[chartContainer setChartView:chartView];
[[chartContainer topLimitLabel] setText:[[self formatter] stringFromSensorValue:@(maxValue)]];
[[chartContainer botLimitLabel] setText:[[self formatter] stringFromSensorValue:@(minValue)]];

NSNumber* minValue = @([chartView chartYMin]);
NSNumber* maxValue = @([chartView chartYMax]);
NSString* minText = [[self formatter] stringFromSensorValue:minValue];
NSString* maxText = [[self formatter] stringFromSensorValue:maxValue];
[[chartContainer topLimitLabel] setText:maxText];
[[chartContainer botLimitLabel] setText:minText];

if (![self chartLoaded] && [[self chartData] count] > 0) {
[chartView animateIn];
Expand Down
14 changes: 14 additions & 0 deletions SleepModel/HEMVoiceService.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ typedef void(^HEMVoiceCommandsHandler)(NSArray<SENSpeechResult*>* _Nullable resu
@interface HEMVoiceService()

@property (nonatomic, assign, getter=isStarted) BOOL started;
@property (nonatomic, assign, getter=isInProgress) BOOL inProgress;
@property (nonatomic, strong) NSDate* lastVoiceResultDate;

@end

@implementation HEMVoiceService

- (instancetype)init {
self = [super init];
if (self) {
_lastVoiceResultDate = [NSDate date];
}
return self;
}

- (void)mostRecentVoiceCommands:(HEMVoiceCommandsHandler)completion {
[SENAPISpeech getRecentVoiceCommands:^(id data, NSError *error) {
if (error) {
Expand All @@ -45,7 +54,11 @@ - (void)startListeningForVoiceResult {
}

- (void)waitForVoiceCommandResult {
if ([self isInProgress]) {
return;
}
__weak typeof(self) weakSelf = self;
[self setInProgress:YES];
[self mostRecentVoiceCommands:^(NSArray<SENSpeechResult *> * results, NSError * error) {
__strong typeof(weakSelf) strongself = weakSelf;
NSDictionary* info = nil;
Expand All @@ -72,6 +85,7 @@ - (void)waitForVoiceCommandResult {
int64_t delay = (int64_t)(HEMVoiceServiceWaitDelay * NSEC_PER_SEC);
dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delay);
dispatch_after(delayTime, dispatch_get_main_queue(), ^{
[strongself setInProgress:NO];
if ([strongself isStarted]) {
[strongself waitForVoiceCommandResult];
}
Expand Down
18 changes: 14 additions & 4 deletions SleepModel/HEMVoiceTutorialPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ @interface HEMVoiceTutorialPresenter()
@property (nonatomic, assign) NSInteger failures;

@property (nonatomic, weak) HEMVoiceService* voiceService;
@property (nonatomic, assign, getter=hasStoppedListening) BOOL stopListening;
@property (nonatomic, assign, getter=isInfoShowing) BOOL infoShowing;

@end

Expand Down Expand Up @@ -297,6 +297,7 @@ - (void)voiceInfo {
[sheet setOptionTextAlignment:NSTextAlignmentCenter];
[sheet addDismissAction:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf setInfoShowing:NO];
[strongSelf listenForVoiceResult];
}];
[sheet addOptionWithTitle:cancelOption
Expand All @@ -305,10 +306,12 @@ - (void)voiceInfo {
imageName:nil
action:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf setInfoShowing:NO];
[strongSelf listenForVoiceResult];
}];

[self stopListeningForVoiceResult];
[self setInfoShowing:YES];
[[self delegate] showController:sheet fromPresenter:self];
}

Expand Down Expand Up @@ -372,20 +375,27 @@ - (void)stopListeningForVoiceResult {
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:HEMVoiceNotification object:[self voiceService]];
[[self voiceService] stopListeningForVoiceResult];
[self setStopListening:YES];
}

- (void)listenForVoiceResult {
if ([self isInfoShowing]) {
[self stopListeningForVoiceResult];
return;
}

NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(didGetVoiceResult:)
name:HEMVoiceNotification
object:[self voiceService]];
[[self voiceService] startListeningForVoiceResult];
[self setStopListening:NO];
}

- (void)didGetVoiceResult:(NSNotification*)note {
if ([self isInfoShowing]) {
return;
}

SENSpeechResult* result = [note userInfo][HEMVoiceNotificationInfoResult];
if (result) {
NSDictionary* props = @{kHEManaltyicsEventPropStatus : @([result status])};
Expand Down Expand Up @@ -452,7 +462,7 @@ - (void)restartListeningForResponse {
__strong typeof(weakSelf) strongSelf = weakSelf;
if ([strongSelf failures] == HEMVoiceTutorialFailureBeforeTip) {
[strongSelf voiceInfo];
} else if (![strongSelf hasStoppedListening]){
} else {
[strongSelf listenForVoiceResult];
}
});
Expand Down
2 changes: 1 addition & 1 deletion SleepModel/Sense-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.5.3.8</string>
<string>1.5.3.9</string>
<key>FacebookAppID</key>
<string>372438546161587</string>
<key>FacebookDisplayName</key>
Expand Down

0 comments on commit a6d8984

Please sign in to comment.