Start to reorganize

This commit is contained in:
2019-09-29 22:08:21 -04:00
parent aee51c8a15
commit 89df5efe5a
92 changed files with 15494 additions and 544 deletions

View File

@@ -0,0 +1,7 @@
import { LaundryStatus } from './laundry-status';
describe('LaundryStatus', () => {
it('should create an instance', () => {
expect(new LaundryStatus()).toBeTruthy();
});
});

View File

@@ -0,0 +1,4 @@
export class LaundryStatus {
washer = false;
dryer = false;
}

View 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();
});
});

View 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();
}
}

View File

@@ -0,0 +1,7 @@
import { WeatherReading } from './weather-reading';
describe('WeatherReading', () => {
it('should create an instance', () => {
expect(new WeatherReading()).toBeTruthy();
});
});

View 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;
}

View File

@@ -0,0 +1,4 @@
export class WeatherValue {
bucket: string;
averageValue: number;
}

View 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();
});
});

View 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();
}
}