this.on('close', () => { this.debug('remove event listeners'); tvService.getCharacteristic(Characteristic.Active) .removeListener('set', setActive); tvService.getCharacteristic(Characteristic.ActiveIdentifier) .removeListener('set', setActiveIdentifier); tvService.getCharacteristic(Characteristic.RemoteKey) .removeListener('set', setRemoteKey); tvService.getCharacteristic(Characteristic.PowerModeSelection) .removeListener('set', setPowerModeSelection); speakerService.getCharacteristic(Characteristic.VolumeSelector) .removeListener('set', setVolumeSelector); });
config.inputsources.forEach((src, i) => { const id = i + 1; const inputService = acc.addService(Service.InputSource, src.name, src.name); inputService .setCharacteristic(Characteristic.Identifier, id) .setCharacteristic(Characteristic.ConfiguredName, src.name) .setCharacteristic(Characteristic.IsConfigured, Characteristic.IsConfigured.CONFIGURED) .setCharacteristic(Characteristic.InputSourceType, src.type) .setCharacteristic(Characteristic.CurrentVisibilityState, Characteristic.CurrentVisibilityState.SHOWN) .setCharacteristic(Characteristic.TargetVisibilityState, Characteristic.TargetVisibilityState.SHOWN); tvService.addLinkedService(inputService); });
this.on('input', msg => { console.log(msg); this.debug('update ProgrammableSwitchEvent SINGLE_PRESS'); doorbellService.getCharacteristic(hap.Characteristic.ProgrammableSwitchEvent).updateValue(0); });
describe('constructor', () => { it('should assign config values to member variables', () => { const homebridge = dummyHomebridge(dummyConfig); const device = dummyConfig.devices[0]; const dummyURL = 'https://some.random.url.com/'; const dummyAccessToken = 'MY_top_SECRET_access_TOKEN'; const Service = homebridge.hap.Service; const Characteristic = homebridge.hap.Characteristic; const accessory = new ActorAccessory( () => {}, dummyURL, dummyAccessToken, device, homebridge, Service.Lightbulb, Characteristic.On ); accessory.url.should.be.equal(dummyURL); accessory.accessToken.should.be.equal(dummyAccessToken); accessory.deviceId.should.be.equal(device.device_id); accessory.services.should.have.length(2); accessory.services[1].should.be.an.instanceOf(Service.Lightbulb); }); });
this.on('input', msg => { switch (msg.topic) { case 'InputSource': { let identifier = msg.payload; if (typeof msg.payload === 'string') { config.inputsources.forEach((src, i) => { if (msg.payload === src.name) { identifier = i + 1; } }); } if (config.inputsources[identifier - 1]) { this.debug('set ActiveIdentifier ' + identifier + ' (payload was ' + msg.payload + ')'); this.status({shape: 'dot', fill: 'blue', text: config.inputsources[identifier - 1].name}); tvService.updateCharacteristic(Characteristic.ActiveIdentifier, identifier); } break; } default: this.debug('set Active ' + msg.payload); this.status({shape: msg.payload ? 'dot' : 'ring', fill: msg.payload ? 'blue' : 'grey'}); tvService.updateCharacteristic(Characteristic.Active, msg.payload ? 1 : 0); } });
.setCharacteristic(hap.Characteristic.Manufacturer, 'RedMatic') .setCharacteristic(hap.Characteristic.Model, 'HAP-Nodejs Bridge') .setCharacteristic(hap.Characteristic.SerialNumber, this.username) .setCharacteristic(hap.Characteristic.FirmwareRevision, pkg.version);
accessory.deviceId.should.be.equal(device.device_id); accessory.ServiceType.should.be.equal(homebridge.hap.Service.HumiditySensor); accessory.CharacteristicType.should.be.equal(homebridge.hap.Characteristic.CurrentRelativeHumidity); }); });
homebridge, Service.HumiditySensor, Characteristic.CurrentRelativeHumidity ); accessory.eventName.should.be.equal(device.event_name);