Repository navigation
v5.4.0 #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
v5.4.0 #98
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
380e433
feat!: replace axios with fetch and report characteristic errors
NorthernMan54 0941562
fix: remember a refused pin on the client, so an unregistered bridge …
bwp91 4658a59
feat: take the list of our own bridges, so another homebridge's refus…
bwp91 afbceed
fix: add a bridge that registers after the monitor started to it, so …
bwp91 50a08c4
chore: run the type generator with tsx instead of ts-node
bwp91 c1beb93
chore(deps): dependency updates
bwp91 9161d31
fix: fix empty HAP characteristic write responses (#95)
dnicolson 0ae2cbf
chore: prepare v5.4.0 changelog and drop unused axios
NorthernMan54 6999147
fix: restore 5.3.0 behaviour for getResource errors and failed monito…
NorthernMan54 6ef26c4
ci: add a publish summary to the release workflow
NorthernMan54 4a56ef5
chore: publish only dist, README, LICENSE and CHANGELOG to npm
NorthernMan54 6a68e1f
fix: sort the files allowlist for lint, and stop emitting source maps
NorthernMan54 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Examples | ||
|
|
||
| Build the local package, then inspect and monitor the HomeKit accessory named `Backyard Tree`: | ||
|
|
||
| ```sh | ||
| npm run build | ||
| HAP_PIN=031-45-154 node examples/backyard-tree.js | ||
| ``` | ||
|
|
||
| During development, use Nodemon to rebuild and restart the example whenever its source or the client source changes: | ||
|
|
||
| ```sh | ||
| HAP_PIN=031-45-154 npm run exampleWatch | ||
| ``` | ||
|
|
||
| Homebridge must be running in insecure mode (`-I`). Replace the example PIN with your bridge PIN. | ||
|
|
||
| The example limits discovery to bridge `69:62:B7:AE:38:D4`. Once discovery ends, it calls `getValue()` for every readable, event-enabled characteristic before printing the accessory's services, then subscribes to its event-enabled characteristics. Debug output includes each full `getValue()` HTTP response and the complete sent and received event-monitor packets as plain text, which may contain the bridge PIN and other sensitive values. | ||
|
|
||
| To inspect a different accessory without editing the file, set `HAP_ACCESSORY`: | ||
|
|
||
| ```sh | ||
| HAP_PIN=031-45-154 HAP_ACCESSORY='Front Porch' node examples/backyard-tree.js | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* eslint-disable no-console -- This example intentionally writes discovery results to the terminal. */ | ||
| import process from 'node:process' | ||
|
|
||
| // Build first with `npm run build`; this imports the local package output. | ||
| // eslint-disable-next-line antfu/no-import-dist | ||
| import { HapClient } from '../dist/index.js' | ||
|
|
||
| const accessoryName = process.env.HAP_ACCESSORY ?? 'Backyard Tree' | ||
| const pin = process.env.HAP_PIN | ||
|
|
||
| if (!pin) { | ||
| console.error('Set HAP_PIN to your Homebridge PIN. See examples/README.md for an invocation.') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const client = new HapClient({ | ||
| pin, | ||
| logger: console, | ||
| config: { | ||
| autoStartDiscovery: false, | ||
| debug: true, | ||
| debugRawPackets: true, | ||
| discoveryTimeout: 5000, | ||
| instanceWhitelist: ['69:62:B7:AE:38:D4'], | ||
| }, | ||
| }) | ||
|
|
||
| function shutDown(exitCode = 0) { | ||
| client.destroy() | ||
| process.exit(exitCode) | ||
| } | ||
|
|
||
| process.once('SIGINT', () => shutDown(130)) | ||
| process.once('SIGTERM', () => shutDown(143)) | ||
|
|
||
| client.on('instance-discovered', (instance) => { | ||
| console.log(`Found ${instance.name} (${instance.username}) at ${instance.ipAddress}:${instance.port}`) | ||
| }) | ||
|
|
||
| client.once('discovery-ended', async () => { | ||
| try { | ||
| console.log(`Discovery has ended`) | ||
| const services = await client.getAllServices() | ||
| const accessoryServices = services.filter(service => service.accessoryInformation?.Name === accessoryName) | ||
|
|
||
| if (!accessoryServices.length) { | ||
| const names = [ | ||
| ...new Set(services.map(service => service.accessoryInformation?.Name).filter(Boolean)), | ||
| ] | ||
| throw new Error(`Accessory ${JSON.stringify(accessoryName)} was not found. Discovered: ${names.join(', ') || 'none'}`) | ||
| } | ||
|
|
||
| // Values included in the accessories response may be stale. Prime each | ||
| // readable, event-enabled characteristic with its latest value before | ||
| // displaying and monitoring the returned service objects. | ||
| await Promise.all(accessoryServices.flatMap(service => | ||
| service.serviceCharacteristics | ||
| .filter(characteristic => characteristic.ev && characteristic.canRead) | ||
| .map(async (characteristic) => { | ||
| try { | ||
| console.log(`Retrieving lastest value for ${characteristic.description} ${JSON.stringify(await characteristic.getValue(), null, 2)}`) | ||
| } catch (error) { | ||
| console.warn(`Could not refresh ${service.serviceName} / ${characteristic.type}:`, error) | ||
| } | ||
| }), | ||
| )) | ||
|
|
||
| // A HAP accessory is returned as one ServiceType per service. Services with | ||
| // the same bridge username and aid belong to this single accessory. | ||
| console.dir(accessoryServices, { depth: null, colors: process.stdout.isTTY }) | ||
|
|
||
| const eventServices = accessoryServices.filter(service => service.serviceCharacteristics.some(characteristic => characteristic.ev)) | ||
| if (!eventServices.length) { | ||
| console.log(`\n${accessoryName} has no event-enabled characteristics, so there are no packets to monitor.`) | ||
| client.destroy() | ||
| return | ||
| } | ||
|
|
||
| const monitor = await client.monitorCharacteristics(eventServices) | ||
| monitor.on('service-update', (updatedServices) => { | ||
| console.log(`\n[${new Date().toISOString()}] ${accessoryName} update:`) | ||
| console.dir(updatedServices, { depth: null, colors: process.stdout.isTTY }) | ||
| }) | ||
| monitor.on('monitor-error', (instance, error) => { | ||
| console.error(`Monitor error for ${instance.username}:`, error) | ||
| }) | ||
|
|
||
| console.log(`\nMonitoring ${JSON.stringify(accessoryName)}. Change its state to see updates; press Ctrl+C to stop.`) | ||
| } catch (error) { | ||
| console.error(error) | ||
| client.destroy() | ||
| process.exitCode = 1 | ||
| } | ||
| }) | ||
|
|
||
| console.log(`Discovering bridges for ${JSON.stringify(accessoryName)}...`) | ||
| client.startDiscovery() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "watch": [ | ||
| "src", | ||
| "examples/backyard-tree.js" | ||
| ], | ||
| "ext": "ts,js,json", | ||
| "ignore": [ | ||
| "dist/**", | ||
| "node_modules/**" | ||
| ], | ||
| "exec": "npm run build && node examples/backyard-tree.js", | ||
| "signal": "SIGTERM" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.