home assistant integration; volume for tidal; do some abstracting

This commit is contained in:
Darius
2025-10-02 21:36:19 +02:00
parent 9097266197
commit 0c54b1f776
12 changed files with 390 additions and 33 deletions

View File

@@ -0,0 +1,48 @@
import type { ChatMessage } from "@twurple/chat";
import { getDeskHeight } from "../../util/api-homeassistant.ts";
import { logSuccess } from "../../util/logger.ts";
import { BaseCommand } from "../base-command.ts";
import type { ICommandRequirements } from "../interface.ts";
export class PositionCommand extends BaseCommand {
name = "position";
cooldown = 0;
enabled = true;
requirements: ICommandRequirements = {
developer: false,
mod: false,
};
triggered = async (
channel: string,
user: string,
_text: string,
msg: ChatMessage,
) => {
logSuccess(`${channel} ${user} position command triggered`);
const position = await getPosition();
this.chatClient.say(channel, `darius is ${position} right now`, {
replyTo: msg,
});
};
}
async function getPosition(): Promise<string> {
const heightFromHA = await getDeskHeight();
if (!heightFromHA) {
return "unkown";
}
const height = convertHeightToCentimeters(heightFromHA.state);
if (height > 95) {
return "standing";
} else {
return "sitting";
}
}
function convertHeightToCentimeters(height: string): number {
const meters = parseFloat(height);
const centimeters = Math.round(meters * 100);
return centimeters;
}