diff --git a/README.md b/README.md index b8d6739..d482e0c 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ Options: -c, --category [string] [required] [choices: "other", "bridge", "fan", "garage", "lightbulb", "doorLock", "outlet", "switch", "thermostat", "sensor", "securitySystem", "door", "window", "windowCovering", "programmableSwitch", "rangeExtender", "ipCamera", "videoDoorBell", "airPurifier", "heater", "airConditioner", "humidifier", "dehumidifier", "appleTv", "speaker", "airport", "sprinkler", "faucet", "showerHead", "television", "targetController"] -o, --output [string] [default: "qrcode.svg"] -p, --pairingCode [string] [required] - -s, --setupId [string] [default: ""] + -s, --setupId [string] [required] Examples: - npx homekit-qrcode --category=switch --pairingCode=01234567 Generate a QR code for a HomeKit switch + npx homekit-qrcode --category=switch --pairingCode=84131633 --setupId=3QYT Generate a QR code for a HomeKit switch ``` ### Output diff --git a/docs/qrcode.png b/docs/qrcode.png index c3f13a7..1dedc11 100644 Binary files a/docs/qrcode.png and b/docs/qrcode.png differ diff --git a/src/index.ts b/src/index.ts index bc756f9..0c4cf1c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ import { argv } from './yargs'; const main = async () => { const { category, output, pairingCode, setupId } = argv; - const categoryId = CATEGORIES.get(category); + const categoryId = CATEGORIES.get(category) as number; const filename = getFilename(output); const qrCodeSvg = await generateQrCodeAsSvg(categoryId, pairingCode, setupId); const file = createLabelAsSvg(pairingCode, qrCodeSvg); diff --git a/src/qrcode.ts b/src/qrcode.ts index 3aad6a2..86227da 100644 --- a/src/qrcode.ts +++ b/src/qrcode.ts @@ -2,13 +2,13 @@ import qrcode from 'qrcode'; import { createSetupUri } from './homekit'; const QR_CODE_STRING_OPTIONS: qrcode.QRCodeToStringOptions = { - errorCorrectionLevel: 'Q', + errorCorrectionLevel: 'quartile', margin: 0, type: 'svg', version: 2, }; -export const generateQrCodeAsSvg = async (category = 0, password = '', setupId = ''): Promise => { +export const generateQrCodeAsSvg = async (category: number, password: string, setupId: string): Promise => { const setupUri = createSetupUri(category, password, setupId); return qrcode.toString(setupUri, QR_CODE_STRING_OPTIONS); }; diff --git a/src/yargs.ts b/src/yargs.ts index eea4cd9..adde4a1 100644 --- a/src/yargs.ts +++ b/src/yargs.ts @@ -30,8 +30,7 @@ export const argv = yargs(process.argv.slice(2)) }, setupId: { alias: 's', - demandOption: false, - default: '', + demandOption: true, type: 'string', }, }) @@ -43,5 +42,8 @@ export const argv = yargs(process.argv.slice(2)) } }) .usage('Usage: homekit-qrcode [options]') - .example('npx homekit-qrcode --category=switch --pairingCode=01234567', 'Generate a QR code for a HomeKit switch') + .example( + 'npx homekit-qrcode --category=switch --pairingCode=84131633 --setupId=3QYT', + 'Generate a QR code for a HomeKit switch', + ) .parseSync();