extend action handling
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user