mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-16 17:23:24 -05:00
Start to reorganize
This commit is contained in:
7
Display/src/app/services/laundry/laundry-status.spec.ts
Normal file
7
Display/src/app/services/laundry/laundry-status.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { LaundryStatus } from './laundry-status';
|
||||
|
||||
describe('LaundryStatus', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new LaundryStatus()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
4
Display/src/app/services/laundry/laundry-status.ts
Normal file
4
Display/src/app/services/laundry/laundry-status.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class LaundryStatus {
|
||||
washer = false;
|
||||
dryer = false;
|
||||
}
|
||||
12
Display/src/app/services/laundry/laundry.service.spec.ts
Normal file
12
Display/src/app/services/laundry/laundry.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LaundryService } from './laundry.service';
|
||||
|
||||
describe('LaundryService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: LaundryService = TestBed.get(LaundryService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
31
Display/src/app/services/laundry/laundry.service.ts
Normal file
31
Display/src/app/services/laundry/laundry.service.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { Socket } from 'ngx-socket-io';
|
||||
import { LaundryStatus } from './laundry-status';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LaundryService {
|
||||
private latestStatus: BehaviorSubject<LaundryStatus> = new BehaviorSubject<LaundryStatus>(new LaundryStatus());
|
||||
|
||||
constructor(private socket: Socket) {
|
||||
this.socket.on('status', (statusString: string) => {
|
||||
const newStatus: LaundryStatus = JSON.parse(statusString);
|
||||
|
||||
if (newStatus.washer !== undefined) {
|
||||
this.latestStatus.value.washer = newStatus.washer;
|
||||
}
|
||||
|
||||
if (newStatus.dryer !== undefined) {
|
||||
this.latestStatus.value.dryer = newStatus.dryer;
|
||||
}
|
||||
});
|
||||
|
||||
this.socket.emit('getStatus');
|
||||
}
|
||||
|
||||
getLatestStatus(): Observable<LaundryStatus> {
|
||||
return this.latestStatus.asObservable();
|
||||
}
|
||||
}
|
||||
7
Display/src/app/services/weather/weather-reading.spec.ts
Normal file
7
Display/src/app/services/weather/weather-reading.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { WeatherReading } from './weather-reading';
|
||||
|
||||
describe('WeatherReading', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new WeatherReading()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
19
Display/src/app/services/weather/weather-reading.ts
Normal file
19
Display/src/app/services/weather/weather-reading.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export class WeatherReading {
|
||||
Type: string;
|
||||
Message: null;
|
||||
Timestamp: Date;
|
||||
WindDirection: string;
|
||||
WindSpeed: number;
|
||||
Humidity: number;
|
||||
HumidityTemperature: number;
|
||||
Rain: number;
|
||||
Pressure: number;
|
||||
PressureTemperature: number;
|
||||
BatteryLevel: number;
|
||||
LightLevel: number;
|
||||
Latitude: number;
|
||||
Longitude: number;
|
||||
Altitude: number;
|
||||
SatelliteCount: number;
|
||||
GpsTimestamp: Date;
|
||||
}
|
||||
4
Display/src/app/services/weather/weather-value.ts
Normal file
4
Display/src/app/services/weather/weather-value.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class WeatherValue {
|
||||
bucket: string;
|
||||
averageValue: number;
|
||||
}
|
||||
12
Display/src/app/services/weather/weather.service.spec.ts
Normal file
12
Display/src/app/services/weather/weather.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WeatherService } from './weather.service';
|
||||
|
||||
describe('WeatherService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: WeatherService = TestBed.get(WeatherService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
28
Display/src/app/services/weather/weather.service.ts
Normal file
28
Display/src/app/services/weather/weather.service.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr';
|
||||
import { WeatherReading } from './weather-reading';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WeatherService {
|
||||
private connection: HubConnection;
|
||||
private latestReading: BehaviorSubject<WeatherReading> = new BehaviorSubject<WeatherReading>(null);
|
||||
|
||||
constructor() {
|
||||
this.connection = new HubConnectionBuilder()
|
||||
.withUrl('http://172.23.10.3:80/api/hub/weather')
|
||||
.build();
|
||||
|
||||
this.connection.on('LatestReading', (message: string) => {
|
||||
this.latestReading.next(JSON.parse(message));
|
||||
});
|
||||
|
||||
this.connection.start();
|
||||
}
|
||||
|
||||
getLatestReading(): Observable<WeatherReading> {
|
||||
return this.latestReading.asObservable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user