From a7224a00518452df46f7311d96e3d3a5f108bf07 Mon Sep 17 00:00:00 2001 From: LeLunZ <31982496+LeLunZ@users.noreply.github.com> Date: Wed, 11 Sep 2024 23:46:17 +0200 Subject: [PATCH] Add aborter to authorize script --- package.json | 2 +- src/scripts/hisenseTV/authorize.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 86cb4da..1b5edd8 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ ] }, "engines": { - "homebridge": "^1.8.0 || ^2.0.0-beta.0", + "homebridge": "^1.8.0 || ^2.0.0-beta.1", "node": "^18.20.4 || ^20.15.1" }, "dependencies": { diff --git a/src/scripts/hisenseTV/authorize.ts b/src/scripts/hisenseTV/authorize.ts index 55f896c..6ed37f9 100644 --- a/src/scripts/hisenseTV/authorize.ts +++ b/src/scripts/hisenseTV/authorize.ts @@ -5,6 +5,7 @@ import path from 'path'; import {clearTimeout} from 'node:timers'; export function authorize(rl: readline.Interface, mqttHelper: HisenseMQTTClient): SubscriptExitCode { + const aborter = new AbortController(); let timeout: NodeJS.Timeout|undefined; mqttHelper.mqttClient.on('connect', () => { mqttHelper.callService('ui_service', 'sourcelist'); @@ -18,7 +19,8 @@ export function authorize(rl: readline.Interface, mqttHelper: HisenseMQTTClient) } const data = JSON.parse(strMessage); if(topic === mqttHelper._SOURCE_LIST_TOPIC){ - rl.write('Mac address is already authorized\n'); + aborter.abort(); + rl.write('\nMac address is already authorized!\n'); process.exit(0); } else if(data != null && typeof data === 'object' && 'result' in data) { if(timeout != null) { @@ -38,7 +40,7 @@ export function authorize(rl: readline.Interface, mqttHelper: HisenseMQTTClient) }); (async () => { - const code = await rl.question('Please enter the 4-digit code shown on tv: '); + const code = await rl.question('Please enter the 4-digit code shown on tv: ', { signal: aborter.signal }); mqttHelper.subscribe(path.join(mqttHelper._COMMUNICATION_TOPIC, '#')); timeout = setTimeout(() => { rl.write('Timeout\n');