Skip to content

Commit

Permalink
Handle case where tplink devices are not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
nicou committed Jul 2, 2024
1 parent 73f5a6b commit 9ad8372
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/tplink/tplink-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { Client } from 'tplink-smarthome-api';
const client = new Client();

export async function scanTplinkDevices() {
const dmxConfig = store.getState().data.tplink.dmxconfig;
const dmxConfig = store.getState().data.tplink?.dmxconfig;
if (!dmxConfig) {
logger.debug('No TP-link DMX config found');
return;
}

const ipaddresses: string[] = dmxConfig.signals.map(signal => signal.ip);
const uniqueIpAddresses = [...new Set(ipaddresses)];
const devices = {};
Expand All @@ -32,8 +37,18 @@ export async function scanTplinkDevices() {
}

export async function processDmxSignal(signal: string): Promise<void> {
if (process.env.DISABLE_TPLINK_SCANNING) {
logger.info('TP-link scanning is disabled');
return;
}

// List of objects { dmx: "LoungeFuseFixed", ip: "1.2.3.4", powerstate: true }
const dmxSignals = store.getState().data.tplink.dmxconfig.signals;
const dmxSignals = store.getState().data.tplink?.dmxconfig?.signals;
if (!dmxSignals) {
logger.debug('No TP-link DMX signals configured');
return;
}

for (let dmxSignal of dmxSignals) {
if (dmxSignal.dmx === signal) {
setTimeout(async () => {
Expand Down

0 comments on commit 9ad8372

Please sign in to comment.