diff --git a/backend/src/models/backendInterfaces.d.ts b/backend/src/models/backendInterfaces.d.ts index dfb412c7..684707e4 100644 --- a/backend/src/models/backendInterfaces.d.ts +++ b/backend/src/models/backendInterfaces.d.ts @@ -122,27 +122,27 @@ export declare class IDataIO { /** AC particular status command */ export declare interface AirConditioningCommand { - command: string; + command: string | string []; status: AirConditioning; } /** Toggle commands set */ export declare interface ToggleCommands { - on: string; - off: string; + on: string | string []; + off: string | string []; } /** Ac commands set */ export declare interface AcCommands { - off: string; + off: string | string []; statusCommands: AirConditioningCommand[]; } /** Roller commands set */ export declare interface RollerCommands { - off: string; - up: string; - down: string; + off: string | string []; + up: string | string []; + down: string | string []; } /** RF (IR/433MHz etc.) commands set based of device type */ diff --git a/backend/src/modules/broadlink/broadlinkHandler.ts b/backend/src/modules/broadlink/broadlinkHandler.ts index 9ea4f2c1..a6b8786d 100644 --- a/backend/src/modules/broadlink/broadlinkHandler.ts +++ b/backend/src/modules/broadlink/broadlinkHandler.ts @@ -20,7 +20,7 @@ import { Delay, sleep } from '../../utilities/sleep'; import { BrandModuleBase } from '../brandModuleBase'; import * as broadlink from 'node-broadlink'; import Device from 'node-broadlink/dist/device'; -import { Rmpro, Sp2 } from 'node-broadlink'; +import { Rmpro, Sp2 } from 'node-broadlink'; import { Duration, Temperature } from 'unitsnet-js'; // tslint:disable-next-line:no-var-requires @@ -175,7 +175,7 @@ export class BroadlinkHandler extends BrandModuleBase { /** Get broadlink protocol handler instance for given minion */ private async getBroadlinkInstance(minion: Minion): Promise { try { - const list : Device[] = await broadlink.discover(); + const list: Device[] = await broadlink.discover(); logger.info(`[BroadlinkModule.getBroadlinkInstance] Devices founded ${list.map(i => toNormalMac(i.mac)).join(',')}`); @@ -202,9 +202,17 @@ export class BroadlinkHandler extends BrandModuleBase { } /** Send RF/IR command */ - private async sendBeamCommand(broadlink: Rmpro, beamCommand: string): Promise { + private async sendBeamCommand(broadlink: Rmpro, beamCommand: string | string[]): Promise { try { - await broadlink.sendData(beamCommand); + + if (typeof beamCommand === 'string') { + await broadlink.sendData(beamCommand); + } else { + for (const command of beamCommand) { + await broadlink.sendData(command); + } + } + } catch (error) { logger.error(` ${error?.message}`); throw { diff --git a/backend/src/utilities/cacheManager.ts b/backend/src/utilities/cacheManager.ts index 9b19f694..32f1d911 100644 --- a/backend/src/utilities/cacheManager.ts +++ b/backend/src/utilities/cacheManager.ts @@ -110,7 +110,7 @@ export class CommandsCacheManager extends CacheManager { return minionCache.lastStatus; } - public async getRFToggleCommand(minion: Minion, status: MinionStatus): Promise { + public async getRFToggleCommand(minion: Minion, status: MinionStatus): Promise { const minionCache = this.getOrCreateMinionCache(minion); @@ -134,7 +134,7 @@ export class CommandsCacheManager extends CacheManager { return hexCommandCode; } - public async getRFRollerCommand(minion: Minion, status: MinionStatus): Promise { + public async getRFRollerCommand(minion: Minion, status: MinionStatus): Promise { const minionCache = this.getOrCreateMinionCache(minion); @@ -162,7 +162,7 @@ export class CommandsCacheManager extends CacheManager { return hexCommandCode; } - public async getIrCommand(minion: Minion, setStatus: MinionStatus): Promise { + public async getIrCommand(minion: Minion, setStatus: MinionStatus): Promise { const minionCache = this.getOrCreateMinionCache(minion); @@ -173,7 +173,7 @@ export class CommandsCacheManager extends CacheManager { } as ErrorResponse; } - let hexCommandCode: string; + let hexCommandCode: string | string []; /** * If the request is to set off, get the off command. @@ -193,7 +193,7 @@ export class CommandsCacheManager extends CacheManager { if (!hexCommandCode) { throw { responseCode: 4503, - message: 'there is no availble command for current status. record a new command.', + message: 'there is no available command for current status. record a new command.', } as ErrorResponse; } @@ -206,7 +206,7 @@ export class CommandsCacheManager extends CacheManager { await this.saveCache(); } - public async cacheIRACommand(minion: Minion, statusToRecordFor: MinionStatus, hexIRCommand: string): Promise { + public async cacheIRACommand(minion: Minion, statusToRecordFor: MinionStatus, hexIRCommand: string | string[]): Promise { const minionCache = this.getOrCreateMinionCache(minion); @@ -234,7 +234,7 @@ export class CommandsCacheManager extends CacheManager { await this.saveCache(); } - public async cacheRFRollerCommand(minion: Minion, statusToRecordFor: MinionStatus, hexRfCommand: string): Promise { + public async cacheRFRollerCommand(minion: Minion, statusToRecordFor: MinionStatus, hexRfCommand: string | string[]): Promise { const minionCache = this.getOrCreateMinionCache(minion);