UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

32 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceFactory = void 0; class DeviceFactory { constructor(typeConstructor, matchers) { this.typeConstructor = typeConstructor; this.matchers = matchers; DeviceFactory.factories.push(this); } create(device, eventBus, commandBus) { const categoryMatches = this.matchers[device.category]; if (categoryMatches === undefined) { return undefined; } const groupMatches = categoryMatches[device.categoryGroup]; if (groupMatches === undefined) { return undefined; } if (typeof groupMatches !== 'boolean') { const patternMatches = (Array.isArray(groupMatches) ? groupMatches : [groupMatches]).find((pattern) => device.modelName.match(pattern)); if (patternMatches === undefined) { return undefined; } } const constructor = this.typeConstructor; const newDevice = new constructor(device, eventBus, commandBus); return newDevice; } } exports.DeviceFactory = DeviceFactory; DeviceFactory.factories = []; //# sourceMappingURL=device.factory.js.map