source, static files & Dockerfile

This commit is contained in:
2025-04-08 21:47:35 +02:00
parent 24ab595ab3
commit 68ebc7568e
92 changed files with 4348 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { env } from '$env/dynamic/private';
import type { Entity } from '$lib/interfaces/homeassistant';
function buildHomeassistantRequest() {
const url = env.HOMEASSISTANT_URL || '';
const token = env.HOMEASSISTANT_TOKEN || '';
const options = {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
}
};
return { url, options };
}
async function fetchHassStates() {
const { url, options } = buildHomeassistantRequest();
return fetch(url, options).then((resp) => resp.json());
}
export async function fetchP1P(): Promise<Entity[]> {
try {
let hassStates = await fetchHassStates();
hassStates = hassStates.filter(
(el: Entity) => el.attributes.friendly_name?.includes('P1P') === true
);
return hassStates;
} catch (error) {
console.log('ERROR! from fetchP1P:', error);
return Promise.reject(null);
}
}