Add power display widget

This commit is contained in:
2019-10-15 18:10:55 -04:00
parent fe1a66a655
commit 2ee6cb2b4a
9 changed files with 132 additions and 8 deletions

View File

@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr';
import { PowerStatus } from 'src/app/models/power/power-status';
@Injectable({
providedIn: 'root'
})
export class PowerService {
private connection: HubConnection;
private latestStatus: BehaviorSubject<PowerStatus> = new BehaviorSubject<PowerStatus>(null);
constructor() {
this.connection = new HubConnectionBuilder()
.withUrl('/api/hub/power')
.build();
this.connection.on('LatestSample', (message: string) => {
this.latestStatus.next(JSON.parse(message));
});
this.connection.start();
}
getLatestStatus(): Observable<PowerStatus> {
return this.latestStatus.asObservable();
}
}