UNPKG

lavva.exalushome.extalife

Version:

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

301 lines 15.2 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 "../DataRequest"; import { GlobalTimeParameters } from "../OnOffSwitchConfigurations/OnOffSwitchParameters"; import { OnOffSwitchService, SwitchConfigurationErrorCode } from "../OnOffSwitchConfigurations/OnOffSwitchService"; import { Time as TimeParam } from "../OnOffSwitchConfigurations/OnOffSwitchParameters"; export class LedControllerService extends OnOffSwitchService { constructor() { super(); } GetServiceName() { return LedControllerService.ServiceName; } GetDimmingAndBrighteningTimeAsync(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 and brightening time - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetDimmingAndBrighteningTimeRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get dimming and brightening time - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get dimming and brightening time - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get dimming and brightening time - no data in response.`); return result.Data.State; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get dimming and brightening time - unknown error.`); } }); } SetDimmingAndBrighteningTimeAsync(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 SetDimmingAndBrighteningTimeRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set dimming and brightening time - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set dimming and brightening time, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetTurnOffTimeAsync(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 turn off time - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetTurnOffTimeRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get turn off time - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get turn off time - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get turn off time - no data in response.`); const data = new GlobalTimeParameters(); data.Channel = result.Data.Channel; data.Time = this.ParseNumberToTime(result.Data.Time); return data; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get turn off time - unknown error.`); } }); } SetTurnOffTimeAsync(device, params) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const time = params.Time.Hours * 3600 + params.Time.Minutes * 60 + params.Time.Seconds; if (time > 240) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to turn off time - time must be in range between 0 and 240 seconds.`); return Status.WrongData; } const request = new GlobalTimeParametersFrame(); request.Channel = params.Channel; request.DeviceGuid = device.Guid; request.Time = time; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetTurnOffTimeRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to turn off time - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to turn off time, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetFloatingTimeAsync(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 floating time - invalid channel number, channel: ${channel}`); const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new GetFloatingTimeRequest(new GetChannelParamsRequest(device.Guid, channel)), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot floating time - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot floating time - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot floating time - no data in response.`); const data = new GlobalTimeParameters(); data.Channel = result.Data.Channel; data.Time = this.ParseNumberToTime(result.Data.Time); return data; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot floating time - unknown error.`); } }); } SetFloatingTimeAsync(device, params) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const time = params.Time.Hours * 3600 + params.Time.Minutes * 60 + params.Time.Seconds; if (time > 64800) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set floating time - time must be in range between 1s to 18 hours.`); return Status.WrongData; } const request = new GlobalTimeParametersFrame(); request.Channel = params.Channel; request.DeviceGuid = device.Guid; request.Time = time; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetFloatingTimeRequest(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set floating time - unknow error.`); return Status.FatalError; } if (result.Status !== Status.OK) this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set floating time, response status: ${result.Status}`); return result.Status; } catch (error) { return Status.FatalError; } }); } GetTurnOnOffTimeActivationAsync(device) { 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 GetTurnOnOffTimeActivation(device.Guid), 8000, false)); if (result == null || result.Status == null) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get turn on/off time activation - unknown error.`); if (result.Status !== Status.OK) return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get turn on/off time activation - controller responded with error code: ${result.Status}.`); if (result.Data == null) return new ResponseResult(SwitchConfigurationErrorCode.NoData, `Cannot get turn on/off time activation - no data in response.`); return result.Data; } catch (error) { return new ResponseResult(SwitchConfigurationErrorCode.OtherError, `Cannot get turn on/off time activation - unknown error.`); } }); } SetTurnOnOffTimeActivationAsync(device, activation) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const request = new ActivationOnOffTimes(); request.DeviceGuid = device.Guid; request.Active = activation; const result = yield ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.SendAndWaitForResponseAsync(new SetTurnOnOffTimeActivation(request), 8000, false)); if (result == null || result.Status == null) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set turn on/off time activation - unknow error.`); return Status.FatalError; } return result.Status; } catch (error) { this._logger.Error(OnOffSwitchService.ServiceName, `Failed to set turn on/off time activation, error: ${error}`); return Status.FatalError; } }); } } LedControllerService.ServiceName = "LedControllerService"; //BrighteningAndDimmingTime class DimmerSettingsParameters { constructor() { this.Channel = 0; this.DeviceGuid = ""; this.State = 0; this.StateOptional = 0; } } class GetDimmingAndBrighteningTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/brightening/time"; this.Method = Method.Get; this.Data = data; } } class SetDimmingAndBrighteningTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/brightening/time"; this.Method = Method.Put; this.Data = data; } } //Global time class Time extends TimeParam { set Raw(value) { this._raw = value; } } class GlobalTimeParametersFrame { constructor() { this.Channel = 0; this.DeviceGuid = ""; this.Time = 0; } } //Turn on/off time activation class ActivationOnOffTimes { constructor() { this.DeviceGuid = ""; this.Active = false; } } //TrunOffTime class GetTurnOffTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/device/off/time"; this.Method = Method.Get; this.Data = data; } } class SetTurnOffTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/device/off/time"; this.Method = Method.Put; this.Data = data; } } //FloatingTime class GetFloatingTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/device/floating/time"; this.Method = Method.Get; this.Data = data; } } class SetFloatingTimeRequest extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/device/floating/time"; this.Method = Method.Put; this.Data = data; } } //Turn on off time activation class GetTurnOnOffTimeActivation extends DataFrame { constructor(deviceGuid) { super(); this.Resource = "/extalife/device/parameters/activation/onoff/times"; this.Method = Method.Get; this.Data = deviceGuid; } } class SetTurnOnOffTimeActivation extends DataFrame { constructor(data) { super(); this.Resource = "/extalife/device/parameters/activation/onoff/times"; this.Method = Method.Put; this.Data = data; } } //# sourceMappingURL=LedControllerService.js.map