Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember listeners on AccessoryInformation if returned by getServices #2169

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 26 additions & 13 deletions lib/server.js
Expand Up @@ -437,28 +437,41 @@ Server.prototype._createAccessory = function(accessoryInstance, displayName, acc
if (service instanceof Service.AccessoryInformation) {
var existingService = accessory.getService(Service.AccessoryInformation);

// pull out any values you may have defined
var manufacturer = service.getCharacteristic(Characteristic.Manufacturer).value;
var model = service.getCharacteristic(Characteristic.Model).value;
var serialNumber = service.getCharacteristic(Characteristic.SerialNumber).value;
var firmwareRevision = service.getCharacteristic(Characteristic.FirmwareRevision).value;
var hardwareRevision = service.getCharacteristic(Characteristic.HardwareRevision).value;

if (manufacturer) existingService.setCharacteristic(Characteristic.Manufacturer, manufacturer);
if (model) existingService.setCharacteristic(Characteristic.Model, model);
if (serialNumber) existingService.setCharacteristic(Characteristic.SerialNumber, serialNumber);
if (firmwareRevision) existingService.setCharacteristic(Characteristic.FirmwareRevision, firmwareRevision);
if (hardwareRevision) existingService.setCharacteristic(Characteristic.HardwareRevision, hardwareRevision);
this._augmentService(service, existingService, Characteristic.Name);
this._augmentService(service, existingService, Characteristic.Manufacturer);
this._augmentService(service, existingService, Characteristic.Model);
this._augmentService(service, existingService, Characteristic.SerialNumber);
this._augmentService(service, existingService, Characteristic.FirmwareRevision);
this._augmentService(service, existingService, Characteristic.HardwareRevision);
}
else {
accessory.addService(service);
}
});
}.bind(this));

return accessory;
}
}

Server.prototype._augmentService = function(srcService, dstService, characteristicUUID) {
var srcCharacteristic = srcService.getCharacteristic(characteristicUUID);
var dstCharacteristic = dstService.getCharacteristic(characteristicUUID);

if (!srcCharacteristic) return;
Copy link
Member

Choose a reason for hiding this comment

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

This will always return false, as "getCharacteristic" will create the characteristic if it is not present.


if (srcCharacteristic.value) dstService.setCharacteristic(characteristicUUID, srcCharacteristic.value);

var listeners = srcCharacteristic.listeners('get');
if (listeners.length === 0) return;

listeners.reverse();
for (var index in listeners) {
var listener = listeners[index];

dstCharacteristic.prependListener('get', listener);
}
}

Server.prototype._handleRegisterPlatformAccessories = function(accessories) {
var hapAccessories = [];
for (var index in accessories) {
Expand Down