lavva.exalushome.extalife
Version:
Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system
223 lines • 12.9 kB
JavaScript
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 { ResponseResult, FieldChangeResultType } from "lavva.exalushome/build/js/Services/FieldChangeResult";
import { GetParamsErrorCode } from "../../../ExtaLife";
import { SbrAlarmLightDelay, SbrAlarmLightDuration, SbrAutoCloseTime } from "./ISbrConfigService";
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 { ControllerConfigurationService } from "lavva.exalushome/build/js/Services/Controller/ControllerConfigurationService";
import { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame";
export class SbrConfigService {
constructor() {
this._connection = Api.Get(ExalusConnectionService.ServiceName);
this._logger = Api.Get(LoggerService.ServiceName);
this._controllerConfigurationService = Api.Get(ControllerConfigurationService.ServiceName);
}
GetServiceName() {
return SbrConfigService.ServiceName;
}
SetAutoCloseTimeAsync(deviceChannel, timeInMiliseconds, resetOnCrossToOn) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (timeInMiliseconds < 60000 || timeInMiliseconds > 3600000)
return new ResponseResult(FieldChangeResultType.WrongData, `Cannot set auto close time - invalid value. Time must be in range from 60_000 to 3_600_000 ms.`);
this._controllerConfigurationService.EnterConfigurationModeAsync();
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetAutoCloseTimeRequest(deviceChannel, timeInMiliseconds, resetOnCrossToOn), 8000, false));
this._logger.Error(SbrConfigService.ServiceName, `EXIT CONFIGURATION MODE WILL BE FIRED! SetAutoCloseTimeAsync()`);
this._controllerConfigurationService.ExitConfigurationModeAsync();
if (result == null || result.Status == null)
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot set auto close time - unknown error.`);
if (result.Status !== Status.OK)
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot set auto close time - controller responded with error code: ${result.Status}.`);
return new ResponseResult(FieldChangeResultType.Changed, `Auto close time set successfully.`);
}
catch (error) {
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot get auto close time - unknown error.`);
}
});
}
GetAutoCloseTimeAsync(deviceChannel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetAutoCloseTimeRequest(deviceChannel), 8000, false));
switch (result === null || result === void 0 ? void 0 : result.Status) {
case Status.OK:
return result.Data;
default:
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get auto close time`);
}
}
catch (error) {
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get auto close time error: ${error}`);
}
});
}
SetAlarmLightDelayAsync(deviceChannel, lightDelayInMiliseconds) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (lightDelayInMiliseconds < 0 || lightDelayInMiliseconds > 120000)
return new ResponseResult(FieldChangeResultType.WrongData, `Cannot set light delay time - invalid value. Time must be in range from 60_000 to 3_600_000 ms.`);
this._controllerConfigurationService.EnterConfigurationModeAsync();
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetAlarmLightDelayRequest(deviceChannel, lightDelayInMiliseconds), 8000, false));
this._logger.Error(SbrConfigService.ServiceName, `EXIT CONFIGURATION MODE WILL BE FIRED! SetAlarmLightDelayAsync()`);
this._controllerConfigurationService.ExitConfigurationModeAsync();
if (result == null || result.Status == null)
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot set light delay time - unknown error.`);
if (result.Status !== Status.OK)
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot set light delay time - controller responded with error code: ${result.Status}.`);
return new ResponseResult(FieldChangeResultType.Changed, `Light delay set successfully.`);
}
catch (error) {
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot get light delay time - unknown error.`);
}
});
}
GetAlarmLightDelayAsync(deviceChannel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetAlarmLightDelayRequest(deviceChannel), 8000, false));
switch (result === null || result === void 0 ? void 0 : result.Status) {
case Status.OK:
return result.Data;
default:
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get light delay time`);
}
}
catch (error) {
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get auto light delay error: ${error}`);
}
});
}
SetAlarmLightDurationAsync(deviceChannel, lightDurationInMiliseconds) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (lightDurationInMiliseconds < 0 || lightDurationInMiliseconds > 3600000)
return new ResponseResult(FieldChangeResultType.WrongData, `Cannot set alarm light duration time - invalid value. Time must be in range from 60_000 to 3_600_000 ms.`);
this._controllerConfigurationService.EnterConfigurationModeAsync();
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetAlarmLightDurationRequest(deviceChannel, lightDurationInMiliseconds), 8000, false));
this._logger.Error(SbrConfigService.ServiceName, `EXIT CONFIGURATION MODE WILL BE FIRED! SetAlarmLightDurationAsync()`);
this._controllerConfigurationService.ExitConfigurationModeAsync();
if (result == null || result.Status == null)
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot set alarm light duration time - unknown error.`);
if (result.Status !== Status.OK)
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot set alarm light duration time - controller responded with error code: ${result.Status}.`);
return new ResponseResult(FieldChangeResultType.Changed, `Alarm light duration set successfully.`);
}
catch (error) {
return new ResponseResult(FieldChangeResultType.UnknownError, `Cannot get alarm light duration time - unknown error.`);
}
});
}
GetAlarmLightDurationAsync(deviceChannel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetAlarmLightDurationRequest(deviceChannel), 8000, false));
switch (result === null || result === void 0 ? void 0 : result.Status) {
case Status.OK:
return result.Data;
default:
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get light delay time`);
}
}
catch (error) {
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get auto light delay error: ${error}`);
}
});
}
GetServiceInfoAsync(deviceChannel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetServiceInfoRequest(deviceChannel), 8000, false));
switch (result === null || result === void 0 ? void 0 : result.Status) {
case Status.OK:
return result.Data;
default:
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get service info, response status: ${result === null || result === void 0 ? void 0 : result.Status}`);
}
}
catch (error) {
return new ResponseResult(GetParamsErrorCode.UnknownError, `Cannot get service info error: ${error}`);
}
});
}
}
SbrConfigService.ServiceName = "SbrConfigService";
class GetAutoCloseTimeRequest extends DataFrame {
constructor(deviceChannel) {
super();
this.Resource = "/extalife/device/parameters/sbr/autoclosetime";
this.Method = Method.Get;
this.Data = deviceChannel.GetDevice().Guid;
}
}
class SetAutoCloseTimeRequest extends DataFrame {
constructor(DeviceChannel, timeInMiliseconds, resetOnCrossToOn) {
super();
this.Resource = "/extalife/device/parameters/sbr/autoclosetime";
this.Method = Method.Put;
this.Data = new SbrAutoCloseTime();
this.Data.DeviceGuid = DeviceChannel.GetDevice().Guid;
this.Data.TimeInMiliseconds = timeInMiliseconds;
this.Data.ResetOnCrossToOn = resetOnCrossToOn;
}
}
class GetAlarmLightDelayRequest extends DataFrame {
constructor(deviceChannel) {
super();
this.Resource = "/extalife/device/parameters/sbr/alarmlightdelay";
this.Method = Method.Get;
this.Data = deviceChannel.GetDevice().Guid;
}
}
class SetAlarmLightDelayRequest extends DataFrame {
constructor(DeviceChannel, lightDelayInMiliseconds) {
super();
this.Resource = "/extalife/device/parameters/sbr/alarmlightdelay";
this.Method = Method.Put;
this.Data = new SbrAlarmLightDelay();
this.Data.DeviceGuid = DeviceChannel.GetDevice().Guid;
this.Data.LightDelayInMiliseconds = lightDelayInMiliseconds;
}
}
class GetAlarmLightDurationRequest extends DataFrame {
constructor(deviceChannel) {
super();
this.Resource = "/extalife/device/parameters/sbr/lightduration";
this.Method = Method.Get;
this.Data = deviceChannel.GetDevice().Guid;
}
}
class SetAlarmLightDurationRequest extends DataFrame {
constructor(DeviceChannel, lightDurationInMiliseconds) {
super();
this.Resource = "/extalife/device/parameters/sbr/lightduration";
this.Method = Method.Put;
this.Data = new SbrAlarmLightDuration();
this.Data.DeviceGuid = DeviceChannel.GetDevice().Guid;
this.Data.LightDurationInMiliseconds = lightDurationInMiliseconds;
}
}
class GetServiceInfoRequest extends DataFrame {
constructor(deviceChannel) {
super();
this.Resource = "/extalife/device/parameters/sbr/serviceinfo";
this.Method = Method.Get;
this.Data = deviceChannel.GetDevice().Guid;
}
}
//# sourceMappingURL=SbrConfigService.js.map