@switchbot/homebridge-switchbot 5.2.10 → 5.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,8 +152,26 @@ node -p "const v=require('./package.json').version.split('.'); v[2]=parseInt(v[2
152
152
 
153
153
  ## Following node-switchbot Changes
154
154
 
155
- node-switchbot tracks [pySwitchbot](https://github.com/sblibs/pySwitchbot). After node-switchbot
156
- ships a change, this repo usually needs a follow-up PR so the plugin can use it:
155
+ node-switchbot tracks [pySwitchbot](https://github.com/sblibs/pySwitchbot).
156
+
157
+ **Version updates come as pull requests.** `.github/workflows/node-switchbot-update.yml` checks
158
+ npm hourly. When node-switchbot publishes a newer release (patch, minor or major), it opens a pull
159
+ request to `latest`, from the `deps/node-switchbot` branch. The pull request:
160
+
161
+ - changes only the `node-switchbot` range in `package.json` and its `package-lock.json` entries,
162
+ never the plugin's own `version` (the release workflow sets that when it publishes);
163
+ - is labelled `patch`, `minor` or `major` to match the node-switchbot change, which sets the kind
164
+ of plugin release that merging it publishes;
165
+ - is updated if a newer node-switchbot comes out before it is merged, and closed if `latest`
166
+ catches up some other way.
167
+
168
+ The maintainer reviews and merges it. Do not open separate pull requests that only bump
169
+ node-switchbot; Dependabot ignores it for the same reason. For a node-switchbot major (or any
170
+ release) that needs plugin changes, push them to the `deps/node-switchbot` branch or open a
171
+ follow-up pull request.
172
+
173
+ When node-switchbot ships something the plugin must change code to use, this repo needs a
174
+ follow-up PR:
157
175
 
158
176
  1. Read the node-switchbot PR/release and list what consumers see: new device types, renamed or
159
177
  split model identities (`modelName`, OpenAPI `deviceType`), new status fields, new commands.
@@ -162,7 +180,9 @@ ships a change, this repo usually needs a follow-up PR so the plugin can use it:
162
180
  accessory behaviour in `src/devices/genericDevice.ts`.
163
181
  3. Make sure no existing saved `configDeviceType` stops resolving (normalization map or
164
182
  `src/homebridge-ui/utils/device-migration.ts`).
165
- 4. Bump `node-switchbot` in `package.json` only to a version already published on npm.
183
+ 4. The version bump itself comes from the `deps/node-switchbot` pull request. Bump
184
+ `node-switchbot` in `package.json` yourself only if the plugin change must ship together with
185
+ it, and only to a version already published on npm.
166
186
  5. Add `createDevice` tests under `test/device/` asserting each affected type's accessory class.
167
187
  6. Run build, test and lint; commit the regenerated `config.schema.json` if `DEVICE_TYPES` changed.
168
188
 
@@ -242,7 +262,10 @@ npm run lint # eslint (src, test, UI html/js) then tsc --noEmit
242
262
  - `.github/workflows/ci.yml`: build, test and lint on Node 22 and 24 for pushes to `latest`/`beta-*`
243
263
  and PRs to `latest`/`beta-*`.
244
264
  - `.github/workflows/release.yml`: pushes to `beta-*` publish a beta to npm; pushes to `latest`
245
- publish a stable release.
265
+ publish a stable release. It can also be started by hand (`workflow_dispatch`).
266
+ - `.github/workflows/node-switchbot-update.yml`: hourly, opens or updates a pull request that moves
267
+ node-switchbot to its newest release (see "Following node-switchbot Changes"), and starts
268
+ `ci.yml` on it. Run it by hand from the Actions tab to check immediately.
246
269
 
247
270
  ## Complete Workflow Examples
248
271
 
@@ -10,6 +10,9 @@ updates:
10
10
  target-branch: 'beta-*.*.*'
11
11
  schedule:
12
12
  interval: 'daily'
13
+ ignore:
14
+ # Updated and released automatically by .github/workflows/node-switchbot-update.yml
15
+ - dependency-name: 'node-switchbot'
13
16
  - package-ecosystem: 'github-actions' # See documentation for possible values
14
17
  directory: '/' # Location of package manifests
15
18
  target-branch: 'beta-*.*.*'
@@ -5,6 +5,8 @@ on:
5
5
  branches: ["main", "latest", "beta-*"]
6
6
  pull_request:
7
7
  branches: ["main", "latest", "beta-*"]
8
+ # Started by node-switchbot-update.yml: pull requests it opens with GITHUB_TOKEN don't trigger CI
9
+ workflow_dispatch:
8
10
 
9
11
  permissions:
10
12
  contents: read
@@ -0,0 +1,180 @@
1
+ name: Update node-switchbot
2
+
3
+ # When node-switchbot publishes a new release (patch, minor or major), open a pull request to
4
+ # latest that updates it. Merging the pull request publishes a plugin release through release.yml.
5
+ #
6
+ # The pull request changes only the node-switchbot dependency range in package.json and its
7
+ # entries in package-lock.json. It never changes the plugin's own "version": the release workflow
8
+ # sets that when it publishes, from the patch / minor / major label on the merged pull request.
9
+ #
10
+ # The label is set to match the node-switchbot change. Change it before merging if the plugin
11
+ # release should be a different kind (for example a node-switchbot major that needs no plugin
12
+ # changes can ship as a minor).
13
+
14
+ on:
15
+ schedule:
16
+ - cron: '23 * * * *' # hourly
17
+ workflow_dispatch:
18
+ # Lets node-switchbot's release workflow trigger this immediately, if it is given a token that
19
+ # can dispatch to this repository:
20
+ # gh api repos/OpenWonderLabs/homebridge-switchbot/dispatches -f event_type=node-switchbot-released
21
+ repository_dispatch:
22
+ types: [node-switchbot-released]
23
+
24
+ permissions:
25
+ contents: write
26
+ pull-requests: write
27
+ actions: write
28
+
29
+ concurrency:
30
+ group: node-switchbot-update
31
+ cancel-in-progress: false
32
+
33
+ env:
34
+ BRANCH: deps/node-switchbot
35
+
36
+ jobs:
37
+ update:
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - uses: actions/checkout@v6
41
+ with:
42
+ ref: latest
43
+
44
+ - uses: actions/setup-node@v6
45
+ with:
46
+ node-version: 24
47
+
48
+ - name: Compare with the newest node-switchbot on npm
49
+ id: check
50
+ run: |
51
+ published=$(npm view node-switchbot@latest version)
52
+ wanted=$(node -p "require('./package.json').dependencies['node-switchbot']")
53
+ current=$(node -p "process.argv[1].replace(/^[^0-9]*/, '')" "$wanted")
54
+ level=$(node -e '
55
+ const [a, b] = process.argv.slice(1).map(v => v.split("-")[0].split(".").map(Number))
56
+ const newer = a[0] !== b[0] ? a[0] > b[0] : a[1] !== b[1] ? a[1] > b[1] : a[2] > b[2]
57
+ console.log(!newer ? "none" : a[0] !== b[0] ? "major" : a[1] !== b[1] ? "minor" : "patch")
58
+ ' "$published" "$current")
59
+ {
60
+ echo "published=$published"
61
+ echo "current=$current"
62
+ echo "level=$level"
63
+ } >> "$GITHUB_OUTPUT"
64
+ echo "node-switchbot: plugin requires ^$current, npm latest is $published -> $level"
65
+
66
+ - name: Close an update pull request that latest has caught up with
67
+ if: steps.check.outputs.level == 'none'
68
+ env:
69
+ GH_TOKEN: ${{ github.token }}
70
+ run: |
71
+ number=$(gh pr list --head "$BRANCH" --base latest --state open --json number --jq '.[0].number // empty')
72
+ if [[ -n "$number" ]]; then
73
+ gh pr close "$number" --delete-branch \
74
+ --comment "latest already requires node-switchbot ^${{ steps.check.outputs.current }}, the newest release."
75
+ fi
76
+
77
+ - name: Find an open update pull request
78
+ if: steps.check.outputs.level != 'none'
79
+ id: pr
80
+ env:
81
+ GH_TOKEN: ${{ github.token }}
82
+ run: |
83
+ number=$(gh pr list --head "$BRANCH" --base latest --state open --json number --jq '.[0].number // empty')
84
+ title=$(gh pr list --head "$BRANCH" --base latest --state open --json title --jq '.[0].title // empty')
85
+ echo "number=$number" >> "$GITHUB_OUTPUT"
86
+ # Skip when the open pull request already proposes this version
87
+ if [[ -n "$number" && "$title" == *" ${{ steps.check.outputs.published }}" ]]; then
88
+ echo "uptodate=true" >> "$GITHUB_OUTPUT"
89
+ echo "Pull request #$number already updates to ${{ steps.check.outputs.published }}"
90
+ fi
91
+
92
+ - name: Update node-switchbot
93
+ if: steps.check.outputs.level != 'none' && steps.pr.outputs.uptodate != 'true'
94
+ run: |
95
+ git switch -C "$BRANCH"
96
+ npm pkg set "dependencies.node-switchbot=^${{ steps.check.outputs.published }}"
97
+ npx -y npm@11 install --package-lock-only --ignore-scripts
98
+ # Only the dependency may change: never the plugin's own version
99
+ before=$(git show HEAD:package.json | node -p "JSON.parse(require('fs').readFileSync(0)).version")
100
+ after=$(node -p "require('./package.json').version")
101
+ test "$before" = "$after"
102
+ git diff --stat
103
+
104
+ - name: Build, test and lint
105
+ if: steps.check.outputs.level != 'none' && steps.pr.outputs.uptodate != 'true'
106
+ id: verify
107
+ continue-on-error: true
108
+ run: |
109
+ npm ci --legacy-peer-deps
110
+ npm run build
111
+ npm test
112
+ npm run lint
113
+
114
+ - name: Push the update branch
115
+ if: steps.check.outputs.level != 'none' && steps.pr.outputs.uptodate != 'true'
116
+ run: |
117
+ git config user.name 'github-actions[bot]'
118
+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
119
+ # Commit only the dependency change; the build regenerates other files
120
+ git add package.json package-lock.json
121
+ git commit -m "fix(deps): update node-switchbot to ${{ steps.check.outputs.published }}"
122
+ # The branch belongs to this workflow; replace it with an update from current latest
123
+ git push --force origin "$BRANCH"
124
+
125
+ - name: Open or update the pull request
126
+ if: steps.check.outputs.level != 'none' && steps.pr.outputs.uptodate != 'true'
127
+ env:
128
+ GH_TOKEN: ${{ github.token }}
129
+ PUBLISHED: ${{ steps.check.outputs.published }}
130
+ CURRENT: ${{ steps.check.outputs.current }}
131
+ LEVEL: ${{ steps.check.outputs.level }}
132
+ VERIFY: ${{ steps.verify.outcome }}
133
+ NUMBER: ${{ steps.pr.outputs.number }}
134
+ run: |
135
+ title="fix(deps): update node-switchbot to $PUBLISHED"
136
+ if [[ "$VERIFY" == "success" ]]; then
137
+ checks="Build, test and lint passed in the update workflow."
138
+ else
139
+ checks="**Build, test or lint failed** in the [update workflow run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID). The plugin needs changes before this can be merged."
140
+ fi
141
+ major_note=""
142
+ if [[ "$LEVEL" == "major" ]]; then
143
+ major_note=$'\n\n'"**This is a new major version of node-switchbot.** Read its release notes for breaking changes, and test it (or add plugin changes to this branch) before merging."
144
+ fi
145
+ body=$(cat <<EOF
146
+ Updates \`node-switchbot\` from \`^$CURRENT\` to \`^$PUBLISHED\` (a **$LEVEL** update).
147
+
148
+ - [node-switchbot v$PUBLISHED release notes](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v$PUBLISHED)
149
+ - Changes only the \`node-switchbot\` range in \`package.json\` and its entries in \`package-lock.json\`. The plugin's own \`version\` is set by the release workflow when this is merged.
150
+ - Labelled \`$LEVEL\`: merging publishes a $LEVEL plugin release. Change the label before merging for a different kind of release.
151
+
152
+ $checks$major_note
153
+
154
+ _Opened by the "Update node-switchbot" workflow. If a newer node-switchbot is published before this is merged, this pull request is updated to it._
155
+ EOF
156
+ )
157
+ # Create the labels only if missing; never change existing ones
158
+ for label in "$LEVEL" dependencies; do
159
+ gh label create "$label" >/dev/null 2>&1 || true
160
+ done
161
+ if [[ -n "$NUMBER" ]]; then
162
+ gh pr edit "$NUMBER" --title "$title" --body "$body"
163
+ for old in patch minor major; do
164
+ [[ "$old" == "$LEVEL" ]] || gh pr edit "$NUMBER" --remove-label "$old" >/dev/null 2>&1 || true
165
+ done
166
+ gh pr edit "$NUMBER" --add-label "$LEVEL" --add-label dependencies
167
+ echo "Updated pull request #$NUMBER" >> "$GITHUB_STEP_SUMMARY"
168
+ else
169
+ url=$(gh pr create --base latest --head "$BRANCH" --title "$title" --body "$body" \
170
+ --label "$LEVEL" --label dependencies)
171
+ echo "Opened $url" >> "$GITHUB_STEP_SUMMARY"
172
+ fi
173
+
174
+ - name: Run CI on the pull request
175
+ if: steps.check.outputs.level != 'none' && steps.pr.outputs.uptodate != 'true'
176
+ env:
177
+ GH_TOKEN: ${{ github.token }}
178
+ # Pull requests opened with GITHUB_TOKEN do not start CI on their own; workflow_dispatch does,
179
+ # and its checks show on the pull request's commit.
180
+ run: gh workflow run ci.yml --ref "$BRANCH"
@@ -28,7 +28,7 @@
28
28
  </div></li></ul></div>
29
29
  <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources">
30
30
  <ul>
31
- <li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/bd3937a78acb28ef4f3dfa3cbbbc20c9bcbfc9a4/src/index.ts#L23">index.ts:23</a></li></ul></aside></div>
31
+ <li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/d4962d579222c868dce32477f0813130bd9e0b20/src/index.ts#L23">index.ts:23</a></li></ul></aside></div>
32
32
  <div class="col-sidebar">
33
33
  <div class="page-menu">
34
34
  <div class="tsd-navigation settings">
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@switchbot/homebridge-switchbot",
3
3
  "displayName": "SwitchBot",
4
4
  "type": "module",
5
- "version": "5.2.10",
5
+ "version": "5.2.11",
6
6
  "description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
7
7
  "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
8
8
  "contributors": [
@@ -93,7 +93,7 @@
93
93
  "dependencies": {
94
94
  "@homebridge/plugin-ui-utils": "^2.2.6",
95
95
  "class-validator": "^0.15.1",
96
- "node-switchbot": "^6.0.2"
96
+ "node-switchbot": "^6.0.5"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@antfu/eslint-config": "^10.0.0",