Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 19 additions & 5 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,25 @@ Always reference these instructions first and fallback to search or bash command
- **Use lint:fix for automatic fixes**: `npm run lint:fix` to automatically fix ESLint issues

### Platform Requirements and Constraints
- **BLE functionality requires Linux-based OS only** (Raspbian, Ubuntu, etc.)
- **Windows and macOS are NOT supported** for BLE operations (use OpenAPI instead)
- **BLE functionality requires Linux or macOS** (Raspbian, Ubuntu, macOS, etc.)
- **Windows is NOT supported** for BLE operations (use OpenAPI instead)
- **Node.js versions**: Must use ^20, ^22, or ^24 (currently using v20.19.4)
- **ES Modules**: This project uses `"type": "module"` - always use ES import/export syntax

#### BLE Prerequisites

**macOS:**
- Xcode installed
- Bluetooth permissions enabled for terminal app in System Preferences

**Linux (Ubuntu/Debian/Raspbian):**
- Required packages: `sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev`
- For non-root access: `sudo setcap cap_net_raw+eip $(eval readlink -f \`which node\`)`
- Raspberry Pi: May need to disable pnat plugin in `/etc/bluetooth/main.conf`

**Linux (Fedora/RPM):**
- Required packages: `sudo yum install bluez bluez-libs bluez-libs-devel`

