extend action handling

This commit is contained in:
2025-11-16 16:45:47 +01:00
parent 1f42266103
commit c5c566bd8c
2 changed files with 17 additions and 4 deletions

View File

@@ -28,4 +28,4 @@ const bootEntries = await efiBootMgrService.listBootEntries();
const mqttClient = await getMqttClient(config.mqtt);
runPublishLoop(config, mqttClient, bootEntries);
startListeners(config, mqttClient);
startListeners(config, mqttClient, bootEntries);

View File

@@ -1,27 +1,40 @@
import type { MqttClient } from "mqtt";
import type z from "zod";
import type { ConfigSchema } from "./config.schema";
import type { BootEntries } from "./efibootmgr.schema";
import { logger } from "./logger";
export async function startListeners(
config: z.output<typeof ConfigSchema>,
mqttClient: MqttClient,
bootEntries: z.output<typeof BootEntries>,
) {
await mqttClient.subscribeAsync(`efibootmgr-mqtt/${config.device.key}/+`);
mqttClient.on("message", async (topic, payload) => {
logger.info(topic, payload);
logger.info(topic, payload.toString());
const pathParts = topic.split("/");
const action = pathParts[pathParts.length - 1];
switch (action) {
/* case "trigger-power": {
await nanoKvmService.triggerPower({});
case "trigger-reboot": {
const bootEntry = bootEntries.find(
({ number }) => Number.parseInt(payload.toString(), 10) === number,
);
if (!bootEntry) {
logger.fatal(
`Requested boot entry "${payload.toString()}" not found - doing nothing.`,
);
}
logger.info(`Rebooting into: ${bootEntry?.label}`);
return;
}
/*
case "trigger-reset": {
await nanoKvmService.triggerReset();