UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

45 lines 2.56 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RetrieveLightEffectsCommandHandler = void 0; const cqrs_1 = require("@nestjs/cqrs"); const _ultimate_govee_data_1 = require("../../../../data"); const auth_1 = require("../../../auth"); const cqrs_2 = require("../../../devices/cqrs"); const retrieve_light_effects_command_1 = require("../commands/retrieve-light-effects.command"); let RetrieveLightEffectsCommandHandler = class RetrieveLightEffectsCommandHandler { constructor(eventBus, queryBus, api, diyApi) { this.eventBus = eventBus; this.queryBus = queryBus; this.api = api; this.diyApi = diyApi; } async execute(command) { const authData = await this.queryBus.execute(new auth_1.AuthDataQuery()); if (!authData) { return; } const [effects, diys] = await Promise.all([ this.api.getEffects(authData, command.device.model, command.device.goodsType, command.device.id), this.diyApi.getDiyEffects(authData, command.device.model, command.device.goodsType, command.device.id), ]); this.eventBus.publish(new cqrs_2.LightEffectsReceivedEvent(command.device.id, effects ?? [], diys ?? [])); } }; exports.RetrieveLightEffectsCommandHandler = RetrieveLightEffectsCommandHandler; exports.RetrieveLightEffectsCommandHandler = RetrieveLightEffectsCommandHandler = __decorate([ (0, cqrs_1.CommandHandler)(retrieve_light_effects_command_1.RetrieveLightEffectsCommand), __metadata("design:paramtypes", [cqrs_1.EventBus, cqrs_1.QueryBus, _ultimate_govee_data_1.GoveeEffectService, _ultimate_govee_data_1.GoveeDiyService]) ], RetrieveLightEffectsCommandHandler); //# sourceMappingURL=retrieve-light-effects.handler.js.map