stand impl part 3

This commit is contained in:
Darius
2025-11-16 20:26:16 +01:00
parent 9a170d6f21
commit 4baacd9952

View File

@@ -1,6 +1,6 @@
import axios from "axios"; import axios from "axios";
import { Config } from "../config/config.js"; import { Config } from "../config/config.js";
import { logWarning } from "./logger.js"; import { logInfo, logWarning } from "./logger.js";
type HomeAssistantEntity = { type HomeAssistantEntity = {
entity_id: string; entity_id: string;
@@ -78,12 +78,14 @@ export async function getTemperatures(): Promise<Array<HomeAssistantEntity>> {
} }
// UTILITY // UTILITY
async function sendRequestToHomeAssistantStates( async function sendRequestToHomeAssistantStates(
entity_id: string, entity_id: string,
): Promise<HomeAssistantEntity> { ): Promise<HomeAssistantEntity> {
const url = `${Config.homeassistant.api_url}states/"${entity_id}`
logInfo(`sending request to ${url}`)
const response = await axios.get<HomeAssistantEntity>( const response = await axios.get<HomeAssistantEntity>(
`${Config.homeassistant.api_url}states/"${entity_id}`, url,
{ {
headers: { headers: {
Authorization: `Bearer ${Config.homeassistant.api_token}`, Authorization: `Bearer ${Config.homeassistant.api_token}`,
@@ -97,14 +99,10 @@ async function sendRequestToHomeAssistantStates(
async function sendRequestToHomeAssistantWebhook( async function sendRequestToHomeAssistantWebhook(
webhook_id: string, webhook_id: string,
): Promise<unknown> { ): Promise<unknown> {
const response = await axios.post<HomeAssistantEntity>( const url = `${Config.homeassistant.api_url}webhook/"${webhook_id}`
`${Config.homeassistant.api_url}webhook/"${webhook_id}`, logInfo(`sending request to ${url}`)
{
headers: { const response = await axios.post<HomeAssistantEntity>(url);
Authorization: `Bearer ${Config.homeassistant.api_token}`,
},
},
);
return response.data; return response.data;
} }