node-red-contrib-homebridge-automation 0.2.1-beta.6 → 0.2.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homebridge-automation",
3
- "version": "0.2.1-beta.6",
3
+ "version": "0.2.1",
4
4
  "description": "NodeRED Automation for HomeBridge",
5
5
  "main": "src/HAP-NodeRed.js",
6
6
  "scripts": {
@@ -76,4 +76,4 @@
76
76
  "!src/test-utils"
77
77
  ]
78
78
  }
79
- }
79
+ }
@@ -52,11 +52,18 @@ class HBConfigNode {
52
52
  */
53
53
  async handleReady() {
54
54
  const updatedDevices = await this.hapClient.getAllServices();
55
+ // Fix broken uniqueId's from HAP-Client
56
+ updatedDevices.forEach((service) => {
57
+ const friendlyName = (service.serviceName ? service.serviceName : service.accessoryInformation.Name);
58
+ service.uniqueId = `${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${friendlyName}${service.uuid.slice(0, 8)}`;
59
+ });
55
60
  updatedDevices.forEach((updatedService, index) => {
56
61
  if (this.hbDevices.find(service => service.uniqueId === updatedService.uniqueId)) {
62
+ // debug(`Exsiting UniqueID breakdown - ${updatedService.serviceName}-${updatedService.instance.username}-${updatedService.aid}-${updatedService.iid}-${updatedService.type}`);
57
63
  const update = this.hbDevices.find(service => service.uniqueId === updatedService.uniqueId);
58
64
  update.instance = updatedService.instance;
59
65
  } else {
66
+ // debug(`New Service UniqueID breakdown - ${updatedService.serviceName}-${updatedService.instance.username}-${updatedService.aid}-${updatedService.iid}-${updatedService.type}`);
60
67
  this.hbDevices.push(updatedService);
61
68
  }
62
69
  });
@@ -81,7 +88,7 @@ class HBConfigNode {
81
88
  name: (service.serviceName ? service.serviceName : service.accessoryInformation.Name),
82
89
  fullName: `${(service.serviceName ? service.serviceName : service.accessoryInformation.Name)} - ${service.humanType}`,
83
90
  sortName: `${(service.serviceName ? service.serviceName : service.accessoryInformation.Name)}:${service.type}`,
84
- uniqueId: `${service.instance.name}${service.instance.username}${service.accessoryInformation.Manufacturer}${(service.serviceName ? service.serviceName : service.accessoryInformation.Name)}${service.uuid.slice(0, 8)}`,
91
+ uniqueId: service.uniqueId,
85
92
  homebridge: service.instance.name,
86
93
  service: service.type,
87
94
  manufacturer: service.accessoryInformation.Manufacturer,
@@ -1,85 +0,0 @@
1
- #!/bin/env node
2
-
3
- /**
4
- * This scripts queries the npm registry to pull out the latest version for a given tag.
5
- */
6
-
7
- const assert = require('node:assert')
8
- const child_process = require('node:child_process')
9
- const fs = require('node:fs')
10
- const process = require('node:process')
11
-
12
- const semver = require('semver')
13
-
14
- const BRANCH_VERSION_PATTERN = /^([A-Z]+)-(\d+\.\d+\.\d+)$/i
15
-
16
- // Load the contents of the package.json file
17
- const packageJSON = JSON.parse(fs.readFileSync('package.json', 'utf8'))
18
-
19
- const refArgument = process.argv[2]
20
- const tagArgument = process.argv[3] || 'latest'
21
-
22
- if (refArgument == null) {
23
- console.error('ref argument is missing')
24
- console.error('Usage: npm-version-script.js <ref> [tag]')
25
- process.exit(1)
26
- }
27
-
28
- /**
29
- * Queries the NPM registry for the latest version for the provided tag.
30
- * @param tag The tag to query for.
31
- * @returns {string} Returns the version.
32
- */
33
- function getTagVersionFromNpm(tag) {
34
- try {
35
- return child_process.execSync(`npm info ${packageJSON.name} version --tag="${tag}"`).toString('utf8').trim()
36
- } catch (e) {
37
- console.error(`Failed to query the npm registry for the latest version for tag: ${tag}`)
38
- // throw e;
39
- return '0.0.0'
40
- }
41
- }
42
-
43
- function desiredTargetVersion(ref) {
44
- // ref is a GitHub action ref string
45
- if (ref.startsWith('refs/pull/')) {
46
- throw new Error('The version script was executed inside a PR!')
47
- }
48
-
49
- assert(ref.startsWith('refs/heads/'))
50
- const branchName = ref.slice('refs/heads/'.length)
51
-
52
- const results = branchName.match(BRANCH_VERSION_PATTERN)
53
- if (results != null) {
54
- if (results[1] !== tagArgument) {
55
- console.warn(`The base branch name (${results[1]}) differs from the tag name ${tagArgument}`)
56
- }
57
-
58
- return results[2]
59
- }
60
-
61
- throw new Error(`Malformed branch name for ref: ${ref}. Can't derive the base version. Use a branch name like: beta-x.x.x or alpha-x.x.x`)
62
- }
63
-
64
- // derive the base version from the branch ref
65
- const baseVersion = desiredTargetVersion(refArgument)
66
-
67
- // query the npm registry for the latest version of the provided tag name
68
- const latestReleasedVersion = getTagVersionFromNpm(tagArgument) // e.g. 0.7.0-beta.12
69
- const latestReleaseBase = semver.inc(latestReleasedVersion, 'patch') // will produce 0.7.0 (removing the preid, needed for the equality check below)
70
-
71
- let publishTag
72
- if (semver.eq(baseVersion, latestReleaseBase)) { // check if we are releasing another version for the latest beta or alpha
73
- publishTag = latestReleasedVersion // set the current latest beta or alpha to be incremented
74
- } else {
75
- publishTag = baseVersion // start of with a new beta or alpha version
76
- }
77
-
78
- // save the package.json
79
- packageJSON.version = publishTag
80
- fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2))
81
-
82
- // perform the same change to the package-lock.json
83
- const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'))
84
- packageLockJSON.version = publishTag
85
- fs.writeFileSync('package-lock.json', JSON.stringify(packageLockJSON, null, 2))