UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

57 lines 3.28 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 RestChannelSagas_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.RestChannelSagas = void 0; const common_1 = require("@nestjs/common"); const cqrs_1 = require("@nestjs/cqrs"); const rxjs_1 = require("rxjs"); const events_1 = require("./events"); const configure_rest_channel_command_1 = require("./commands/configure-rest-channel.command"); const retrieve_device_list_command_1 = require("./commands/retrieve-device-list.command"); let RestChannelSagas = RestChannelSagas_1 = class RestChannelSagas { constructor(eventBus) { this.eventBus = eventBus; this.logger = new common_1.Logger(RestChannelSagas_1.name); this.refreshInterval = undefined; this.configureRestChannelFlow = (events$) => events$.pipe((0, cqrs_1.ofType)(events_1.RestChannelConfigReceivedEvent), (0, rxjs_1.map)((event) => new configure_rest_channel_command_1.ConfigureRestChannelCommand(event.config))); this.configurationChangedFlow = (events$) => events$.pipe((0, cqrs_1.ofType)(events_1.RestChannelChangedEvent), (0, rxjs_1.tap)(() => { if (this.refreshInterval !== undefined) { this.refreshInterval = setInterval(() => this.eventBus.publish(new events_1.RefreshDeviceListEvent()), 3 * 60 * 60 * 1000); } }), (0, rxjs_1.map)(() => new retrieve_device_list_command_1.RetrieveDeviceListCommand())); this.refreshDeviceList = (events$) => events$.pipe((0, cqrs_1.ofType)(events_1.RefreshDeviceListEvent), (0, rxjs_1.auditTime)(30000), (0, rxjs_1.map)(() => new retrieve_device_list_command_1.RetrieveDeviceListCommand())); } onModuleDestroy() { if (this.refreshInterval !== undefined) { clearInterval(this.refreshInterval); this.refreshInterval = undefined; } } }; exports.RestChannelSagas = RestChannelSagas; __decorate([ (0, cqrs_1.Saga)(), __metadata("design:type", Object) ], RestChannelSagas.prototype, "configureRestChannelFlow", void 0); __decorate([ (0, cqrs_1.Saga)(), __metadata("design:type", Object) ], RestChannelSagas.prototype, "configurationChangedFlow", void 0); __decorate([ (0, cqrs_1.Saga)(), __metadata("design:type", Object) ], RestChannelSagas.prototype, "refreshDeviceList", void 0); exports.RestChannelSagas = RestChannelSagas = RestChannelSagas_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [cqrs_1.EventBus]) ], RestChannelSagas); //# sourceMappingURL=rest-channel.sagas.js.map