lavva.exalushome.extalife
Version:
Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system
135 lines • 7.62 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 { Api } from "lavva.exalushome";
import { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame";
import { ControllerConfigurationService } from "lavva.exalushome/build/js/Services/Controller/ControllerConfigurationService";
import { ExalusConnectionService } from "lavva.exalushome/build/js/Services/ExalusConnectionService";
import { ResponseResult } from "lavva.exalushome/build/js/Services/FieldChangeResult";
import { LoggerService } from "lavva.exalushome/build/js/Services/Logging/LoggerService";
import { GetParamsErrorCode } from "../../../ExtaLife";
import { WindAndBrightnessThresholds } from "./WszfBidiConfigParams";
export class WszfBidiConfigService {
constructor() {
this._connection = Api.Get(ExalusConnectionService.ServiceName);
this._logger = Api.Get(LoggerService.ServiceName);
this._controllerConfigurationService = Api.Get(ControllerConfigurationService.ServiceName);
}
GetServiceName() {
return WszfBidiConfigService.ServiceName;
}
GetBrightnessAndWindThresholdAsync(device, channel) {
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 GetWindAndBrightnessThresholds(device.Guid), 8000, false));
if (result == null || result.Status == null || result.Data == null)
return new ResponseResult(GetParamsErrorCode.OtherError, `Cannot get brightness threshold - unknown error.`);
if (result.Status !== Status.OK)
return new ResponseResult(GetParamsErrorCode.OtherError, `Cannot get brightness threshold - controller responded with error code: ${result.Status}.`);
const returnRes = new WindAndBrightnessThresholds();
returnRes.BrightnessThreshold = result.Data.BrightnessThreshold;
returnRes.WindThreshold = result.Data.WindThreshold;
return returnRes;
}
catch (error) {
return new ResponseResult(GetParamsErrorCode.OtherError, `Cannot get brightness threshold - unknown error.`);
}
});
}
SetBrightnessThresholdAsync(device, channel, threshold) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const currentConfig = yield this.GetBrightnessAndWindThresholdAsync(device, channel);
if (currentConfig.Type != null) {
this._logger.Error(WszfBidiConfigService.ServiceName, `Failed to set brightness threshold parameter - cannot get current configuration.`);
return Status.Error;
}
yield this._controllerConfigurationService.EnterConfigurationModeAsync();
const request = new WindAndBrightnessThresholdsFrame();
request.DeviceGuid = device.Guid;
request.BrightnessThreshold = threshold;
request.WindThreshold = currentConfig.WindThreshold;
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetWindAndBrightnessThresholds(request), 8000, false));
if (result == null || result.Status == null) {
this._logger.Error(WszfBidiConfigService.ServiceName, `Failed to set brightness threshold parameter- unknow error.`);
return Status.FatalError;
}
if (result.Status !== Status.OK)
this._logger.Error(WszfBidiConfigService.ServiceName, `Failed to set brightness threshold parameter, response status: ${result.Status}`);
return result.Status;
}
catch (error) {
return Status.FatalError;
}
finally {
this._logger.Error(WszfBidiConfigService.ServiceName, `EXIT CONFIGURATION MODE WILL BE FIRED! SetBrightnessThresholdAsync()`);
yield this._controllerConfigurationService.ExitConfigurationModeAsync();
}
});
}
SetWindThresholdAsync(device, channel, threshold) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
const currentConfig = yield this.GetBrightnessAndWindThresholdAsync(device, channel);
if (currentConfig.Type != null) {
this._logger.Error(WszfBidiConfigService.ServiceName, `Failed to set wind threshold parameter - cannot get current configuration.`);
return Status.Error;
}
yield this._controllerConfigurationService.EnterConfigurationModeAsync();
const request = new WindAndBrightnessThresholdsFrame();
request.DeviceGuid = device.Guid;
request.BrightnessThreshold = currentConfig.BrightnessThreshold;
request.WindThreshold = threshold;
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetWindAndBrightnessThresholds(request), 8000, false));
if (result == null || result.Status == null) {
this._logger.Error(WszfBidiConfigService.ServiceName, `Failed to set wind threshold parameter- unknow error.`);
return Status.FatalError;
}
if (result.Status !== Status.OK)
this._logger.Error(WszfBidiConfigService.ServiceName, `Failed to set wind threshold parameter, response status: ${result.Status}`);
return result.Status;
}
catch (error) {
return Status.FatalError;
}
finally {
this._logger.Error(WszfBidiConfigService.ServiceName, `EXIT CONFIGURATION MODE WILL BE FIRED! SetWindThresholdAsync()`);
yield this._controllerConfigurationService.ExitConfigurationModeAsync();
}
});
}
}
WszfBidiConfigService.ServiceName = "WszfBidiConfigService";
class WindAndBrightnessThresholdsFrame extends WindAndBrightnessThresholds {
constructor() {
super(...arguments);
this.DeviceGuid = "";
}
}
//WindAndBrightness
class GetWindAndBrightnessThresholds extends DataFrame {
constructor(guid) {
super();
this.Resource = "/extalife/device/parameters/threshold/windbrightness/";
this.Method = Method.Get;
this.Data = guid;
}
}
class SetWindAndBrightnessThresholds extends DataFrame {
constructor(data) {
super();
this.Resource = "/extalife/device/parameters/threshold/windbrightness/";
this.Method = Method.Put;
this.Data = data;
}
}
//# sourceMappingURL=WszfBidiConfigService.js.map