Skip to content

Commit

Permalink
Merge pull request #301 from casanet/support-multy-commands-action
Browse files Browse the repository at this point in the history
Support multiply commands per action
  • Loading branch information
haimkastner committed Sep 23, 2023
2 parents 6c94c34 + 3152d44 commit 5ca22c8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
14 changes: 7 additions & 7 deletions backend/src/models/backendInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
16 changes: 12 additions & 4 deletions backend/src/modules/broadlink/broadlinkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -175,7 +175,7 @@ export class BroadlinkHandler extends BrandModuleBase {
/** Get broadlink protocol handler instance for given minion */
private async getBroadlinkInstance(minion: Minion): Promise<Device | ErrorResponse> {
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(',')}`);

Expand All @@ -202,9 +202,17 @@ export class BroadlinkHandler extends BrandModuleBase {
}

/** Send RF/IR command */
private async sendBeamCommand(broadlink: Rmpro, beamCommand: string): Promise<void> {
private async sendBeamCommand(broadlink: Rmpro, beamCommand: string | string[]): Promise<void> {
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 {
Expand Down
14 changes: 7 additions & 7 deletions backend/src/utilities/cacheManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CommandsCacheManager extends CacheManager {
return minionCache.lastStatus;
}

public async getRFToggleCommand(minion: Minion, status: MinionStatus): Promise<string | ErrorResponse> {
public async getRFToggleCommand(minion: Minion, status: MinionStatus): Promise<string | string [] | ErrorResponse> {

const minionCache = this.getOrCreateMinionCache(minion);

Expand All @@ -134,7 +134,7 @@ export class CommandsCacheManager extends CacheManager {
return hexCommandCode;
}

public async getRFRollerCommand(minion: Minion, status: MinionStatus): Promise<string | ErrorResponse> {
public async getRFRollerCommand(minion: Minion, status: MinionStatus): Promise<string | string [] | ErrorResponse> {

const minionCache = this.getOrCreateMinionCache(minion);

Expand Down Expand Up @@ -162,7 +162,7 @@ export class CommandsCacheManager extends CacheManager {
return hexCommandCode;
}

public async getIrCommand(minion: Minion, setStatus: MinionStatus): Promise<string | ErrorResponse> {
public async getIrCommand(minion: Minion, setStatus: MinionStatus): Promise<string | string [] | ErrorResponse> {

const minionCache = this.getOrCreateMinionCache(minion);

Expand All @@ -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.
Expand All @@ -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;
}

Expand All @@ -206,7 +206,7 @@ export class CommandsCacheManager extends CacheManager {
await this.saveCache();
}

public async cacheIRACommand(minion: Minion, statusToRecordFor: MinionStatus, hexIRCommand: string): Promise<void | ErrorResponse> {
public async cacheIRACommand(minion: Minion, statusToRecordFor: MinionStatus, hexIRCommand: string | string[]): Promise<void | ErrorResponse> {

const minionCache = this.getOrCreateMinionCache(minion);

Expand Down Expand Up @@ -234,7 +234,7 @@ export class CommandsCacheManager extends CacheManager {
await this.saveCache();
}

public async cacheRFRollerCommand(minion: Minion, statusToRecordFor: MinionStatus, hexRfCommand: string): Promise<void | ErrorResponse> {
public async cacheRFRollerCommand(minion: Minion, statusToRecordFor: MinionStatus, hexRfCommand: string | string[]): Promise<void | ErrorResponse> {

const minionCache = this.getOrCreateMinionCache(minion);

Expand Down

0 comments on commit 5ca22c8

Please sign in to comment.