Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
feat: update cli argument setup id
Browse files Browse the repository at this point in the history
- set required and remove default value
- update example qr code
- update README

BREAKING CHANGE: set setupId to requried
  • Loading branch information
SimonGolms committed Oct 26, 2021
1 parent 3c73c3e commit f94ea6f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down
Binary file modified docs/qrcode.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/qrcode.ts
Expand Up @@ -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<string> => {
export const generateQrCodeAsSvg = async (category: number, password: string, setupId: string): Promise<string> => {
const setupUri = createSetupUri(category, password, setupId);
return qrcode.toString(setupUri, QR_CODE_STRING_OPTIONS);
};
8 changes: 5 additions & 3 deletions src/yargs.ts
Expand Up @@ -30,8 +30,7 @@ export const argv = yargs(process.argv.slice(2))
},
setupId: {
alias: 's',
demandOption: false,
default: '',
demandOption: true,
type: 'string',
},
})
Expand All @@ -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();

0 comments on commit f94ea6f

Please sign in to comment.