UNPKG

klf-200-api

Version:

This module provides a wrapper to the socket API of a Velux KLF-200 interface. You will need at least firmware 0.2.0.0.71 on your KLF interface for this library to work.

27 lines 1.05 kB
"use strict"; import { dirname, resolve } from "path"; import { fileURLToPath } from "url"; import { GatewayCommand } from "./common.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export class FrameRcvFactory { static async CreateRcvFrame(Buff) { const CommandName = GatewayCommand[Buff.readUInt16BE(1)]; await this.LoadModule(CommandName); const typeToCreate = this.modules[CommandName][CommandName]; if (typeToCreate === undefined) throw new Error(`Unknown command ${CommandName}.`); return new typeToCreate(Buff); } static modules = {}; static async LoadModule(moduleName) { if (!this.modules[moduleName]) { let modulePath = resolve(__dirname, moduleName + ".js"); if (!modulePath.startsWith("file://")) { modulePath = `file://${modulePath}`; } this.modules[moduleName] = await import(modulePath); } } } //# sourceMappingURL=FrameRcvFactory.js.map