UNPKG

lavva.exalushome.portos

Version:

Library implementing communication and abstraction layers for Portos 433MHz API in ExalusHome system

63 lines 3.15 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Api } from "lavva.exalushome"; import { ExalusConnectionService } from "lavva.exalushome/build/js/Services/ExalusConnectionService"; import { LoggerService } from "lavva.exalushome/build/js/Services/Logging/LoggerService"; import { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame"; export class Portos433ConfigService { constructor() { this._connection = Api.Get(ExalusConnectionService.ServiceName); this._logger = Api.Get(LoggerService.ServiceName); } GetServiceName() { return Portos433ConfigService.ServiceName; } SendP2PairingSignalAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; try { if (!device.Channels.any(ch => ch.Number === channel)) { this._logger.Error(Portos433ConfigService.ServiceName, `Cannot pair channel. Wrong channel number.`); return Status.WrongData; } const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new P2ProgrammingPairRequest(new ChannelPair(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(Portos433ConfigService.ServiceName, `Cannot pair channel. Controller response does not contain data.`); return Status.Error; } if (result.Status !== Status.OK) this._logger.Error(Portos433ConfigService.ServiceName, `Cannot pair channel. Controller responede with status code: ${result.Status}`); return result.Status; } catch (error) { this._logger.Error(Portos433ConfigService.ServiceName, `Cannot pair channel. ${error}`); return Status.FatalError; } }); } } Portos433ConfigService.ServiceName = "Portos433ConfigService"; class P2ProgrammingPairRequest extends DataFrame { constructor(data) { super(); this.Resource = "/portos/devices/device/channel/pair"; this.Method = Method.Put; this.Data = data; } } class ChannelPair { constructor(deviceGuid, channel) { this.DeviceGuid = ""; this.Channel = 0; this.DeviceGuid = deviceGuid; this.Channel = channel; } } //# sourceMappingURL=Portos433ConfigService.js.map