### Testing and Validation
- **Basic functionality test**: After any changes to core classes, run this validation:
```javascript
Expand Down Expand Up @@ -116,9 +130,9 @@ Always reference these instructions first and fallback to search or bash command
## Troubleshooting Common Issues

### BLE Not Working
- **Check OS**: BLE only works on Linux-based systems
- **Check OS**: BLE works on Linux and macOS systems only
- **Install noble prerequisites**: May need additional system libraries for @stoprocent/noble
- **Use OpenAPI instead**: For Windows/macOS development, use SwitchBotOpenAPI class
- **Use OpenAPI instead**: For Windows development, use SwitchBotOpenAPI class
Comment on lines +133 to +135
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc still recommends using SwitchBotOpenAPI on Windows, but the PR description states v4 replaces SwitchBotBLE/SwitchBotOpenAPI with a single SwitchBot class (and separately mentions OpenAPIClient). Update this troubleshooting line to reference the v4 way to do API-only operation (e.g., SwitchBot with enableBLE: false) or the lower-level OpenAPIClient, to avoid pointing readers at a removed/legacy class.

Copilot uses AI. Check for mistakes.

### Build Failures
- **Check Node.js version**: Must be ^20, ^22, or ^24
Expand Down Expand Up @@ -156,7 +170,7 @@ npm run watch # Build and link for development
- **Type definitions**: All device status and response types

### Dependencies Summary
- **@stoprocent/noble**: BLE functionality (Linux only)
- **@stoprocent/noble**: BLE functionality (Linux/macOS)
- **undici**: HTTP client for API requests
- **async-mutex**: Concurrency control
- **TypeScript**: Language and compilation
Expand Down
52 changes: 0 additions & 52 deletions .github/workflows/beta-release.yml

This file was deleted.

79 changes: 64 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,78 @@
name: Unified Release
name: Release

on:
push:
branches:
#- "alpha-*"
#- "beta-*"
- latest
- 'beta-*'
- 'beta'
- 'latest'
workflow_dispatch:

jobs:
# ─── BETA RELEASE (branches starting with "beta") ────────────────────────────

# 1️⃣ Build and test
build_and_test:
if: startsWith(github.ref_name, 'beta')
uses: homebridge/.github/.github/workflows/nodejs-build-and-test.yml@latest
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
with:
enable_coverage: false
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

# 2️⃣ Lint
lint:
if: startsWith(github.ref_name, 'beta')
needs: build_and_test
uses: homebridge/.github/.github/workflows/eslint.yml@latest
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.

# 3️⃣ Publish beta to NPM (OIDC — id-token required here and in the reusable workflow)
beta-publish:
if: startsWith(github.ref_name, 'beta')
needs: lint
permissions:
id-token: write
uses: homebridge/.github/.github/workflows/npm-publish-esm-oidc.yml@latest
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
with:
tag: 'beta'
dynamically_adjust_version: true
npm_version_command: 'pre'
pre_id: 'beta'

# 4️⃣ Create GitHub pre-release
beta-pre-release:
if: startsWith(github.ref_name, 'beta')
needs: beta-publish
uses: homebridge/.github/.github/workflows/pre-release.yml@latest
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
with:
npm_version: ${{ needs.beta-publish.outputs.NPM_VERSION }}
body: |
**Beta Release**
**Version**: v${{ needs.beta-publish.outputs.NPM_VERSION }}
[How To Test Beta Releases](https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Beta-Version)


# ─── STABLE RELEASE (branch: "latest") ───────────────────────────────────────

# 1️⃣ Determine release type, ESM status, and branch name
determine-release-type:
if: github.ref_name == 'latest'
uses: homebridge/.github/.github/workflows/determine-release-type.yml@latest
with:
ref_name: ${{ github.ref_name }}

# 2️⃣ Update version and changelog using the scripts
update-version:
if: github.ref_name == 'latest'
needs: determine-release-type
uses: homebridge/.github/.github/workflows/update-version.yml@latest
with:
release_type: ${{ needs.determine-release-type.outputs.release_type }}
is_esm: ${{ needs.determine-release-type.outputs.is_esm == 'true' }}

# 3️⃣ Publish to NPM and create GitHub release
# 3️⃣ Publish to NPM and create GitHub release (OIDC — id-token required here and in the reusable workflow)
publish-release:
if: github.ref_name == 'latest'
needs: [determine-release-type, update-version]
permissions:
id-token: write
Expand All @@ -39,33 +87,34 @@ jobs:

# 4️⃣ Promote branch if this is a prerelease (alpha/beta)
promote-branch:
if: ${{ github.ref_name == 'latest' && needs.determine-release-type.outputs.release_type != 'latest' && needs.determine-release-type.outputs.release_type != 'skip' }}
needs: [determine-release-type, publish-release]
if: ${{ needs.determine-release-type.outputs.release_type != 'latest' && needs.determine-release-type.outputs.release_type != 'skip' }}
uses: homebridge/.github/.github/workflows/promote-branch.yml@latest
with:
branch_name: ${{ needs.determine-release-type.outputs.branch_name }}
release_type: ${{ needs.determine-release-type.outputs.release_type }}
is_esm: ${{ needs.determine-release-type.outputs.is_esm == 'true' }}

# 5️⃣ Notify if any previous job fails
# 5️⃣ Notify if any stable-release job fails
workflow-failure:
if: ${{ failure() }}
if: failure()
needs: [determine-release-type, update-version, publish-release, promote-branch]
uses: homebridge/.github/.github/workflows/report-failure.yml@latest
with:
workflow_name: ${{ github.workflow }}
job_name: ${{ github.job }}
run_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

# 6️⃣ Post to Discord
github-releases-to-discord:
name: Discord Webhooks
needs: [determine-release-type, update-version, publish-release]
# 6️⃣ Post to Discord (Beta + Stable)
discord:
name: Release Notifications
if: ${{ always() && ((startsWith(github.ref_name, 'beta') && needs.beta-publish.result == 'success') || (github.ref_name == 'latest' && needs.publish-release.result == 'success')) }}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
needs: [beta-publish, update-version, publish-release]
uses: homebridge/.github/.github/workflows/discord-webhooks.yml@latest
with:
title: "Node-SwitchBot Module Release"
title: ${{ startsWith(github.ref_name, 'beta') && 'SwitchBot-Node Beta Release' || 'SwitchBot-Node Release' }}
description: |
Version `v${{ needs.update-version.outputs.version }}`
url: "https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v${{ needs.update-version.outputs.version }}"
Version `v${{ startsWith(github.ref_name, 'beta') && needs.beta-publish.outputs.NPM_VERSION || needs.update-version.outputs.version }}`
Comment on lines +115 to +117
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
url: "https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v${{ startsWith(github.ref_name, 'beta') && needs.beta-publish.outputs.NPM_VERSION || needs.update-version.outputs.version }}"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }}
4 changes: 2 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Stale workflow
on:
workflow_dispatch:
schedule:
- cron: '45 11 * * *'
- cron: '45 7 * * *'

jobs:
stale:
uses: OpenWonderLabs/.github/.github/workflows/stale.yml@latest
uses: homebridge/.github/.github/workflows/stale.yml@latest
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

src

# v4.0.0 additions
test/
examples/
.dev-archive/
vitest.config.ts
typedoc.json
eslint.config.js

# ------------- Defaults -------------

# eslint
Expand Down
Loading
Loading