mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-21 01:25:38 -05:00
Bunch more new UI
This commit is contained in:
62
WebDisplay/src/stores/indoorStore.ts
Normal file
62
WebDisplay/src/stores/indoorStore.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import axios from 'axios';
|
||||
import Environment from '@/environment';
|
||||
import { HubConnection, HubConnectionBuilder } from '@microsoft/signalr';
|
||||
import { LatestReadings } from '@/models/environment.ts/latestReadings';
|
||||
import { ReadingsGrouped } from '@/models/environment.ts/readingsGrouped';
|
||||
|
||||
export function createIndoorStore(name: string) {
|
||||
return defineStore(`indoor-${name}`, {
|
||||
state: () => {
|
||||
return {
|
||||
current: null as LatestReadings | null,
|
||||
_connection: null as HubConnection | null
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
async start() {
|
||||
if (this._connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._connection = new HubConnectionBuilder()
|
||||
.withUrl(Environment.getUrlPrefix() + '/api/hub/environment', {
|
||||
withCredentials: false
|
||||
})
|
||||
.build();
|
||||
|
||||
await this._connection.start();
|
||||
|
||||
this._connection.on('Latest', (message: string) => {
|
||||
const latestReadings = JSON.parse(message) as LatestReadings;
|
||||
|
||||
if (latestReadings.name === name) {
|
||||
this.$patch({ current: latestReadings });
|
||||
}
|
||||
});
|
||||
|
||||
this._connection.send('RequestLatest');
|
||||
},
|
||||
async stop() {
|
||||
if (!this._connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this._connection.stop();
|
||||
|
||||
this._connection = null;
|
||||
},
|
||||
async getReadingValueHistoryGrouped(start: Date, end: Date, bucketMinutes: number): Promise<ReadingsGrouped[]> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const response = await axios.get<ReadingsGrouped[]>(
|
||||
Environment.getUrlPrefix() +
|
||||
`/api/environment/readings/history-grouped?start=${startString}&end=${endString}&bucketMinutes=${bucketMinutes}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { HubConnection, HubConnectionBuilder } from '@microsoft/signalr';
|
||||
import axios from 'axios';
|
||||
import Environment from '@/environment';
|
||||
import PowerStatus from '@/models/power/power-status';
|
||||
import PowerHistoryGrouped from '@/models/power/power-history-grouped';
|
||||
|
||||
export const usePowerStore = defineStore('power', {
|
||||
state: () => {
|
||||
@@ -36,6 +38,16 @@ export const usePowerStore = defineStore('power', {
|
||||
await this._connection.stop();
|
||||
|
||||
this._connection = null;
|
||||
},
|
||||
async getReadingHistoryGrouped(start: Date, end: Date, bucketMinutes: number): Promise<PowerHistoryGrouped[]> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const response = await axios.get<PowerHistoryGrouped[]>(
|
||||
Environment.getUrlPrefix() + `/api/power/status/history-grouped?start=${startString}&end=${endString}&bucketMinutes=${bucketMinutes}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,7 +6,9 @@ import WeatherUpdate from '@/models/weather/weather-update';
|
||||
import WeatherRecent from '@/models/weather/weather-recent';
|
||||
import WeatherValueType from '@/models/weather/weather-value-type';
|
||||
import WeatherValueGrouped from '@/models/weather/weather-value-grouped';
|
||||
import { WeatherAggregates } from '@/models/weather/weather-aggregates';
|
||||
import WeatherHistoryGrouped from '@/models/weather/weather-history-grouped';
|
||||
import WindHistoryGrouped from '@/models/weather/wind-history-grouped';
|
||||
import WeatherAggregates from '@/models/weather/weather-aggregates';
|
||||
|
||||
export const useWeatherStore = defineStore('weather', {
|
||||
state: () => {
|
||||
@@ -43,18 +45,11 @@ export const useWeatherStore = defineStore('weather', {
|
||||
this._connection = null;
|
||||
},
|
||||
async getLatest(): Promise<WeatherRecent> {
|
||||
const response = await axios.get<WeatherRecent>(
|
||||
Environment.getUrlPrefix() + `/api/weather/readings/recent`
|
||||
);
|
||||
const response = await axios.get<WeatherRecent>(Environment.getUrlPrefix() + `/api/weather/readings/recent`);
|
||||
|
||||
return response.data;
|
||||
},
|
||||
async getReadingValueHistoryGrouped(
|
||||
valueType: WeatherValueType,
|
||||
start: Date,
|
||||
end: Date,
|
||||
bucketMinutes: number
|
||||
): Promise<WeatherValueGrouped[]> {
|
||||
async getReadingValueHistoryGrouped(valueType: WeatherValueType, start: Date, end: Date, bucketMinutes: number): Promise<WeatherValueGrouped[]> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
@@ -65,16 +60,32 @@ export const useWeatherStore = defineStore('weather', {
|
||||
|
||||
return response.data;
|
||||
},
|
||||
async getReadingAggregate(
|
||||
start: Date,
|
||||
end: Date
|
||||
): Promise<WeatherAggregates | undefined> {
|
||||
async getReadingAggregate(start: Date, end: Date): Promise<WeatherAggregates | undefined> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const response = await axios.get<WeatherAggregates>(
|
||||
Environment.getUrlPrefix() +
|
||||
`/api/weather/readings/aggregate?start=${startString}&end=${endString}`
|
||||
Environment.getUrlPrefix() + `/api/weather/readings/aggregate?start=${startString}&end=${endString}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
},
|
||||
async getReadingHistoryGrouped(start: Date, end: Date, bucketMinutes: number): Promise<WeatherHistoryGrouped[]> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const response = await axios.get<WeatherHistoryGrouped[]>(
|
||||
Environment.getUrlPrefix() + `/api/weather/readings/history-grouped?start=${startString}&end=${endString}&bucketMinutes=${bucketMinutes}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
},
|
||||
async getWindHistoryGrouped(start: Date, end: Date, bucketMinutes: number): Promise<WindHistoryGrouped[]> {
|
||||
const startString = start.toISOString();
|
||||
const endString = end.toISOString();
|
||||
|
||||
const response = await axios.get<WindHistoryGrouped[]>(
|
||||
Environment.getUrlPrefix() + `/api/weather/readings/wind-history-grouped?start=${startString}&end=${endString}&bucketMinutes=${bucketMinutes}`
|
||||
);
|
||||
|
||||
return response.data;
|
||||
|
||||
Reference in New Issue
Block a user