// src/actions/home-axes.ts import streamDeck, { action, KeyDownEvent, SingletonAction } from "@elgato/streamdeck"; import { OctoPrintClient, OctoPrintSettings } from "../octoprint-client"; @action({ UUID: "com.octoprint.monitor.home-axes" }) export class HomeAxesAction extends SingletonAction { override async onKeyDown(ev: KeyDownEvent): Promise { const settings = ev.payload.settings as unknown as OctoPrintSettings; if (!settings?.host || !settings?.apiKey) { await ev.action.setTitle("Configure"); return; } const client = new OctoPrintClient(settings); try { const printer = await client.getPrinterState(); if (printer.state.flags.printing) { await ev.action.setTitle("Printing!\nBlocked"); setTimeout(() => ev.action.setTitle("Home"), 2000); return; } if (!printer.state.flags.operational) { await ev.action.setTitle("Offline"); setTimeout(() => ev.action.setTitle("Home"), 2000); return; } await ev.action.setTitle("Homing…"); await client.homeAxes(["x", "y", "z"]); await ev.action.setTitle("✓ Homed"); setTimeout(() => ev.action.setTitle("Home"), 2000); } catch (err) { streamDeck.logger.error("HomeAxes: failed", err); await ev.action.setTitle("⚠️ Error"); setTimeout(() => ev.action.setTitle("Home"), 2000); } } }