Skip to content

Commit

Permalink
Go into standby if unable to contact OctoPrint (#540)
Browse files Browse the repository at this point in the history
* Go into standby if unable to contact OctoPrint

* test

* introduce boot grace time

* delete tmp.txt

Co-authored-by: UnchartedBull <timon.gaebelein@icloud.com>
  • Loading branch information
harleyg321 and UnchartedBull committed Apr 9, 2020
1 parent 534e0d0 commit 25523db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/app/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ export class NotificationService {
private observable: Observable<Notification>;
private observer: Observer<Notification>;
private hideNotifications = false;
private bootGrace = true;

public constructor() {
this.observable = new Observable((observer: Observer<Notification>): void => {
this.observer = observer;
setTimeout((): void => {
this.bootGrace = false;
}, 30000);
}).pipe(shareReplay(1));
}

Expand All @@ -27,7 +31,7 @@ export class NotificationService {
}

public setError(heading: string, text: string): void {
if (!this.hideNotifications) {
if ((!this.hideNotifications && !this.bootGrace) || (this.bootGrace && !text.endsWith('0 Unknown Error'))) {
this.observer.next({ heading, text, type: 'error' });
}
}
Expand All @@ -45,6 +49,10 @@ export class NotificationService {
public getObservable(): Observable<Notification> {
return this.observable;
}

public getBootGrace(): boolean {
return this.bootGrace;
}
}

export interface Notification {
Expand Down
13 changes: 13 additions & 0 deletions src/app/printer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ export class PrinterService {
);
}
});
} else if (error.status === 0 && this.notificationService.getBootGrace()) {
const printerStatus: PrinterStatusAPI = {
status: `connecting ...`,
nozzle: {
current: 0,
set: 0,
},
heatbed: {
current: 0,
set: 0,
},
};
observer.next(printerStatus);
} else {
const printerStatus: PrinterStatusAPI = {
status: `error (${error.status})`,
Expand Down

0 comments on commit 25523db

Please sign in to comment.