UNPKG

lavva.exalushome.extalife

Version:

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

217 lines 13.3 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 { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame"; import { GetParamsErrorCode } from "../../../ExtaLife"; import { Rcz21ConfigParams } from "./Rcz21ConfigParams"; import { DependencyContainer } from "lavva.exalushome/build/js/DependencyContainer"; import { ResponseResult } from "lavva.exalushome/build/js/Services/FieldChangeResult"; import { GetParamsRequest } from "../Common/DataRequest"; export class Rcz21ConfigService { constructor() { this._connection = null; this._connection = Api.Get(ExalusConnectionService.ServiceName); } GetServiceName() { return Rcz21ConfigService.ServiceName; } GetAllParamsAsync(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 GetFloodSensorParamsRequest(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}`); }); } SetAllParamsAsync(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 SetFloodSensorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_b = DependencyContainer.Log) === null || _b === void 0 ? void 0 : _b.Error(Rcz21ConfigService.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(Rcz21ConfigService.ServiceName, `Failed to change device parameters, response status: ${result.Status}`); return result.Status; }); } SetFloodAlertModeAsync(device, channel, alarmMode) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { const currentConfig = yield this.GetCurrentConfig(device.Guid); let params = new Rcz21ConfigParams(); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcz21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } params.DeviceGuid = device.Guid; params.AlertMode = alarmMode; params.RepeatFloodEvent = currentConfig.RepeatFloodEvent; params.RepeatFloodEventTime = currentConfig.RepeatFloodEventTime; params.SyncTime = currentConfig.SyncTime; params.WorkingMode = currentConfig.WorkingMode; const result = yield ((_b = this._connection) === null || _b === void 0 ? void 0 : _b.SendAndWaitForResponseAsync(new SetFloodSensorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcz21ConfigService.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(Rcz21ConfigService.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(Rcz21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetFloodEventRepetitionAsync(device, channel, repeatEvent) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { const currentConfig = yield this.GetCurrentConfig(device.Guid); let params = new Rcz21ConfigParams(); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcz21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device.`); return Status.ResourceIsNotAvailable; } params.DeviceGuid = device.Guid; params.RepeatFloodEvent = repeatEvent; params.AlertMode = currentConfig.AlertMode; params.RepeatFloodEventTime = currentConfig.RepeatFloodEventTime; params.SyncTime = currentConfig.SyncTime; params.WorkingMode = currentConfig.WorkingMode; const result = yield ((_b = this._connection) === null || _b === void 0 ? void 0 : _b.SendAndWaitForResponseAsync(new SetFloodSensorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcz21ConfigService.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(Rcz21ConfigService.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(Rcz21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetFloodEventRepetitionTimeAsync(device, channel, repeatTime) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { const currentConfig = yield this.GetCurrentConfig(device.Guid); let params = new Rcz21ConfigParams(); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcz21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } params.DeviceGuid = device.Guid; params.RepeatFloodEventTime = repeatTime; params.AlertMode = currentConfig.AlertMode; params.RepeatFloodEvent = currentConfig.RepeatFloodEvent; params.SyncTime = currentConfig.SyncTime; params.WorkingMode = currentConfig.WorkingMode; const result = yield ((_b = this._connection) === null || _b === void 0 ? void 0 : _b.SendAndWaitForResponseAsync(new SetFloodSensorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcz21ConfigService.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(Rcz21ConfigService.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(Rcz21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } SetSynchronizationTimeAsync(device, channel, syncTime) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; try { const currentConfig = yield this.GetCurrentConfig(device.Guid); let params = new Rcz21ConfigParams(); if (currentConfig === null) { (_a = DependencyContainer.Log) === null || _a === void 0 ? void 0 : _a.Error(Rcz21ConfigService.ServiceName, `Failed to change device parameters - cannot read current configuration of device`); return Status.ResourceIsNotAvailable; } params.DeviceGuid = device.Guid; params.SyncTime = syncTime; params.AlertMode = currentConfig.AlertMode; params.RepeatFloodEvent = currentConfig.RepeatFloodEvent; params.RepeatFloodEventTime = currentConfig.RepeatFloodEventTime; params.WorkingMode = currentConfig.WorkingMode; const result = yield ((_b = this._connection) === null || _b === void 0 ? void 0 : _b.SendAndWaitForResponseAsync(new SetFloodSensorParamsRequest(params), 35000, false)); if (result == null || result.Status == null) { (_c = DependencyContainer.Log) === null || _c === void 0 ? void 0 : _c.Error(Rcz21ConfigService.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(Rcz21ConfigService.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(Rcz21ConfigService.ServiceName, `Cannot change device parameters. ${error}`); return Status.FatalError; } }); } GetCurrentConfig(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 GetFloodSensorParamsRequest(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!`); }); } } Rcz21ConfigService.ServiceName = "Rcz21ConfigService"; class GetFloodSensorParamsRequest extends DataFrame { constructor(guid) { super(); this.Resource = "/extalife/device/parameters/floodsensor"; this.Method = Method.Get; this.Data = new GetParamsRequest(guid); } } class SetFloodSensorParamsRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/floodsensor"; this.Method = Method.Put; this.Data = data; } } //# sourceMappingURL=Rcz21ConfigService.js.map