@homebridge-plugins/homebridge-august 3.2.3 → 3.3.0-beta.0

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.
Files changed (44) hide show
  1. package/.github/npm-version-script-esm.js +97 -0
  2. package/CHANGELOG.md +15 -0
  3. package/dist/Platform.Base.d.ts +288 -0
  4. package/dist/Platform.Base.d.ts.map +1 -0
  5. package/dist/Platform.Base.js +797 -0
  6. package/dist/Platform.Base.js.map +1 -0
  7. package/dist/Platform.HAP.d.ts +20 -139
  8. package/dist/Platform.HAP.d.ts.map +1 -1
  9. package/dist/Platform.HAP.js +46 -733
  10. package/dist/Platform.HAP.js.map +1 -1
  11. package/dist/connectivity-manager.d.ts +3 -3
  12. package/dist/connectivity-manager.d.ts.map +1 -1
  13. package/dist/connectivity-manager.js +57 -14
  14. package/dist/connectivity-manager.js.map +1 -1
  15. package/dist/devices/device.d.ts +5 -16
  16. package/dist/devices/device.d.ts.map +1 -1
  17. package/dist/devices/device.js +18 -75
  18. package/dist/devices/device.js.map +1 -1
  19. package/dist/devices/lock.d.ts +3 -3
  20. package/dist/devices/lock.d.ts.map +1 -1
  21. package/dist/devices/lock.js +41 -41
  22. package/dist/devices/lock.js.map +1 -1
  23. package/dist/index.js +4 -4
  24. package/dist/index.js.map +1 -1
  25. package/dist/package.json +8 -7
  26. package/dist/platform.matter.d.ts +18 -20
  27. package/dist/platform.matter.d.ts.map +1 -1
  28. package/dist/platform.matter.js +74 -80
  29. package/dist/platform.matter.js.map +1 -1
  30. package/docs/variables/default.html +1 -1
  31. package/package.json +8 -7
  32. package/test/device.test.ts +384 -0
  33. package/test/{platform.test.ts → platform.hap.test.ts} +23 -23
  34. package/test/platform.polling.test.ts +5 -5
  35. package/.github/scripts/compute-version-override.cjs +0 -51
  36. package/.github/scripts/normalize-changelog-header.cjs +0 -86
  37. package/.github/scripts/npm-version-script-esm-auto.js +0 -201
  38. package/.github/scripts/resolve-version-bump-esm.js +0 -118
  39. package/dist/devices/device.test.d.ts +0 -2
  40. package/dist/devices/device.test.d.ts.map +0 -1
  41. package/dist/devices/device.test.js +0 -294
  42. package/dist/devices/device.test.js.map +0 -1
  43. package/test/connectivity-manager.test.ts +0 -590
  44. package/test/platform.matter.test.ts +0 -660
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const child_process = require('node:child_process')
4
- const fs = require('node:fs')
5
-
6
- const changelogPath = 'CHANGELOG.md'
7
-
8
- function normalizeChangelogHeader(content) {
9
- const headerStart = content.indexOf('# Changelog\n')
10
- if (headerStart <= 0) {
11
- return content
12
- }
13
-
14
- const nextSectionStart = content.indexOf('\n## ', headerStart + 1)
15
- const headerBlock = (nextSectionStart === -1 ? content.slice(headerStart) : content.slice(headerStart, nextSectionStart)).trim()
16
- const prependedEntries = content.slice(0, headerStart).trim()
17
- const remainingEntries = (nextSectionStart === -1 ? '' : content.slice(nextSectionStart)).trim()
18
-
19
- return [headerBlock, prependedEntries, remainingEntries].filter(Boolean).join('\n\n') + '\n'
20
- }
21
-
22
- function getRepoUrl() {
23
- try {
24
- const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
25
- let url = (typeof pkg.repository === 'string' ? pkg.repository : pkg.repository?.url) || ''
26
- url = url.replace(/^git\+/, '').replace(/\.git$/, '')
27
- if (url.startsWith('https://')) return url
28
- } catch {}
29
- try {
30
- const remote = child_process.execSync('git remote get-url origin').toString().trim()
31
- return remote.replace(/^git\+/, '').replace(/\.git$/, '').replace(/^git@github\.com:/, 'https://github.com/')
32
- } catch {}
33
- return ''
34
- }
35
-
36
- function getPreviousTag() {
37
- try {
38
- const tags = child_process
39
- .execSync('git tag --sort=-version:refname')
40
- .toString()
41
- .trim()
42
- .split('\n')
43
- .filter(Boolean)
44
- return tags[0] || ''
45
- } catch {
46
- return ''
47
- }
48
- }
49
-
50
- function appendFullChangelogLink(content, currentTag, repoUrl) {
51
- const prefix = `**Full Changelog**: ${repoUrl}/compare/`
52
- // Find the bounds of the first release section (the newly generated one)
53
- const firstSectionStart = content.indexOf('\n## ')
54
- if (firstSectionStart === -1) return content
55
- const firstSectionEnd = content.indexOf('\n## ', firstSectionStart + 1)
56
- const firstSection = firstSectionEnd === -1 ? content.slice(firstSectionStart) : content.slice(firstSectionStart, firstSectionEnd)
57
-
58
- // Skip if a Full Changelog link is already present in that section
59
- if (firstSection.includes(prefix)) return content
60
-
61
- const prevTag = getPreviousTag()
62
- if (!prevTag) return content
63
-
64
- const link = `**Full Changelog**: ${repoUrl}/compare/${prevTag}...${currentTag}`
65
- if (firstSectionEnd === -1) {
66
- return content.trimEnd() + '\n\n' + link + '\n'
67
- }
68
- return content.slice(0, firstSectionEnd).trimEnd() + '\n\n' + link + '\n' + content.slice(firstSectionEnd)
69
- }
70
-
71
- exports.preCommit = (props) => {
72
- if (!fs.existsSync(changelogPath)) {
73
- return
74
- }
75
-
76
- let content = fs.readFileSync(changelogPath, 'utf8')
77
- content = normalizeChangelogHeader(content)
78
-
79
- const repoUrl = getRepoUrl()
80
- const currentTag = props?.tag || ''
81
- if (repoUrl && currentTag) {
82
- content = appendFullChangelogLink(content, currentTag, repoUrl)
83
- }
84
-
85
- fs.writeFileSync(changelogPath, content)
86
- }
@@ -1,201 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Standalone ESM implementation — self-contained so this file can be copied
5
- * into other repos without pulling any other files.
6
- */
7
-
8
- import assert from 'node:assert'
9
- import child_process from 'node:child_process'
10
- import fs from 'node:fs'
11
- import process from 'node:process'
12
- // Minimal, in-file semver utilities used by this script.
13
- // This avoids an external dependency so the script can run in environments
14
- // where `semver` isn't installed.
15
- const semver = {
16
- // Very small validation: match major.minor.patch with optional prerelease/build
17
- valid(v) {
18
- return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/.test(v)
19
- },
20
- // Return prerelease identifiers array or null
21
- prerelease(v) {
22
- const m = v.match(/^\d+\.\d+\.\d+-(.+)$/)
23
- return m ? m[1].split('.') : null
24
- },
25
- // Compare two semver strings in reverse order (for rcompare use)
26
- rcompare(a, b) {
27
- // Use standard semver precedence rules for major.minor.patch; ignore prerelease complexity except that prerelease is lower than release
28
- const pa = a.split('-')
29
- const pb = b.split('-')
30
- const aCore = pa[0].split('.').map(Number)
31
- const bCore = pb[0].split('.').map(Number)
32
- for (let i = 0; i < 3; i++) {
33
- if (aCore[i] > bCore[i]) return -1
34
- if (aCore[i] < bCore[i]) return 1
35
- }
36
- // equal core; releases (no prerelease) are greater than prerelease
37
- if (pa.length === 1 && pb.length > 1) return -1
38
- if (pa.length > 1 && pb.length === 1) return 1
39
- // both same prerelease status: compare as strings
40
- if (a > b) return -1
41
- if (a < b) return 1
42
- return 0
43
- },
44
- // Increment version by 'major'|'minor'|'patch'
45
- inc(v, level) {
46
- if (!this.valid(v)) throw new Error(`Invalid semver passed to inc: ${v}`)
47
- // strip prerelease/build
48
- const core = v.split('-')[0].split('+')[0]
49
- const parts = core.split('.').map(Number)
50
- switch (level) {
51
- case 'major':
52
- parts[0] += 1
53
- parts[1] = 0
54
- parts[2] = 0
55
- break
56
- case 'minor':
57
- parts[1] += 1
58
- parts[2] = 0
59
- break
60
- case 'patch':
61
- default:
62
- parts[2] += 1
63
- break
64
- }
65
- return parts.join('.')
66
- }
67
- }
68
-
69
- const BRANCH_VERSION_PATTERN = /^([A-Z]+)-(\d+\.\d+\.\d+)$/i
70
-
71
- // Load package.json
72
- const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf8'))
73
-
74
- const refArgument = process.argv[2]
75
- const tagArgument = process.argv[3] || 'latest'
76
-
77
- if (!refArgument) {
78
- console.error('ref argument is missing')
79
- console.error('Usage: npm-version-script-esm.js <ref> [tag]')
80
- process.exit(1)
81
- }
82
-
83
- /**
84
- * Queries the NPM registry for the latest version for the provided base version and tag.
85
- * If the tag is latest, then the base version is returned if it exists. For other tags, the latest
86
- * version found for that base version and tag is returned.
87
- * @param baseVersion The base version to query for, e.g. 2.0.0
88
- * @param tag The tag to query for, e.g. beta or latest
89
- * @returns {string} Returns the version, or '' if not found
90
- */
91
- function getTagVersionFromNpm(baseVersion, tag) {
92
- try {
93
- return JSON.parse(child_process.execSync(`npm info ${packageJSON.name} versions --json`).toString('utf8').trim())
94
- .filter(v => (tag === 'latest' ? v === baseVersion : v.startsWith(`${baseVersion}-${tag}.`)))
95
- .reduce((_, current) => current, '')
96
- } catch (e) {
97
- console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`, e)
98
- // throw e;
99
- return ''
100
- }
101
- }
102
-
103
- function getLatestStableVersionFromNpm() {
104
- try {
105
- const versions = JSON.parse(child_process.execSync(`npm info ${packageJSON.name} versions --json`).toString('utf8').trim())
106
- if (!Array.isArray(versions) || versions.length === 0) return ''
107
-
108
- // Only consider stable semver versions (no prerelease)
109
- const stable = versions.filter(v => semver.valid(v) && !semver.prerelease(v))
110
- if (stable.length === 0) return ''
111
-
112
- // Sort descending and return the highest
113
- const sorted = stable.sort(semver.rcompare)
114
- return sorted[0]
115
- } catch (e) {
116
- console.error('Failed to query the npm registry for published versions', e)
117
- return ''
118
- }
119
- }
120
-
121
- function desiredTargetVersion(ref) {
122
- // ref is a GitHub action ref string
123
- if (ref.startsWith('refs/pull/')) {
124
- throw new Error('The version script was executed inside a PR!')
125
- }
126
-
127
- assert(ref.startsWith('refs/heads/'))
128
- const branchName = ref.slice('refs/heads/'.length)
129
-
130
- const results = branchName.match(BRANCH_VERSION_PATTERN)
131
- if (results !== null) {
132
- if (results[1].toLowerCase() !== tagArgument.toLowerCase()) {
133
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`)
134
- }
135
-
136
- return results[2]
137
- }
138
-
139
- if (branchName === 'latest') {
140
- // For latest branch, start with package.json version as base
141
- return packageJSON.version
142
- }
143
-
144
- throw new Error(`Malformed branch name for ref: ${ref}. Must be beta-x.x.x, alpha-x.x.x, or 'latest'`)
145
- }
146
-
147
- function bumpVersion(baseVersion, level) {
148
- const normalizedLevel = (level || 'patch').toLowerCase()
149
- if (!semver.valid(baseVersion)) {
150
- throw new Error(`Invalid base version passed to bumpVersion: ${baseVersion}`)
151
- }
152
-
153
- switch (normalizedLevel) {
154
- case 'major':
155
- return semver.inc(baseVersion, 'major')
156
- case 'minor':
157
- return semver.inc(baseVersion, 'minor')
158
- case 'patch':
159
- default:
160
- return semver.inc(baseVersion, 'patch')
161
- }
162
- }
163
-
164
- const baseVersion = desiredTargetVersion(refArgument)
165
- let publishTag = baseVersion
166
-
167
- if (refArgument.includes('latest')) {
168
- // For latest branch, determine next version based on npm and bump patch.
169
- const latestPublishedStable = getLatestStableVersionFromNpm()
170
- if (latestPublishedStable) {
171
- console.warn(`Latest published stable version is ${latestPublishedStable}; bumping patch`)
172
- publishTag = bumpVersion(latestPublishedStable, 'patch')
173
- } else {
174
- console.warn('No published stable versions found; bumping package.json version patch')
175
- publishTag = bumpVersion(baseVersion, 'patch')
176
- }
177
- } else {
178
- // For alpha/beta, query npm for latest
179
- const latestReleasedVersion = getTagVersionFromNpm(baseVersion, tagArgument)
180
- if (latestReleasedVersion) {
181
- console.warn(`Latest published version for ${baseVersion} with tag ${tagArgument} is ${latestReleasedVersion}`)
182
- publishTag = latestReleasedVersion
183
- } else {
184
- console.warn(`No published versions for ${baseVersion} with tag ${tagArgument}`)
185
- }
186
- }
187
-
188
- if (packageJSON.version !== publishTag) {
189
- console.warn(`Updating version in package.json from ${packageJSON.version} to ${publishTag}`)
190
- packageJSON.version = publishTag
191
- fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2))
192
-
193
- // perform the same change to the package-lock.json
194
- const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))
195
- packageLockJSON.version = publishTag
196
- fs.writeFileSync('package-lock.json', JSON.stringify(packageLockJSON, null, 2))
197
- } else {
198
- console.warn(`Version in package.json is already ${packageJSON.version}`)
199
- }
200
-
201
- console.log(publishTag)
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'node:fs'
4
- import https from 'node:https'
5
- import process from 'node:process'
6
-
7
- const allowed = new Set(['major', 'minor', 'patch'])
8
-
9
- function setOutput(name, value) {
10
- if (process.env.GITHUB_OUTPUT) {
11
- fs.appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${value}\n`)
12
- }
13
- console.log(`${name}=${value}`)
14
- }
15
-
16
- function resolveFromLabels(labels) {
17
- const majorLabels = new Set(['major', 'semver:major', 'release:major', 'breaking', 'breaking-change'])
18
- const minorLabels = new Set(['minor', 'semver:minor', 'release:minor', 'feature'])
19
- const patchLabels = new Set(['patch', 'semver:patch', 'release:patch', 'fix'])
20
-
21
- if (labels.some(label => majorLabels.has(label))) return 'major'
22
- if (labels.some(label => minorLabels.has(label))) return 'minor'
23
- if (labels.some(label => patchLabels.has(label))) return 'patch'
24
- return 'patch'
25
- }
26
-
27
- function listPrsForCommit(owner, repo, sha, token) {
28
- return new Promise((resolve, reject) => {
29
- const path = `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/commits/${sha}/pulls`
30
- const req = https.request(
31
- {
32
- hostname: 'api.github.com',
33
- method: 'GET',
34
- path,
35
- headers: {
36
- Accept: 'application/vnd.github+json',
37
- Authorization: `Bearer ${token}`,
38
- 'User-Agent': 'homebridge-resolve-version-bump',
39
- 'X-GitHub-Api-Version': '2022-11-28',
40
- },
41
- },
42
- (res) => {
43
- let body = ''
44
- res.setEncoding('utf8')
45
- res.on('data', (chunk) => {
46
- body += chunk
47
- })
48
- res.on('end', () => {
49
- if (res.statusCode < 200 || res.statusCode >= 300) {
50
- reject(new Error(`GitHub API request failed (${res.statusCode}): ${body}`))
51
- return
52
- }
53
- try {
54
- const parsed = JSON.parse(body)
55
- resolve(Array.isArray(parsed) ? parsed : [])
56
- } catch (error) {
57
- reject(new Error(`Failed to parse GitHub API response: ${error.message}`))
58
- }
59
- })
60
- },
61
- )
62
-
63
- req.on('error', reject)
64
- req.end()
65
- })
66
- }
67
-
68
- async function main() {
69
- const manualInput = (process.argv[2] || '').trim().toLowerCase()
70
- if (manualInput) {
71
- if (!allowed.has(manualInput)) {
72
- console.error(`Invalid version bump '${manualInput}'. Use major, minor, or patch.`)
73
- process.exit(1)
74
- }
75
- console.error(`Using manual version bump input: ${manualInput}`)
76
- setOutput('version_bump', manualInput)
77
- return
78
- }
79
-
80
- const repository = process.env.GITHUB_REPOSITORY || ''
81
- const sha = process.env.GITHUB_SHA || ''
82
- const token = process.env.GITHUB_TOKEN || ''
83
-
84
- if (!repository || !sha || !token || !repository.includes('/')) {
85
- console.error('Missing GITHUB_REPOSITORY, GITHUB_SHA, or GITHUB_TOKEN. Defaulting to patch.')
86
- setOutput('version_bump', 'patch')
87
- return
88
- }
89
-
90
- const [owner, repo] = repository.split('/')
91
-
92
- try {
93
- const prs = await listPrsForCommit(owner, repo, sha, token)
94
- const pr = prs.find((candidate) => candidate.merged_at) || prs[0]
95
-
96
- if (!pr) {
97
- console.error('No PR associated with commit; defaulting to patch.')
98
- setOutput('version_bump', 'patch')
99
- return
100
- }
101
-
102
- const labels = (pr.labels || [])
103
- .map((label) => (typeof label === 'string' ? label : label.name || ''))
104
- .map((label) => label.toLowerCase())
105
-
106
- const bump = resolveFromLabels(labels)
107
- console.error(`Resolved bump '${bump}' from PR #${pr.number} labels: ${labels.join(', ') || '(none)'}`)
108
- setOutput('version_bump', bump)
109
- } catch (error) {
110
- console.error(`Failed to inspect PR labels, defaulting to patch: ${error.message}`)
111
- setOutput('version_bump', 'patch')
112
- }
113
- }
114
-
115
- main().catch((error) => {
116
- console.error(error)
117
- process.exit(1)
118
- })
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=device.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"device.test.d.ts","sourceRoot":"","sources":["../../src/devices/device.test.ts"],"names":[],"mappings":""}