stand impl part 4

This commit is contained in:
Darius
2025-11-16 20:38:49 +01:00
parent 4baacd9952
commit 0fb087fbd9
5 changed files with 43 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ DEVELOPERS=userIdOfDeveloper(,separated)
TIDAL_HOST=http://localhost TIDAL_HOST=http://localhost
TIDAL_PORT=47836 TIDAL_PORT=47836
NIGHT_TIME=01:00-08:00
HA_API_URL=http://homeassistant.com/api/states/ HA_API_URL=http://homeassistant.com/api/states/
HA_API_TOKEN=Nina hätte hier jetzt ihr Token ausversehen stehen hihi HA_API_TOKEN=Nina hätte hier jetzt ihr Token ausversehen stehen hihi
HA_DESK_SENSOR_ID=entityId HA_DESK_SENSOR_ID=entityId

View File

@@ -3,6 +3,7 @@ import { getDeskHeight, startStandingAutomation } from "../../util/api-homeassis
import { logInfo, logSuccess } from "../../util/logger.js"; import { logInfo, logSuccess } from "../../util/logger.js";
import { BaseCommand } from "../base-command.js"; import { BaseCommand } from "../base-command.js";
import type { ICommandRequirements } from "../interface.ts"; import type { ICommandRequirements } from "../interface.ts";
import { Config } from "../../config/config.js";
export class StandCommand extends BaseCommand { export class StandCommand extends BaseCommand {
name = "stand"; name = "stand";
@@ -28,11 +29,16 @@ export class StandCommand extends BaseCommand {
// } // }
if (Config.night_time.contains()) {
this.chatClient.say(channel, `command disabled during nighttime`, {
replyTo: msg,
});
return
}
const response = await startStandingAutomation(); const response = await startStandingAutomation();
logInfo(response) logInfo(response)
this.chatClient.say(channel, `blabla`, { this.chatClient.say(channel, `blabla`, {
replyTo: msg, replyTo: msg,
}); });

View File

@@ -9,6 +9,7 @@ export const Config = {
client_secret: process.env.CLIENT_SECRET || "", client_secret: process.env.CLIENT_SECRET || "",
channels: process.env.CHANNELS?.split(",") || [], channels: process.env.CHANNELS?.split(",") || [],
developers: process.env.DEVELOPERS?.split(",") || [], developers: process.env.DEVELOPERS?.split(",") || [],
night_time: new TimeSpan(process.env.NIGHT_TIME || "00:00-00:00"),
tidal: { tidal: {
host: process.env.TIDAL_HOST || "", host: process.env.TIDAL_HOST || "",

View File

@@ -99,7 +99,7 @@ async function sendRequestToHomeAssistantStates(
async function sendRequestToHomeAssistantWebhook( async function sendRequestToHomeAssistantWebhook(
webhook_id: string, webhook_id: string,
): Promise<unknown> { ): Promise<unknown> {
const url = `${Config.homeassistant.api_url}webhook/"${webhook_id}` const url = `${Config.homeassistant.api_url}webhook/${webhook_id}`
logInfo(`sending request to ${url}`) logInfo(`sending request to ${url}`)
const response = await axios.post<HomeAssistantEntity>(url); const response = await axios.post<HomeAssistantEntity>(url);

32
src/util/timespan.ts Normal file
View File

@@ -0,0 +1,32 @@
class TimeSpan {
private start: { hours: number; minutes: number };
private end: { hours: number; minutes: number };
constructor(timeSpanStr: string) {
const [startStr, endStr] = timeSpanStr.split('-');
this.start = this.parseTime(startStr);
this.end = this.parseTime(endStr);
}
private parseTime(timeStr: string) {
const [hours, minutes] = timeStr.split(':').map(Number);
return { hours, minutes };
}
contains(timestamp: number = Date.now()): boolean {
const date = new Date(timestamp);
const hours = date.getHours();
const minutes = date.getMinutes();
const currentMinutes = hours * 60 + minutes;
const startMinutes = this.start.hours * 60 + this.start.minutes;
const endMinutes = this.end.hours * 60 + this.end.minutes;
if (startMinutes > endMinutes) {
return currentMinutes >= startMinutes || currentMinutes < endMinutes;
} else {
return currentMinutes >= startMinutes && currentMinutes < endMinutes;
}
}
}