mirror of
https://github.com/KevinMidboe/brewPi.git
synced 2025-10-29 16:50:12 +00:00
35 lines
861 B
TypeScript
35 lines
861 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
|
|
const host = 'http://brewpi.schleppe:5000';
|
|
const sensorsUrl = `${host}/api/sensors`;
|
|
const relaysUrl = `${host}/api/relays`;
|
|
|
|
async function getSensors() {
|
|
return fetch(sensorsUrl)
|
|
.then((resp) => resp.json())
|
|
.then((response) => {
|
|
return response?.sensors;
|
|
});
|
|
}
|
|
|
|
async function getRelays() {
|
|
return fetch(relaysUrl)
|
|
.then((resp) => resp.json())
|
|
.then((response) => {
|
|
return response?.relays || [];
|
|
});
|
|
}
|
|
|
|
export const load: PageServerLoad = async () => {
|
|
const [sensors, relays] = await Promise.all([getSensors(), getRelays()]);
|
|
|
|
const inside = sensors.find((sensor) => sensor.location === 'inside');
|
|
const outside = sensors.find((sensor) => sensor.location === 'outside');
|
|
|
|
return {
|
|
inside: inside || null,
|
|
outside: outside || null,
|
|
relays
|
|
};
|
|
};
|