UNPKG

lavva.exalushome.extalife

Version:

Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system

68 lines 4.6 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 { Status } from "lavva.exalushome/build/js/DataFrame"; import { DependencyContainer } from "lavva.exalushome/build/js/DependencyContainer"; import { ResponseResult } from "lavva.exalushome/build/js/Services/FieldChangeResult"; import { GetParamsErrorCode } from "../../../../../ExtaLife"; import { MultisensorDetectionThresholdParams, Rcm21Channels } from "../../Rcm21ConfigParams"; import { Rcm21ConfigService } from "../../Rcm21ConfigService"; import { GetDetectionThresholdParams, Rcm21VersionedService as BaseService, SetDetectionThresholdParamsRequest } from "../^0.0.0.0/Rcm21VersionedService"; export class Rcm21VersionedService extends BaseService { GetHysteresisAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetDetectionThresholdParams(device.Guid, channel.valueOf()), 35000, false)); if (result === null || result === undefined) return new ResponseResult(GetParamsErrorCode.UnknownError, `Failed to retrieve parameters - unknow error.`); switch (result.Status) { case Status.OK: if (result.Data != null) { return result.Data.Hysteresis; } break; case Status.ResourceIsNotAvailable: return new ResponseResult(GetParamsErrorCode.ResourceIsNotAvailable, `Failed to retrieve parameters - cannot communicate with the device.`); } return new ResponseResult(GetParamsErrorCode.OtherError, `Failed to retrieve parameters, response error: ${result.Status} data: ${result.Data}`); }); } SetHysteresisAsync(device, channel, hysteresis) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { if (channel == Rcm21Channels.Unknow) return Status.WrongData; const currentConfig = yield this.GetCurrentDetectionThresholdConfigAsync(device.Guid, channel); let params = new MultisensorDetectionThresholdParams(); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcm21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } params.DeviceGuid = device.Guid; params.Channel = channel; params.Hysteresis = hysteresis; params.Threshold = currentConfig.Threshold; const result = yield ((_b = this._connection) === null || _b === void 0 ? void 0 : _b.SendAndWaitForResponseAsync(new SetDetectionThresholdParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcm21ConfigService.ServiceName, `Failed to change device parameters - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) (_d = DependencyContainer.Log) === null || _d === void 0 ? void 0 : _d.Error(Rcm21ConfigService.ServiceName, `Failed to change device parameters, response status: ${result.Status}`); return result.Status; } catch (error) { (_e = DependencyContainer.Log) === null || _e === void 0 ? void 0 : _e.Error(Rcm21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } } //# sourceMappingURL=Rcm21VersionedService.js.map