Skip to content

Commit

Permalink
Add aborter to authorize script
Browse files Browse the repository at this point in the history
  • Loading branch information
LeLunZ committed Sep 11, 2024
1 parent 839d5db commit a7224a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 4 additions & 2 deletions src/scripts/hisenseTV/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand All @@ -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');
Expand Down

0 comments on commit a7224a0

Please sign in to comment.