homebridge-zwave-usb 2.7.0 → 2.8.4

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.
@@ -39,13 +39,13 @@ class ZWaveAccessory {
39
39
  }
40
40
  }
41
41
  const existingAccessory = this.platform.accessories.find((accessory) => accessory.UUID === uuid);
42
+ const nodeName = this.node.name || this.node.deviceConfig?.label || `Node ${this.node.nodeId}`;
42
43
  if (existingAccessory) {
43
44
  this.platformAccessory = existingAccessory;
44
45
  }
45
46
  else {
46
- const accessoryName = `Node ${this.node.nodeId}`;
47
- this.platform.log.info(`Creating new accessory for ${accessoryName} (UUID: ${uuid})`);
48
- this.platformAccessory = new this.platform.api.platformAccessory(accessoryName, uuid);
47
+ this.platform.log.info(`Creating new accessory for ${nodeName} (UUID: ${uuid})`);
48
+ this.platformAccessory = new this.platform.api.platformAccessory(nodeName, uuid);
49
49
  this.platform.api.registerPlatformAccessories('homebridge-zwave-usb', 'ZWaveUSB', [
50
50
  this.platformAccessory,
51
51
  ]);
@@ -53,12 +53,16 @@ class ZWaveAccessory {
53
53
  }
54
54
  // Set accessory information
55
55
  const manufacturer = this.node.deviceConfig?.manufacturer || 'Unknown';
56
- const model = this.node.deviceConfig?.label || `Node ${this.node.nodeId}`;
57
- this.platformAccessory
58
- .getService(this.platform.Service.AccessoryInformation)
56
+ const model = this.node.deviceConfig?.label || nodeName;
57
+ const infoService = this.platformAccessory.getService(this.platform.Service.AccessoryInformation);
58
+ infoService
59
59
  .setCharacteristic(this.platform.Characteristic.Manufacturer, manufacturer)
60
60
  .setCharacteristic(this.platform.Characteristic.Model, model)
61
61
  .setCharacteristic(this.platform.Characteristic.SerialNumber, `Node ${this.node.nodeId}`);
62
+ if (!infoService.testCharacteristic(this.platform.Characteristic.Name)) {
63
+ infoService.addOptionalCharacteristic(this.platform.Characteristic.Name);
64
+ }
65
+ infoService.updateCharacteristic(this.platform.Characteristic.Name, nodeName);
62
66
  /**
63
67
  * Helper to normalize UUIDs for reliable comparison during metadata pruning.
64
68
  */
@@ -96,11 +100,13 @@ class ZWaveAccessory {
96
100
  infoService.getCharacteristic(this.platform.Characteristic.Name)
97
101
  .setProps({
98
102
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
- format: settings_1.HAPFormat.STRING,
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
103
  perms: [settings_1.HAPPerm.PAIRED_READ, settings_1.HAPPerm.NOTIFY],
102
104
  });
103
105
  infoService.updateCharacteristic(this.platform.Characteristic.Name, newName);
106
+ // Force metadata invalidation by updating the revision
107
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
108
+ const version = require('../../package.json').version;
109
+ infoService.updateCharacteristic(this.platform.Characteristic.SoftwareRevision, version);
104
110
  // Update the Model and Serial if they were using the generic name
105
111
  const model = this.node.deviceConfig?.label || newName;
106
112
  infoService.setCharacteristic(this.platform.Characteristic.Model, model);
@@ -26,6 +26,7 @@ class BaseFeature {
26
26
  */
27
27
  rename(newName) {
28
28
  const serviceName = this.endpoint.index > 0 ? `${newName} ${this.endpoint.index}` : newName;
29
+ this.platform.log.debug(`Feature Rename [Node ${this.node.nodeId}]: Updating ${this.managedServices.length} services to "${serviceName}"`);
29
30
  for (const service of this.managedServices) {
30
31
  if (service.testCharacteristic(this.platform.Characteristic.Name)) {
31
32
  service.updateCharacteristic(this.platform.Characteristic.Name, serviceName);
@@ -80,29 +81,28 @@ class BaseFeature {
80
81
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
82
  this.accessory.addService(new serviceType(serviceName));
82
83
  }
83
- // Explicitly set the name characteristic to ensure it's displayed correctly
84
- const nameChar = service.getCharacteristic(this.platform.Characteristic.Name);
85
- nameChar
86
- .setProps({
84
+ // Mark the first functional service as primary to help HomeKit with naming/tiles
85
+ if (this.managedServices.length === 0) {
87
86
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
- format: settings_1.HAPFormat.STRING,
87
+ service.setPrimaryService(true);
88
+ }
89
+ // Explicitly set the name characteristic with NOTIFY to ensure it's displayed correctly
90
+ service.getCharacteristic(this.platform.Characteristic.Name)
91
+ .setProps({
89
92
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
93
  perms: [settings_1.HAPPerm.PAIRED_READ, settings_1.HAPPerm.NOTIFY],
91
- })
92
- .updateValue(serviceName);
94
+ });
95
+ service.updateCharacteristic(this.platform.Characteristic.Name, serviceName);
93
96
  // Also set ConfiguredName which many HomeKit versions prioritize for plugin-side renaming
94
97
  if (!service.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
95
98
  service.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
96
99
  }
97
- service
98
- .getCharacteristic(this.platform.Characteristic.ConfiguredName)
100
+ service.getCharacteristic(this.platform.Characteristic.ConfiguredName)
99
101
  .setProps({
100
102
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- format: settings_1.HAPFormat.STRING,
102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
103
  perms: [settings_1.HAPPerm.PAIRED_READ, settings_1.HAPPerm.NOTIFY],
104
- })
105
- .updateValue(serviceName);
104
+ });
105
+ service.updateCharacteristic(this.platform.Characteristic.ConfiguredName, serviceName);
106
106
  // Add Service Label Index for multi-endpoint devices to help with ordering/naming
107
107
  if (this.endpoint.index > 0) {
108
108
  if (!service.testCharacteristic(this.platform.Characteristic.ServiceLabelIndex)) {
@@ -344,7 +344,8 @@ class ZWaveUsbPlatform {
344
344
  if (existing || this.discoveryInFlight.has(node.nodeId)) {
345
345
  if (existing) {
346
346
  existing.updateNode(node);
347
- if (existing.platformAccessory.displayName !== nodeName) {
347
+ // Force sync names on every ready event if we have a friendly name
348
+ if (node.name) {
348
349
  existing.rename(nodeName);
349
350
  }
350
351
  existing.refresh();
@@ -355,10 +356,9 @@ class ZWaveUsbPlatform {
355
356
  try {
356
357
  const accessory = AccessoryFactory_1.AccessoryFactory.create(this, node, homeId);
357
358
  this.zwaveAccessories.set(node.nodeId, accessory);
358
- if (accessory.platformAccessory.displayName !== nodeName) {
359
- accessory.rename(nodeName);
360
- }
361
- accessory.initialize();
359
+ accessory.initialize(); // Initialize first to create functional services
360
+ // Force sync names immediately after initialization
361
+ accessory.rename(nodeName);
362
362
  }
363
363
  finally {
364
364
  this.discoveryInFlight.delete(node.nodeId);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-zwave-usb",
3
3
  "displayName": "Homebridge Z-Wave USB",
4
- "version": "2.7.0",
4
+ "version": "2.8.4",
5
5
  "description": "A Homebridge dynamic platform plugin for Z-Wave USB controllers using zwave-js.",
6
6
  "license": "Polyform-Noncommercial-1.0.0",
7
7
  "funding": {