UNPKG

lavva.exalushome.extalife

Version:

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

439 lines 24.4 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 { ResponseResult } from "lavva.exalushome/build/js/Services/FieldChangeResult"; import { MoveSensorMode } from "./Rcr21ConfigParams"; import { GetParamsErrorCode } from "../../../ExtaLife"; import { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame"; import { GetParamsRequest } from "../Common/DataRequest"; import { DependencyContainer } from "lavva.exalushome/build/js/DependencyContainer"; export class Rcr21ConfigService { constructor() { this._connection = null; this._connection = Api.Get(ExalusConnectionService.ServiceName); } GetServiceName() { return Rcr21ConfigService.ServiceName; } GetPirSensorParamsAsync(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 GetPirSensorParamsRequest(device.Guid), 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; } 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}`); }); } SetDetectionThresholdAsync(device, channel, detectionThreshold) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentPirParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } if (currentConfig.PredefinedSettings != 0) return Status.OperationNotPermitted; const params = Object.assign({}, currentConfig); params.DetectionThreshold = detectionThreshold; return this.SetPirSensorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetWindowTimeAsync(device, channel, windowTime) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentPirParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } if (currentConfig.PredefinedSettings != 0) return Status.OperationNotPermitted; const params = Object.assign({}, currentConfig); params.WindowTime = windowTime; return this.SetPirSensorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetDetectionAsync(device, channel, detection) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentPirParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } if (currentConfig.PredefinedSettings != 0) return Status.OperationNotPermitted; const params = Object.assign({}, currentConfig); params.Detection = detection; return this.SetPirSensorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetPredefinedSettingsAsync(device, channel, predefinedSettings) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentPirParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.PredefinedSettings = predefinedSettings; //Workaround - in case when we set predefinedSettings to 0 we need also to change one of rest parameters... otherwise it doesn't work. if (predefinedSettings === 0) params.DetectionThreshold >= 1 ? params.DetectionThreshold-- : params.DetectionThreshold++; return this.SetPirSensorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } GetMovementDetectorParamsAsync(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 GetMovementDetectorParamsRequest(device.Guid), 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) { if (result.Data.SensorMode == MoveSensorMode.DayMode) result.Data.CurrentLuxValue -= 65; return result.Data; } 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}`); }); } SetOffTimeAsync(device, channel, offTime) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } if (offTime < 10 || offTime > 3600) return Status.WrongData; const params = Object.assign({}, currentConfig); params.OffTime = offTime; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetLuxSettingAsync(device, channel, luxSetting) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.LuxSetting = luxSetting; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetSynchronizationTimeAsync(device, channel, syncTime) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.SyncTime = syncTime; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetAccTamperEventAsync(device, channel, tamperEvent) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.AccEvent = tamperEvent; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetAccLevelAsync(device, channel, accLevel) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.AccLevel = accLevel; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetSensorModeAsync(device, channel, sensorMode) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.SensorMode = sensorMode; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetExternalOutModeAsync(device, channel, externalOutputMode) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.ExternalOutMode = externalOutputMode; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetOpticalLEDSignalizationAsync(device, channel, opticalLEDSignalization) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.OpticalLEDSignalization = opticalLEDSignalization; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetMoveLEDSignalizationAsync(device, channel, moveLEDSignalization) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; try { const currentConfig = yield this.GetCurrentMovementDetectorParamsAsync(device.Guid); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } const params = Object.assign({}, currentConfig); params.MoveLEDSignalization = moveLEDSignalization; return this.SetMovementDetectorParamsAsync(params, channel); } catch (error) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } GetCurrentPirParamsAsync(deviceGuid) { 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 GetPirSensorParamsRequest(deviceGuid), 35000, false)); if (result === null || result === undefined) return null; switch (result.Status) { case Status.OK: if (result.Data != null) { return result.Data; } break; case Status.ResourceIsNotAvailable: return null; } throw new Error(`Failed to read current configuration of device! No data in response.`); }); } GetCurrentMovementDetectorParamsAsync(deviceGuid) { 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 GetMovementDetectorParamsRequest(deviceGuid), 35000, false)); if (result === null || result === undefined) return null; switch (result.Status) { case Status.OK: if (result.Data != null) { return result.Data; } break; case Status.ResourceIsNotAvailable: return null; } throw new Error(`Failed to read current configuration of device! No data in response.`); }); } SetPirSensorParamsAsync(params, channel) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetPirSensorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters, response status: ${result.Status}`); return result.Status; }); } SetMovementDetectorParamsAsync(params, channel) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetMovementDetectorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcr21ConfigService.ServiceName, `Failed to change device parameters, response status: ${result.Status}`); return result.Status; }); } ClearTamperAlarmAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new ClearTamperAlarmRequest(device.Guid), 35000, false)); if (result == null || result.Status == null) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcr21ConfigService.ServiceName, `Failed to clear tamper alarm - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcr21ConfigService.ServiceName, `Failed to clear tamper alarm, response status: ${result.Status}`); return result.Status; }); } } Rcr21ConfigService.ServiceName = "Rcr21ConfigService"; class GetPirSensorParamsRequest extends DataFrame { constructor(guid) { super(); this.Resource = "/extalife/device/parameters/movementsensor/pir"; this.Method = Method.Get; this.Data = new GetParamsRequest(guid); } } class SetPirSensorParamsRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/movementsensor/pir"; this.Method = Method.Put; this.Data = data; } } class GetMovementDetectorParamsRequest extends DataFrame { constructor(guid) { super(); this.Resource = "/extalife/device/parameters/movementsensor/movementdetector"; this.Method = Method.Get; this.Data = new GetParamsRequest(guid); } } class SetMovementDetectorParamsRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/movementsensor/movementdetector"; this.Method = Method.Put; this.Data = data; } } class ClearTamperAlarmRequest extends DataFrame { constructor(guid) { super(); this.Resource = "/extalife/device/movementsensor/tamper/clear"; this.Method = Method.Post; this.Data = new GetParamsRequest(guid); } } //# sourceMappingURL=Rcr21ConfigService.js.map