Skip to content

Commit

Permalink
Alarm update
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed May 19, 2024
1 parent e61fd73 commit fda2996
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
7 changes: 7 additions & 0 deletions src/app/modules/alarms/alarms.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ export class AlarmsFacade {

muteAlarm(id: string) {
this.alarms.get(id)['muted'] = true;
this.signalk.api.post(`alarms/${id}/silence`, undefined).subscribe(
() => undefined,
(err: HttpErrorResponse) => {
console.warn(`Error silencing alarm: ${id}`, err);
}
);
}

unMuteAlarm(id: string) {
Expand Down Expand Up @@ -277,6 +283,7 @@ export class AlarmsFacade {
// update alarm entry
alarm.state = notification.state;
alarm.message = notification.message;
alarm.sound = notification.method.includes('sound') ? true : false;
}
}
this.alarmSource.next(true);
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/alarms/components/alarm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class AlarmComponent implements OnInit {
@Input() audioContext: AudioContext; // Web Audio API
@Input() audioStatus: string; // changed audio context state
@Input() soundFile = './assets/sound/woop.mp3';
@Input() hasSound = false;
@Input() loop = true; // true: loop audio file playback
@Input() mute = false; // true: mute audio playback

Expand Down
32 changes: 10 additions & 22 deletions src/app/modules/alarms/components/alarms-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Subscription } from 'rxjs';
import { Alarm, AlarmState, SignalKClient } from 'signalk-client-angular';
import { SignalKClient } from 'signalk-client-angular';
import { AlarmsFacade } from '../alarms.facade';

/********* AlarmsDialog *********
Expand Down Expand Up @@ -42,11 +42,7 @@ import { AlarmsFacade } from '../alarms.facade';
<mat-card-content> </mat-card-content>
<mat-card-actions>
@if(!i.cancel) {
<button
mat-raised-button
color="warn"
(click)="raise(i.key, i.subtitle)"
>
<button mat-raised-button color="warn" (click)="raise(i.key)">
<mat-icon>alarm_on</mat-icon>
RAISE ALARM
</button>
Expand Down Expand Up @@ -205,26 +201,18 @@ export class AlarmsDialog implements OnInit {
});
}

raise(alarmType: string, msg: string) {
this.signalk.api
.raiseAlarm(
'self',
alarmType,
new Alarm(msg, AlarmState.emergency, true, true)
)
.subscribe(
() => {
console.log(`Raise Alarm: ${alarmType}`);
},
(err: HttpErrorResponse) => {
console.warn(`Error raising alarm: ${alarmType}`, err);
}
);
raise(alarmType: string) {
this.signalk.api.post(`alarms/${alarmType}`, undefined).subscribe(
() => undefined,
(err: HttpErrorResponse) => {
console.warn(`Error raising alarm: ${alarmType}`, err);
}
);
this.dialogRef.close();
}

clear(alarmType: string) {
this.signalk.api.clearAlarm('self', alarmType).subscribe(
this.signalk.api.delete(`alarms/${alarmType}`).subscribe(
() => undefined,
(err: HttpErrorResponse) => {
console.warn(`Error clearing alarm: ${alarmType}`, err);
Expand Down

0 comments on commit fda2996

Please sign in to comment.