-
-
Save robertklep/cbe45324aa73e1bb7daf0ccb088250db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { HttpClient, IPDiscovery } = require('../modules/hap-controller'); | |
const { Device } = require('../lib'); | |
const discovery = new IPDiscovery(); | |
discovery.on('serviceUp', async (service) => { | |
const device = Device.fromJSON(service); | |
if (device.name !== 'Simple Light') return; | |
const client = new HttpClient(device.id, device.address, device.port); | |
await client.pairSetup('031-45-154'); | |
const pairingData = client.getLongTermData(); | |
const accessories = await client.getAccessories(); | |
console.log(JSON.stringify(accessories, null, 2)); | |
}).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { HttpClient, IPDiscovery } = require('../modules/hap-controller'); | |
const { Accessory } = require('../drivers/accessory/lib/homekit'); | |
const discovery = new IPDiscovery(); | |
const pairingData = require('./pairingdata.json'); | |
discovery.on('serviceUp', (service) => { | |
if (! (service.name in pairingData)) return; | |
console.log('Found device!', service.name); | |
const client = new HttpClient( | |
service.id, | |
service.address, | |
service.port, | |
pairingData[service.name], | |
); | |
client.getAccessories().then(response => { | |
const accessories = response.accessories.map(acc => Accessory.fromJSON(acc)); | |
console.log(JSON.stringify(accessories, null, 2)); | |
}).catch((e) => console.error(e)); | |
}); | |
discovery.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {HttpClient, IPDiscovery} = require('../modules/hap-controller'); | |
const discovery = new IPDiscovery(); | |
const ID = 'CC:22:3D:E3:A1:30'; | |
const HOST = '192.168.23.13'; | |
const PORT = 51826; | |
const PIN = '012-01-012'; | |
/* | |
const client = new HttpClient('CC:22:3D:E3:A1:30', '192.168.23.13', 51826); | |
client.pairSetup(pin).then(() => { | |
console.log('Paired! Keep the following pairing data safe:'); | |
console.log(JSON.stringify(client.getLongTermData(), null, 2)); | |
}).catch((e) => console.error(e)); | |
*/ | |
discovery.on('serviceUp', (service) => { | |
console.log('Found device!', service); | |
}).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { HttpClient, IPDiscovery } = require('../modules/hap-controller'); | |
const discovery = new IPDiscovery(); | |
const pin = '031-45-154'; | |
discovery.on('serviceUp', (service) => { | |
if (service.name !== 'Simple Light') return; | |
console.log('Found device!', service); | |
const client = new HttpClient(service.id, service.address, service.port); | |
client.pairSetup(pin).then(() => { | |
console.log('Paired! Keep the following pairing data safe:'); | |
console.log(JSON.stringify(client.getLongTermData(), null, 2)); | |
}).catch((e) => console.error('E', e)); | |
}); | |
discovery.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Accessory } = require('../drivers/accessory/lib/homekit/'); | |
const response = require('./accessories.json'); | |
//const accessories = response.accessories.map(acc => Accessory.fromJSON(acc)); | |
for (const acc of response.accessories) { | |
const accessory = Accessory.fromJSON(acc); | |
console.log('%j', accessory.toHomey()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HomeKit = require('homekit'); | |
const uuid = HomeKit.uuid.generate("homekit:yeelight"); | |
const acce = new HomeKit.Accessory('Simple Light', uuid); | |
acce.on('identify', function(paired, callback) { | |
console.log("Identify!"); | |
callback(); // success | |
}); | |
acce | |
.addService(HomeKit.Service.Lightbulb, 'Yeelight') | |
.getCharacteristic(HomeKit.Characteristic.On) | |
.on('set', function(value, callback) { | |
console.log('set to', value); | |
callback(); | |
}) | |
// Publish the Accessory on the local network. | |
acce.publish({ | |
port : 51832, | |
username: "CC:AA:CC:AA:CC:AA", | |
pincode : "000-00-000", | |
category: HomeKit.Accessory.Categories.LIGHTBULB, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment