Skip to content

Commit

Permalink
Merge pull request #137 from SUPLA/develop
Browse files Browse the repository at this point in the history
v2.3.30
  • Loading branch information
przemyslawzygmunt authored Dec 21, 2020
2 parents 1ed0c40 + 6fd32c1 commit 2faf055
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 53 deletions.
24 changes: 18 additions & 6 deletions SUPLA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
019170A1233D4D5A00820BDB /* SADownloadThermostatMeasurements.m in Sources */ = {isa = PBXBuildFile; fileRef = 019170A0233D4D5A00820BDB /* SADownloadThermostatMeasurements.m */; };
019170A4233D67E900820BDB /* SAThermostatChartHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 019170A3233D67E900820BDB /* SAThermostatChartHelper.m */; };
01943EBE249D1C8800DA2B8F /* SASuperuserAuthorizationDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01943EC0249D1C8800DA2B8F /* SASuperuserAuthorizationDialog.xib */; };
0196E82A258CEEEC0016E8DC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0196E82C258CEEEC0016E8DC /* InfoPlist.strings */; };
01996AC1254B6B390034C6F1 /* z_wave_btn@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 01996AC0254B6B380034C6F1 /* z_wave_btn@2x.png */; };
019D22F0233CC2D000F17135 /* SAPreloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 019D22EF233CC2D000F17135 /* SAPreloader.m */; };
019F4CAC2354DC3300286139 /* ImpulseCounterDetailView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 019F4CAE2354DC3300286139 /* ImpulseCounterDetailView.xib */; };
Expand Down Expand Up @@ -595,6 +596,8 @@
019170A3233D67E900820BDB /* SAThermostatChartHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAThermostatChartHelper.m; sourceTree = "<group>"; };
01943EBF249D1C8800DA2B8F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/SASuperuserAuthorizationDialog.xib; sourceTree = "<group>"; };
01943EC2249D1C8D00DA2B8F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/SASuperuserAuthorizationDialog.strings; sourceTree = "<group>"; };
0196E81D258CD2480016E8DC /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/AddWizardVC.strings; sourceTree = "<group>"; };
0196E82B258CEEEC0016E8DC /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
01996AC0254B6B380034C6F1 /* z_wave_btn@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "z_wave_btn@2x.png"; path = "Resources/Assets/Img/z_wave_btn@2x.png"; sourceTree = "<group>"; };
019D22EE233CC2D000F17135 /* SAPreloader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SAPreloader.h; sourceTree = "<group>"; };
019D22EF233CC2D000F17135 /* SAPreloader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAPreloader.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -878,7 +881,6 @@
4077ACE220A21BB100BD2216 /* CreateAccountVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CreateAccountVC.xib; sourceTree = "<group>"; };
407D31921FD17C4B0062FB80 /* wifigeneral@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "wifigeneral@2x.png"; path = "Resources/Assets/Img/wifigeneral@2x.png"; sourceTree = "<group>"; };
407D31951FD1A7070062FB80 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/AddWizardVC.xib; sourceTree = "<group>"; };
407D31981FD1A70B0062FB80 /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/AddWizardVC.strings; sourceTree = "<group>"; };
407D319A1FD1A70D0062FB80 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/AddWizardVC.strings; sourceTree = "<group>"; };
407D319C1FD1A70F0062FB80 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/AddWizardVC.strings; sourceTree = "<group>"; };
407D319E1FD1A7110062FB80 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/AddWizardVC.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1720,6 +1722,7 @@
children = (
4031AD011BBC2A4900CF9D8B /* Assets */,
40DE1A421BCD6F06004CF43B /* Localizable.strings */,
0196E82C258CEEEC0016E8DC /* InfoPlist.strings */,
);
name = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -1964,6 +1967,7 @@
40B9ED481FACCE8700403B1A /* tv-on@3x.png in Resources */,
40B9ED501FACCF8100403B1A /* radio-off@3x.png in Resources */,
407D4AED1BC6C64D009A5505 /* app_icon120x120@3x.png in Resources */,
0196E82A258CEEEC0016E8DC /* InfoPlist.strings in Resources */,
40A87DDF1FADDFF900918B54 /* donate@2x.png in Resources */,
40CF96C21BC7D4E70030EFFF /* power-off@2x.png in Resources */,
40CF96BD1BC7D4E70030EFFF /* light-on@3x.png in Resources */,
Expand Down Expand Up @@ -2499,6 +2503,14 @@
name = SASuperuserAuthorizationDialog.xib;
sourceTree = "<group>";
};
0196E82C258CEEEC0016E8DC /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
0196E82B258CEEEC0016E8DC /* pl */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
019F4CAE2354DC3300286139 /* ImpulseCounterDetailView.xib */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -2591,7 +2603,6 @@
isa = PBXVariantGroup;
children = (
407D31951FD1A7070062FB80 /* Base */,
407D31981FD1A70B0062FB80 /* pl */,
407D319A1FD1A70D0062FB80 /* de */,
407D319C1FD1A70F0062FB80 /* ru */,
407D319E1FD1A7110062FB80 /* it */,
Expand All @@ -2605,6 +2616,7 @@
01BF82D72347569400C9EE9F /* nb */,
01BF82E0234756A000C9EE9F /* el */,
01BF82E9234756B600C9EE9F /* nl */,
0196E81D258CD2480016E8DC /* pl */,
);
name = AddWizardVC.xib;
sourceTree = "<group>";
Expand Down Expand Up @@ -2835,7 +2847,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = SUPLA/SUPLA.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 70;
CURRENT_PROJECT_VERSION = 78;
DEFINES_MODULE = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
Expand All @@ -2850,7 +2862,7 @@
"$(inherited)",
"$(PROJECT_DIR)/SUPLA/lib",
);
MARKETING_VERSION = 2.3.29;
MARKETING_VERSION = 2.3.30;
PRODUCT_BUNDLE_IDENTIFIER = com.acsoftware.ios.supla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SUPLA/SUPLA-Bridging-Header.h";
Expand All @@ -2868,7 +2880,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = SUPLA/SUPLA.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 70;
CURRENT_PROJECT_VERSION = 78;
DEFINES_MODULE = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
Expand All @@ -2883,7 +2895,7 @@
"$(inherited)",
"$(PROJECT_DIR)/SUPLA/lib",
);
MARKETING_VERSION = 2.3.29;
MARKETING_VERSION = 2.3.30;
PRODUCT_BUNDLE_IDENTIFIER = com.acsoftware.ios.supla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SUPLA/SUPLA-Bridging-Header.h";
Expand Down
5 changes: 5 additions & 0 deletions SUPLA/AddWizardVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@interface SAConfigResult : NSObject

