lavva.exalushome.extalife
Version:
Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system
280 lines • 15 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 { BlindConfigService, BlindConfigurationErrorCode } from "../../../Common/BlindConfigurations/BlindConfigService";
import { WorkMode } from "./ISsrVersionedService";
import { BlindCalibrationState, BlindCalibrationStatusEnum, StateReliability } from "lavva.exalushome/build/js/Services/Devices/IDeviceState";
import { ResponseResult } from "lavva.exalushome/build/js/Services/FieldChangeResult";
import { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame";
import { BlindActionEnum, SetBlindPosition } from "lavva.exalushome/build/js/Services/Devices/Tasks/Tasks";
import { DeviceTaskExecutionResult } from "lavva.exalushome/build/js/Services/Devices/TaskExecutionResult";
import { UsersService } from "lavva.exalushome/build/js/Services/Users/UsersService";
import { Api } from "lavva.exalushome";
import { AccessLevel } from "lavva.exalushome/build/js/Services/Users/IUser";
import { UpdatesProvider } from "lavva.exalushome/build/js/Services/Updates/UpdatesProvider";
export class Ssr_4_0_0_0 extends BlindConfigService {
constructor() {
super();
}
RunAutomaticCalibrationAsync(device, channel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (!device.Channels.any(ch => ch.Number === channel)) {
return new ResponseResult(BlindConfigurationErrorCode.InvalidChannelNumber, `Cannot calibrate blind - invalid channel number: ${channel}`);
}
const task = new SetBlindPosition();
task.Action = BlindActionEnum.Stop;
switch (yield device.Channels.first(ch => ch.Number == channel).ExecuteTaskAsync(task)) {
case DeviceTaskExecutionResult.Executed:
break;
default:
return new ResponseResult(BlindConfigurationErrorCode.DeviceNotResponding, `Cannot calibrate blind - device is not responding.`);
}
const calibrationReq = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new EnableAutoCalibraionRequest(device.Guid), 8000, false));
if (calibrationReq == null || calibrationReq.Status == null)
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot calibrate blind - calibration request failed for an unknown reason.`);
switch (calibrationReq.Status) {
case Status.OK:
{
var r = new BlindCalibrationState();
r.CalibrationStatus = BlindCalibrationStatusEnum.AutoLernInProgress;
r.Channel = channel;
r.StateReliability = StateReliability.Confident;
return r;
}
case Status.Error:
return new ResponseResult(BlindConfigurationErrorCode.CalibrationsIsCurrentlyRunning, `Cannot calibrate blind - calibration is currently running.`);
default:
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot calibrate blind - calibration request failed - request status code: ${calibrationReq.Status}`);
}
}
catch (error) {
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot calibrate blind - fatal error: ${error}`);
}
});
}
GetCorrectionStepAsync(device, channel, correctionType) {
const _super = Object.create(null, {
GetCorrectionStepAsync: { get: () => super.GetCorrectionStepAsync }
});
return __awaiter(this, void 0, void 0, function* () {
try {
const version = yield Api.Get(UpdatesProvider.ServiceName).GetSoftwareRuntimeInfoAsync();
const [major, minor] = version.SoftwareVersion.split(".").map(v => parseInt(v));
if (major >= 7 && minor >= 45) {
const workLog = yield this.GetWorkLogAsyncRaw(device, channel);
if (workLog instanceof ResponseResult)
return workLog;
//if true - manual, false - auto
if (workLog.ManualAutoConfigFlag && correctionType === "UPPER") {
return new ResponseResult(BlindConfigurationErrorCode.NotAvailableInManualMode, `Cannot get correction step - not available in manual mode.`);
}
return _super.GetCorrectionStepAsync.call(this, device, channel, correctionType);
}
else
return _super.GetCorrectionStepAsync.call(this, device, channel, correctionType);
}
catch (error) {
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get correction step - fatal error: ${error}`);
}
});
}
SetCorrectionStepAsync(device, channel, correction, correctionType) {
const _super = Object.create(null, {
SetCorrectionStepAsync: { get: () => super.SetCorrectionStepAsync }
});
return __awaiter(this, void 0, void 0, function* () {
try {
const version = yield Api.Get(UpdatesProvider.ServiceName).GetSoftwareRuntimeInfoAsync();
const [major, minor] = version.SoftwareVersion.split(".").map(v => parseInt(v));
if (major >= 7 && minor >= 45) {
const workLog = yield this.GetWorkLogAsyncRaw(device, channel);
if (workLog instanceof ResponseResult) {
this._logger.Error(`Cannot set correction step - cannot get work log - ${workLog.Type} - ${workLog.Data}`);
return Status.Error;
}
//if true - manual, false - auto
if (workLog.ManualAutoConfigFlag && correctionType === "UPPER") {
this._logger.Warning(`Cannot set correction step - not available in manual mode.`);
return Status.WrongData;
}
return yield _super.SetCorrectionStepAsync.call(this, device, channel, correction, correctionType);
}
else
return yield _super.SetCorrectionStepAsync.call(this, device, channel, correction, correctionType);
}
catch (error) {
this._logger.Error(`Cannot set correction step - fatal error: ${error}`);
return Status.FatalError;
}
});
}
GetHeadSensorStatusAsync(device, channel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (!device.Channels.any(ch => ch.Number === channel))
return new ResponseResult(BlindConfigurationErrorCode.InvalidChannelNumber, `Cannot get head sensor status - invalid channel number: ${channel}`);
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetHeadSensorStatusRequest(device.Guid, channel), 8000, false));
if (result == null || result.Status == null)
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get head sensor status - request failed for an unknown reason.`);
if (result.Status != Status.OK)
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get head sensor status - request failed - request status code: ${result.Status}`);
if (result.Data == null)
return new ResponseResult(BlindConfigurationErrorCode.NoData, `Cannot get head sensor status - request failed - no data received.`);
return result.Data;
}
catch (error) {
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get head sensor status - fatal error: ${error}`);
}
});
}
SwitchHeadSensorStatusAsync(enabled, device, channel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (!device.Channels.any(ch => ch.Number === channel))
return Status.WrongData;
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SwitchHeadSensorStatusRequest(device.Guid, channel, enabled), 8000, false));
if (result == null || result.Status == null)
return Status.FatalError;
return result.Status;
}
catch (error) {
return Status.FatalError;
}
});
}
ChangeMovementDirectionAsync(device, channel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (!device.Channels.any(ch => ch.Number === channel))
return Status.WrongData;
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new ChangeMovementDirectionRequest(device.Guid, channel), 8000, false));
if (result == null || result.Status == null)
return Status.FatalError;
return result.Status;
}
catch (error) {
return Status.FatalError;
}
});
}
GetWorkingModeAsync(device, channel) {
return __awaiter(this, void 0, void 0, function* () {
const version = yield Api.Get(UpdatesProvider.ServiceName).GetSoftwareRuntimeInfoAsync();
const [major, minor] = version.SoftwareVersion.split(".").map(v => parseInt(v));
if (major >= 7 && minor >= 45) {
const workLog = yield this.GetWorkLogAsyncRaw(device, channel);
if (workLog instanceof ResponseResult) {
return workLog;
}
//true - manual, false - auto
if (workLog.ManualAutoConfigFlag) {
return WorkMode.Manual;
}
else {
return WorkMode.Automatic;
}
}
else
return WorkMode.Automatic;
});
}
GetWorkLogAsync(device, channel) {
return __awaiter(this, void 0, void 0, function* () {
try {
const user = yield Api.Get(UsersService.ServiceName).GetUserAsync();
if (user == null || user.AccessLevel < AccessLevel.Support)
return new ResponseResult(BlindConfigurationErrorCode.InsufficientPermissions, `Cannot get head sensor status - current user has insufficient permissions.`);
return yield this.GetWorkLogAsyncRaw(device, channel);
}
catch (error) {
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get work log - fatal error: ${error}`);
}
});
}
GetWorkLogAsyncRaw(device, channel) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
try {
if (!device.Channels.any(ch => ch.Number === channel))
return new ResponseResult(BlindConfigurationErrorCode.InvalidChannelNumber, `Cannot get head sensor status - invalid channel number: ${channel}`);
const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetBlindWorkStats(device.Guid, channel), 8000, false));
if (result == null || result.Status == null)
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get work log - request failed for an unknown reason.`);
if (result.Status != Status.OK)
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get work log - request failed - request status code: ${result.Status}`);
if (result.Data == null)
return new ResponseResult(BlindConfigurationErrorCode.NoData, `Cannot get work log - request failed - no data received.`);
return result.Data;
}
catch (error) {
return new ResponseResult(BlindConfigurationErrorCode.OtherError, `Cannot get work log - fatal error: ${error}`);
}
});
}
}
//Auto calibration
class EnableAutoCalibraionRequest extends DataFrame {
constructor(guid) {
super();
this.Resource = "/extafree2/blind/calibration/auto";
this.Method = Method.Get;
this.Data = guid;
}
}
class GetHeadSensorStatusRequest extends DataFrame {
constructor(guid, channel) {
super();
this.Resource = "/extalife/device/blind/head/sensor/status";
this.Method = Method.Get;
this.Data = {
DeviceGuid: guid,
Channel: channel
};
}
}
class SwitchHeadSensorStatusRequest extends DataFrame {
constructor(guid, channel, enabled) {
super();
this.Resource = "/extalife/device/blind/head/sensor/switch";
this.Method = Method.Put;
this.Data = {
DeviceGuid: guid,
Channel: channel,
Enable: enabled
};
}
}
class ChangeMovementDirectionRequest extends DataFrame {
constructor(guid, channel) {
super();
this.Resource = "/extalife/device/blind/direction/reverse";
this.Method = Method.Post;
this.Data = {
DeviceGuid: guid,
Channel: channel
};
}
}
class GetBlindWorkStats extends DataFrame {
constructor(guid, channel) {
super();
this.Resource = "/extalife/device/blind/work/log";
this.Method = Method.Get;
this.Data = {
DeviceGuid: guid,
Channel: channel
};
}
}
//# sourceMappingURL=SsrVersionedService.js.map