Skip to content

Commit

Permalink
Fix double sending of test results, due to missing unsubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed Jun 13, 2024
1 parent 03aecf7 commit 9272b7f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
<router-outlet></router-outlet>
</div>
<footer class="flex-footer">
<span>{{getCurrentYear()}} By <a href="https://www.thingpulse.com">ThingPulse</a> 1.0.10</span>
<span>{{getCurrentYear()}} By <a href="https://www.thingpulse.com">ThingPulse</a> 1.0.11</span>
</footer>
36 changes: 24 additions & 12 deletions src/app/components/testrunner/testrunner.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { MatStepper } from '@angular/material/stepper';
import { ActivatedRoute } from '@angular/router';
import { FirmwareMessage } from 'src/app//model/firmware-message';
Expand All @@ -9,21 +9,22 @@ import { EspPortService } from 'src/app/shared/esp-port.service';
import { Partition, PartitionProgress, sleep, TestState } from 'src/app/shared/utils.service';
import { TestResultService } from 'src/app/shared/test-result.service';
import { TestResult } from 'src/app/model/test-result';
import { Subscription } from 'rxjs';


@Component({
selector: 'app-testrunner',
templateUrl: './testrunner.component.html',
styleUrls: ['./testrunner.component.scss']
})
export class TestrunnerComponent implements OnInit {
export class TestrunnerComponent implements OnInit, OnDestroy {

deviceId: string;
title = 'ThingPulse Hardware Test Tool';
firmwareMessages: FirmwareMessage[] = [];

@ViewChild('stepper') stepper: MatStepper;


private connected = false;
private monitoring = false;
messageArea: string = "";
Expand All @@ -34,6 +35,7 @@ export class TestrunnerComponent implements OnInit {

progresses: PartitionProgress[] = new Array();
deviceConfiguration: DeviceConfiguration;
private subscriptions: Subscription = new Subscription();

constructor(private espPortService: EspPortService,
private route: ActivatedRoute,
Expand All @@ -43,24 +45,29 @@ export class TestrunnerComponent implements OnInit {
}

ngOnInit(): void {
console.log("init TestrunnerComponent");
this.deviceId = this.route.snapshot.paramMap.get("deviceId")!;
console.log("deviceId: ", this.deviceId);
this.deviceConfigurationService.getDeviceConfigurationById(this.deviceId).then(configuration => {
this.deviceConfiguration = configuration!;
})
this.espPortService.portStateStream.subscribe(isConnected => {
const portStateStreamSubscription = this.espPortService.portStateStream.subscribe(isConnected => {
console.log("isConnected: ", isConnected);
this.connected = isConnected;
})
this.espPortService.monitorStateStream.subscribe(isMonitoring => {
});
this.subscriptions.add(portStateStreamSubscription);
const monitorStateSubscription = this.espPortService.monitorStateStream.subscribe(isMonitoring => {
console.log("isMonitoring: ", isMonitoring);
this.monitoring = isMonitoring;
})
this.espPortService.flashProgressStream.subscribe(progress => {

});
this.subscriptions.add(monitorStateSubscription);

const flashProgressStreamSubscription = this.espPortService.flashProgressStream.subscribe(progress => {
this.progresses[progress.index] = progress;
})
this.espPortService.monitorMessageStream.subscribe(message => {
});
this.subscriptions.add(flashProgressStreamSubscription);

const monitorStreamSubscription = this.espPortService.monitorMessageStream.subscribe(message => {
try {
this.firmwareMessages = JSON.parse(message);
this.espPortService.stopMonitor();
Expand All @@ -74,7 +81,8 @@ export class TestrunnerComponent implements OnInit {
}

})
this.espPortService.testStateStream.subscribe(state => {
this.subscriptions.add(monitorStreamSubscription);
const testStateStreamSubscription = this.espPortService.testStateStream.subscribe(state => {
console.log("Test State: ", state);
switch(state) {
case TestState.Restarting:
Expand All @@ -92,8 +100,12 @@ export class TestrunnerComponent implements OnInit {

}
});
this.subscriptions.add(testStateStreamSubscription);
}

ngOnDestroy(): void {
this.subscriptions.unsubscribe();
}

resetState() {
this.messageArea = ""
Expand Down
1 change: 0 additions & 1 deletion src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ <h1>Device Class</h1>

<app-add-local-configuration></app-add-local-configuration>

<button (click)="sendResult()">Send Test Result</button>


19 changes: 1 addition & 18 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { DeviceConfiguration } from '../model/device-configuration';
import { DeviceConfigurationService } from '../shared/device-configuration.service';
import { TestResultService } from '../shared/test-result.service';
import { TestResult } from '../model/test-result';

@Component({
selector: 'app-home',
Expand All @@ -13,7 +11,7 @@ export class HomeComponent implements OnInit {

deviceConfigurations: DeviceConfiguration[];

constructor(public deviceConfigurationService: DeviceConfigurationService, private testResultService: TestResultService) {
constructor(public deviceConfigurationService: DeviceConfigurationService) {

}

Expand All @@ -38,21 +36,6 @@ export class HomeComponent implements OnInit {
return this.deviceConfigurationService.isLocalConfiguration(id);
}

sendResult() {
const testResult = {
mac_address: '00:1A:2B:3C:4D:5E',
overall_result: <const> 'OK',
device_type: 'DeviceTypeA',
additional_info: {
test1: 'pass',
test2: 'fail'
}
};

this.testResultService.sendTestResult(testResult).subscribe(response => {
console.log('Test result sent successfully:', response);
});
}


}

0 comments on commit 9272b7f

Please sign in to comment.