Skip to content

Commit

Permalink
Setting a timeout aswell as resetting the preparationDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Dec 15, 2024
1 parent f41baac commit b239808
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/classes/preparationDevice/sanremo/sanremoYOUDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class SanremoYOUDevice extends PreparationDevice {

private connectionURL: string = '';
private statusPhase: number = 0;
constructor(protected httpClient: HttpClient, _preparation: Preparation) {
constructor(
protected httpClient: HttpClient,
_preparation: Preparation,
) {
super(httpClient, _preparation);

this.connectionURL = this.getPreparation().connectedPreparationDevice.url;
Expand All @@ -26,6 +29,7 @@ export class SanremoYOUDevice extends PreparationDevice {
try {
const options = {
url: this.connectionURL + '/api/runtime',
connectTimeout: 5000,
};
const response: HttpResponse = await CapacitorHttp.get(options);
const responseJSON = await response.data;
Expand All @@ -42,7 +46,7 @@ export class SanremoYOUDevice extends PreparationDevice {

private getApiEndpointForMode(
mode: SanremoYOUMode,
action: 'start' | 'stop'
action: 'start' | 'stop',
): string {
switch (mode) {
case SanremoYOUMode.MANUAL_CONTROLLING:
Expand Down
8 changes: 6 additions & 2 deletions src/classes/preparationDevice/xenia/xeniaDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export class XeniaDevice extends PreparationDevice {
public scriptList: Array<{ INDEX: number; TITLE: string }> = [];

private apiVersion: number = 2;
constructor(protected httpClient: HttpClient, _preparation: Preparation) {
constructor(
protected httpClient: HttpClient,
_preparation: Preparation,
) {
super(httpClient, _preparation);

const connectedPreparationDevice =
Expand Down Expand Up @@ -39,7 +42,7 @@ export class XeniaDevice extends PreparationDevice {
}

const errorMessage = `Unexpected JSON response: ${JSON.stringify(
responseJSON
responseJSON,
)}`;
this.logError(errorMessage);
throw new Error(errorMessage);
Expand Down Expand Up @@ -148,6 +151,7 @@ export class XeniaDevice extends PreparationDevice {
try {
const options = {
url: url,
connectTimeout: 5000,
};
const response: HttpResponse = await CapacitorHttp.get(options);
const responseJSON = await response.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export class BrewBrewingPreparationDeviceComponent implements OnInit {
}

public async instancePreparationDevice(_brew: Brew = null) {
/** If a user changes the preparation device, we need to unset the preparation device here firstly **/
this.preparationDevice = undefined;
this.preparation = this.data.getPreparation();
const connectedDevice: PreparationDevice =
this.uiPreparationHelper.getConnectedDevice(this.preparation);
Expand Down
9 changes: 8 additions & 1 deletion src/components/brews/brew-brewing/brew-brewing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,14 @@ export class BrewBrewingComponent implements OnInit, AfterViewInit {
this.data.method_of_preparation_tools = [];

if (this.brewBrewingPreparationDeviceEl) {
this.brewBrewingPreparationDeviceEl.instancePreparationDevice();
this.brewBrewingPreparationDeviceEl.instancePreparationDevice().then(
() => {
this.checkChanges();
},
() => {
this.checkChanges();
},
);
}

if (this.timer?.isTimerRunning() === false) {
Expand Down

0 comments on commit b239808

Please sign in to comment.