@property(nonatomic) int resultCode;
@property(copy, nonatomic) NSString *extendedResultError;
@property(nonatomic) int extendedResultCode;

@property (copy, nonatomic) NSString *name;
@property (copy, nonatomic) NSString *state;
Expand Down Expand Up @@ -76,5 +78,8 @@
@property (weak, nonatomic) IBOutlet UIButton *btnSystemSettings;
@property (weak, nonatomic) IBOutlet UIButton *btnCancel;
@property (weak, nonatomic) IBOutlet UILabel *lStep3Text2;
@property (weak, nonatomic) IBOutlet UISwitch *swAutoMode;
@property (weak, nonatomic) IBOutlet UILabel *lAutoMode;
- (IBAction)swAutoModeChanged:(id)sender;

@end
119 changes: 86 additions & 33 deletions SUPLA/AddWizardVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
@implementation SAConfigResult

@synthesize resultCode;
@synthesize extendedResultError;
@synthesize extendedResultCode;

@synthesize name;
@synthesize state;
Expand All @@ -59,6 +61,7 @@ @implementation SAConfigResult

@implementation SASetConfigOperation {
int _result;
int _delay;
}

@synthesize SSID;
Expand All @@ -67,6 +70,22 @@ @implementation SASetConfigOperation {
@synthesize Email;
@synthesize delegate;

- (id)init {
if (self = [super init]) {
_delay = 0;
}

return self;
}

- (id)initWithDelay:(int)delay {
if (self = [super init]) {
_delay = delay;
}

return self;
}

- (BOOL)postDataWithFields:(NSDictionary *)fields {

NSMutableURLRequest *request =
Expand Down Expand Up @@ -101,6 +120,10 @@ - (void)onOperationDone:(SAConfigResult*)result {

- (void)main
{
if (_delay) {
[NSThread sleepForTimeInterval:_delay];
}

SAConfigResult *result = [[SAConfigResult alloc] init];

if ( self.SSID == nil
Expand Down Expand Up @@ -136,6 +159,7 @@ - (void)main
if ( requestError == nil && response != nil ) {
break;
} else {

retryCount--;
sleep(1);
}
Expand All @@ -148,6 +172,10 @@ - (void)main

if ( requestError != nil || response == nil ) {
result.resultCode = RESULT_CONN_ERROR;
if (requestError != nil) {
result.extendedResultError = [NSString stringWithFormat:@"%ld - %@", (long)requestError.code, requestError.localizedDescription];
result.extendedResultCode = requestError.code;
}
[self onOperationDone:result];
return;
}
Expand Down Expand Up @@ -299,6 +327,7 @@ @implementation SAAddWizardVC {
int _step;
int _pageId;
SAWifiAutoConnect *_wifiAutoConnect;
BOOL _1stAttempt;
}

-(NSOperationQueue *)OpQueue {
Expand Down Expand Up @@ -327,10 +356,10 @@ - (void)watchDogTimerFireMethod:(NSTimer *)timer {
timeout = 5;
break;
case STEP_WIFI_AUTO_CONNECT:
timeout = 60;
timeout = 90;
break;
case STEP_CONFIGURE:
timeout = 50;
timeout = 90;
break;
}

Expand Down Expand Up @@ -546,20 +575,21 @@ -(void)showPage:(int)page {
break;
case PAGE_STEP_3:
{
if ([SAWifiAutoConnect isAvailable]) {
[self.btnNext2 setAttributedTitle:NSLocalizedString(@"Start", NULL)];
}

_1stAttempt = YES;
_blinkTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(blinkTimerFireMethod:) userInfo:nil repeats:YES];

NSString *txt1 = NSLocalizedString(@"If the device when switched on does not work in the configuration mode, press and hold CONFIG button for at least 5 seconds.\n\n%@\n", NULL);

NSString *txt2 = NSLocalizedString([SAWifiAutoConnect isAvailable]
? @"Press START to start configuration." :
@"Press Next to continue." ,NULL);

self.lStep3Text2.text = [NSString stringWithFormat:txt1, txt2];
if ([SAWifiAutoConnect isAvailable]) {
self.swAutoMode.on = YES;
self.swAutoMode.hidden = NO;
self.lAutoMode.hidden = NO;
} else {
self.swAutoMode.on = NO;
self.swAutoMode.hidden = YES;
self.lAutoMode.hidden = YES;
}

[self swAutoModeChanged:self.swAutoMode];

[self showPageView:self.vStep3];
}
break;
Expand Down Expand Up @@ -605,8 +635,24 @@ -(void)configResult:(SAConfigResult*)result {
case RESULT_COMPAT_ERROR:
[self showError:NSLocalizedString(@"The connected device is not compatible with this Wizard!", NULL)];
break;
case RESULT_CONN_ERROR:
[self showError:NSLocalizedString(@"Connection with the device cannot be set! Make sure, if the Wi-fi connection has been set for the I/O device.", NULL)];
case RESULT_CONN_ERROR: {
NSString *errInfo = @"";
if (result.extendedResultCode == NSURLErrorNotConnectedToInternet && _1stAttempt) {
_1stAttempt = NO;
[NSThread sleepForTimeInterval:1];
[self connectToWiFi];
return;
} else if (result.extendedResultError != nil && result.extendedResultError.length) {
errInfo = [NSString stringWithFormat:@"\n[%@]", result.extendedResultError];
}
NSString *msg = [NSString stringWithFormat:@"%@%@", NSLocalizedString(@"Connection with the device cannot be set!", NULL), errInfo];

if (@available(iOS 14.0, *)) {
[self showErrorWithAttributedString:[self messageExtendedWithNotificationOfPermissions:msg]];
} else {
[self showError:msg];
}
}
break;
case RESULT_FAILED:
[self showError:NSLocalizedString(@"Configuration Failed!", NULL)];
Expand Down Expand Up @@ -716,6 +762,12 @@ -(void) superuserAuthorizationCanceled {
[self.btnNext2 setAttributedTitle:NSLocalizedString(@"Next", NULL)];
}

-(NSAttributedString*)messageExtendedWithNotificationOfPermissions:(NSString *)msg {
NSString *msg2 = NSLocalizedString(@"Make sure that the application has permissions to discover and connect to devices in the local network. This means that the \"iOS->Settings->SUPLA->Local network\" permission must be turned on for the wizard to work properly.", NULL);

return [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n\n%@", msg, msg2]];
}

-(void) connectToWiFi {
[self setStep:STEP_WIFI_AUTO_CONNECT];

Expand All @@ -729,31 +781,17 @@ -(void) connectToWiFi {
[self startConfiguration];
} else {
[self->_OpQueue cancelAllOperations];

NSString *msg1 = NSLocalizedString(@"No devices has been found! Check, if the device you want to configure is working in the configuration mode and try again.", NULL);

NSString *msg2 = NSLocalizedString(@"Make sure that the application has permissions to discover and connect to devices in the local network. This means that the \"iOS->Settings->SUPLA->Local network\" permission must be turned on for the wizard to work properly.", NULL);

if (@available(iOS 14.0, *)) {
NSMutableAttributedString *msg = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n\n%@", msg1, msg2]];

NSRange range = NSMakeRange(msg1.length+2, msg2.length);

[msg addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:range];
[self showErrorWithAttributedString: msg];
} else {
[self showError:msg1];
}
[self showError:NSLocalizedString(@"No devices has been found! Check, if the device you want to configure is working in the configuration mode and try again.", NULL)];
}
}
}];
}

-(void) startConfiguration {
-(void) startConfigurationWithDelay:(int)delaySec {
[self setStep:STEP_CONFIGURE];

[self.OpQueue cancelAllOperations];
SASetConfigOperation *setConfigOp = [[SASetConfigOperation alloc] init];
SASetConfigOperation *setConfigOp = [[SASetConfigOperation alloc] initWithDelay:delaySec];
setConfigOp.SSID = [self.edSSID.text
stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Expand All @@ -764,6 +802,10 @@ -(void) startConfiguration {
[self.OpQueue addOperation:setConfigOp];
}

-(void) startConfiguration {
[self startConfigurationWithDelay:0];
}

- (IBAction)nextTouchch:(id)sender {

[self preloaderVisible:YES];
Expand Down Expand Up @@ -801,7 +843,7 @@ - (IBAction)nextTouchch:(id)sender {

break;
case PAGE_STEP_3:
if ([SAWifiAutoConnect isAvailable]) {
if (self.swAutoMode.on) {
[self connectToWiFi];
} else {
[self showPage:PAGE_STEP_4];
Expand Down Expand Up @@ -850,4 +892,15 @@ - (IBAction)wifiSettingsTouch:(id)sender {
NSLog(@"Unable to open settings app.");
}
}
- (IBAction)swAutoModeChanged:(id)sender {

NSString *txt1 = NSLocalizedString(@"If the device when switched on does not work in the configuration mode, press and hold CONFIG button for at least 5 seconds.\n\n%@\n", NULL);

NSString *txt2 = NSLocalizedString(self.swAutoMode.on
? @"Press START to start configuration." :
@"Press Next to continue." ,NULL);

[self.btnNext2 setAttributedTitle:NSLocalizedString(self.swAutoMode.on ? @"Start" : @"Next", NULL)];
self.lStep3Text2.text = [NSString stringWithFormat:txt1, txt2];
}
@end
Loading

0 comments on commit 2faf055

Please sign in to comment.