mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-24 17:24:00 -05:00
Quick and dirty strict checks
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { Observable, BehaviorSubject, firstValueFrom } from 'rxjs';
|
||||
import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr';
|
||||
import { LaundryStatus } from '../../models/laundry/laundry-status';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
class DeviceMessage {
|
||||
name: string;
|
||||
status: boolean;
|
||||
name: string | undefined;
|
||||
status: boolean | undefined;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@@ -48,7 +48,7 @@ export class LaundryService {
|
||||
}
|
||||
|
||||
private async loadLatestStatus() {
|
||||
const data = await this.httpClient.get<DeviceMessage[]>(`/api/device-status/status/recent`).toPromise();
|
||||
const data = await firstValueFrom(this.httpClient.get<DeviceMessage[]>(`/api/device-status/status/recent`));
|
||||
|
||||
const newStatus = new LaundryStatus();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { PowerStatus } from 'src/app/models/power/power-status';
|
||||
})
|
||||
export class PowerService {
|
||||
private connection: HubConnection;
|
||||
private latestStatus: BehaviorSubject<PowerStatus> = new BehaviorSubject<PowerStatus>(null);
|
||||
private latestStatus: BehaviorSubject<PowerStatus | null> = new BehaviorSubject<PowerStatus | null>(null);
|
||||
|
||||
constructor() {
|
||||
this.connection = new HubConnectionBuilder()
|
||||
@@ -22,7 +22,7 @@ export class PowerService {
|
||||
this.connection.start();
|
||||
}
|
||||
|
||||
getLatestStatus(): Observable<PowerStatus> {
|
||||
getLatestStatus(): Observable<PowerStatus | null> {
|
||||
return this.latestStatus.asObservable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { Observable, BehaviorSubject, firstValueFrom } from 'rxjs';
|
||||
import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr';
|
||||
import { WeatherUpdate } from 'src/app/models/weather/weather-update';
|
||||
import { WeatherValue } from 'src/app/models/weather/weather-value';
|
||||
@@ -7,14 +7,14 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { WeatherValueType } from 'src/app/models/weather/weather-value-type';
|
||||
import { WeatherAggregates } from 'src/app/models/weather/weather-aggregates';
|
||||
|
||||
import * as moment from 'moment';
|
||||
import moment from 'moment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WeatherService {
|
||||
private connection: HubConnection;
|
||||
private latestReading: BehaviorSubject<WeatherUpdate> = new BehaviorSubject<WeatherUpdate>(null);
|
||||
private latestReading: BehaviorSubject<WeatherUpdate | null> = new BehaviorSubject<WeatherUpdate | null>(null);
|
||||
|
||||
constructor(private httpClient: HttpClient) {
|
||||
this.connection = new HubConnectionBuilder()
|
||||
@@ -28,24 +28,24 @@ export class WeatherService {
|
||||
this.connection.start();
|
||||
}
|
||||
|
||||
getLatestReading(): Observable<WeatherUpdate> {
|
||||
getLatestReading(): Observable<WeatherUpdate | null> {
|
||||
return this.latestReading.asObservable();
|
||||
}
|
||||
|
||||
async getReadingValueHistory(valueType: WeatherValueType, start: moment.Moment, end: moment.Moment): Promise<WeatherValue[]> {
|
||||
async getReadingValueHistory(valueType: WeatherValueType, start: moment.Moment, end: moment.Moment): Promise<WeatherValue[] | undefined> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const data = await this.httpClient.get<WeatherValue[]>(`/api/weather/readings/value-history?weatherValueType=${valueType}&start=${startString}&end=${endString}`).toPromise();
|
||||
const data = await firstValueFrom(this.httpClient.get<WeatherValue[]>(`/api/weather/readings/value-history?weatherValueType=${valueType}&start=${startString}&end=${endString}`));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async getReadingAggregate(start: moment.Moment, end: moment.Moment): Promise<WeatherAggregates> {
|
||||
async getReadingAggregate(start: moment.Moment, end: moment.Moment): Promise<WeatherAggregates | undefined> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const data = await this.httpClient.get<WeatherAggregates>(`/api/weather/readings/aggregate?start=${startString}&end=${endString}`).toPromise();
|
||||
const data = await firstValueFrom(this.httpClient.get<WeatherAggregates>(`/api/weather/readings/aggregate?start=${startString}&end=${endString}`));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user