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

@@ -3,6 +3,7 @@ import { getDeskHeight, startStandingAutomation } from "../../util/api-homeassis
import { logInfo, logSuccess } from "../../util/logger.js";
import { BaseCommand } from "../base-command.js";
import type { ICommandRequirements } from "../interface.ts";
import { Config } from "../../config/config.js";
export class StandCommand extends BaseCommand {
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();
logInfo(response)
this.chatClient.say(channel, `blabla`, {
replyTo: msg,
});

View File

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

View File

@@ -99,7 +99,7 @@ async function sendRequestToHomeAssistantStates(
async function sendRequestToHomeAssistantWebhook(
webhook_id: string,
): 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}`)
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;
}
}
}