UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

47 lines 2.74 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); }; var RetrieveDeviceListCommandHandler_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.RetrieveDeviceListCommandHandler = void 0; const cqrs_1 = require("@nestjs/cqrs"); const _ultimate_govee_data_1 = require("../../../../data"); const common_1 = require("@nestjs/common"); const auth_1 = require("../../../auth"); const commands_1 = require("../commands"); const device_config_received_event_1 = require("../../../devices/cqrs/events/device-config-received.event"); let RetrieveDeviceListCommandHandler = RetrieveDeviceListCommandHandler_1 = class RetrieveDeviceListCommandHandler { constructor(api, queryBus, eventBus) { this.api = api; this.queryBus = queryBus; this.eventBus = eventBus; this.logger = new common_1.Logger(RetrieveDeviceListCommandHandler_1.name); } // eslint-disable-next-line @typescript-eslint/no-unused-vars async execute(_) { const authData = await this.queryBus.execute(new auth_1.AuthDataQuery()); if (authData?.accountAuth?.oauth !== undefined) { this.logger.log('Getting device list'); const deviceList = await this.api.getDeviceList(authData?.accountAuth.oauth); this.logger.log(`Got ${deviceList.length} devices`); deviceList .map((device) => new device_config_received_event_1.DeviceConfigReceivedEvent(device)) .forEach((event) => this.eventBus.publish(event)); } } }; exports.RetrieveDeviceListCommandHandler = RetrieveDeviceListCommandHandler; exports.RetrieveDeviceListCommandHandler = RetrieveDeviceListCommandHandler = RetrieveDeviceListCommandHandler_1 = __decorate([ (0, cqrs_1.CommandHandler)(commands_1.RetrieveDeviceListCommand), __metadata("design:paramtypes", [_ultimate_govee_data_1.GoveeDeviceService, cqrs_1.QueryBus, cqrs_1.EventBus]) ], RetrieveDeviceListCommandHandler); //# sourceMappingURL=retrieve-device-list.handler.js.map