UNPKG

lavva.exalushome.extalife

Version:

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

337 lines 17.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 { DataFrame, Method, Status } from "lavva.exalushome/build/js/DataFrame"; import { ResponseResult } from "lavva.exalushome/build/js/Services/FieldChangeResult"; import { GetChannelParamsRequest } from "../Common/DataRequest"; import { OnOffSwitchService, SwitchConfigurationErrorCode } from "../Common/OnOffSwitchConfigurations/OnOffSwitchService"; import { InputOutputDimmerParameters } from "./Rdp21ConfigParameters"; export class Rdp21ConfigService extends OnOffSwitchService { constructor() { super(); } GetServiceName() { return Rdp21ConfigService.ServiceName; } GetDimmerInputOutputParamAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; try { if (!device.Channels.any(ch => ch.Number === channel)) return new ResponseResult(SwitchConfigurationErrorCode.InvalidChannelNumber, `Cannot get input/output parameters - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetDimmerInputOutputParamRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get input/output parameters - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get input/output parameters - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get input/output parameters - no data in response.`); const dataResult = result.Data.first(); const returnObj = new InputOutputDimmerParameters(); returnObj.Channel = dataResult.Channel; returnObj.InputModeDimmer = dataResult.InputModeDimmer; return returnObj; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get input/output parameters - unknown error.`); } }); } SetDimmerInputOutputParamAsync(device, params) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const request = new InputOutputDimmerParametersFrame(); request.DeviceGuid = device.Guid; request.Channel = params.Channel; request.InputModeDimmer = params.InputModeDimmer; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetDimmerInputOutputParamRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set input/output parameters - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set input/output parameters, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetBrighteningTimeAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; try { if (!device.Channels.any(ch => ch.Number === channel)) return new ResponseResult(SwitchConfigurationErrorCode.InvalidChannelNumber, `Cannot get brightening time - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetBrighteningTimeRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get brightening time - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get brightening time - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get brightening time - no data in response.`); return result.Data.State; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get brightening time - unknown error.`); } }); } SetBrighteningTimeAsync(device, channel, time) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const request = new DimmerSettingsParameters(); request.DeviceGuid = device.Guid; request.Channel = channel; request.State = time; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetBrighteningTimeRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set brightening time - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set brightening time, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetDimmingTimeAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; try { if (!device.Channels.any(ch => ch.Number === channel)) return new ResponseResult(SwitchConfigurationErrorCode.InvalidChannelNumber, `Cannot get dimming time - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetDimmingTimeRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get dimming time - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get dimming time - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get dimming time - no data in response.`); return result.Data.State; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get dimming time - unknown error.`); } }); } SetDimmingTimeAsync(device, channel, time) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const request = new DimmerSettingsParameters(); request.DeviceGuid = device.Guid; request.Channel = channel; request.State = time; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetDimmingTimeRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set dimming time - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set dimming time, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetMinLevelAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; try { if (!device.Channels.any(ch => ch.Number === channel)) return new ResponseResult(SwitchConfigurationErrorCode.InvalidChannelNumber, `Cannot get mimimum light level - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetMinLightLevelRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get mimimum light level - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get mimimum light level - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get mimimum light level - no data in response.`); return result.Data.State; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get mimimum light level - unknown error.`); } }); } SetMinLevelAsync(device, channel, level) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const request = new DimmerSettingsParameters(); request.DeviceGuid = device.Guid; request.Channel = channel; request.State = level; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetMinLightLevelRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set mimimum light level - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set mimimum light level, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetMaxLevelAsync(device, channel) { return __awaiter(this, void 0, void 0, function* () { var _a; try { if (!device.Channels.any(ch => ch.Number === channel)) return new ResponseResult(SwitchConfigurationErrorCode.InvalidChannelNumber, `Cannot get maximum light level - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetMaxLightLevelRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get maximum light level - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get maximum light level - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get maximum light level - no data in response.`); return result.Data.State; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get maximum light level - unknown error.`); } }); } SetMaxLevelAsync(device, channel, level) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const request = new DimmerSettingsParameters(); request.DeviceGuid = device.Guid; request.Channel = channel; request.State = level; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetMaxLightLevelRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set maximum light level - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set maximum light level, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } } Rdp21ConfigService.ServiceName = "Rdp21ConfigService"; class DimmerSettingsParameters { constructor() { this.Channel = 0; this.DeviceGuid = ""; this.State = 0; this.StateOptional = 0; } } //Input/output class InputOutputDimmerParametersFrame extends InputOutputDimmerParameters { constructor() { super(...arguments); this.DeviceGuid = ""; } } class GetDimmerInputOutputParamRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/input/output"; this.Method = Method.Get; this.Data = data; } } class SetDimmerInputOutputParamRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/input/output"; this.Method = Method.Put; this.Data = data; } } //BrighteningTime class GetBrighteningTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/brightening/time"; this.Method = Method.Get; this.Data = data; } } class SetBrighteningTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/brightening/time"; this.Method = Method.Put; this.Data = data; } } //DimmingTimeAsync class GetDimmingTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/dimming/time"; this.Method = Method.Get; this.Data = data; } } class SetDimmingTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/dimming/time"; this.Method = Method.Put; this.Data = data; } } //MinLightLevel class GetMinLightLevelRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/min/level"; this.Method = Method.Get; this.Data = data; } } class SetMinLightLevelRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/min/level"; this.Method = Method.Put; this.Data = data; } } //MaxLightLevel class GetMaxLightLevelRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/max/level"; this.Method = Method.Get; this.Data = data; } } class SetMaxLightLevelRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/max/level"; this.Method = Method.Put; this.Data = data; } } //# sourceMappingURL=Rdp21ConfigService.js.map