diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9a5d6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + +node_modules/ + +.homeybuild/ diff --git a/README.md b/README.md index 7a09dca..f62c7d1 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,11 @@ -This App brings support for the "Xiaomi Yeelight Candela BLE Lights". +Introducing support for the "Xiaomi Yeelight Candela BLE Lights," this application offers the following functionalities: ![](upload://fpe2l5YlFvJoKPWXrmL6uem0d8N.jpeg) -Link to: [Official Site](https://www.yeelight.com/en_US/product/gingko) +Visit the [Official Site](https://www.yeelight.com/en_US/product/gingko) to learn more about the product. **Features:** -- Turn light on. -- Turn light off. -- Set brightness. - -**Known shortcommings:** - -- No state feedback - -**Version Information:** - -0.0.4: - -- Initial version. - - 0.0.5 - -- Added brandcollor. -- Added Notification UUID, (not been able to use it yet.) -- Changed Readme. +- Power on the light. +- Power off the light. +- Adjust the brightness level. \ No newline at end of file diff --git a/api.js b/api.js deleted file mode 100644 index 9a4b3b6..0000000 --- a/api.js +++ /dev/null @@ -1,3 +0,0 @@ -const Homey = require("homey"); - -module.exports = []; diff --git a/app.js b/app.js index eb74641..485d9b0 100644 --- a/app.js +++ b/app.js @@ -1,26 +1,8 @@ -"use strict"; - const Homey = require("homey"); class CandelaApp extends Homey.App { onInit() { this.log("Cluster Lights App is running!"); - - Homey.on("unload", () => { - this.log("App unload."); - }); - - Homey.on("memwarn", () => { - this.log("App memwarn."); - }); - - process.on("unhandledRejection", error => { - this.log("unhandledRejection: ", error); - }); - - process.on("uncaughtException", error => { - this.log("uncaughtException: ", error); - }); } } diff --git a/app.json b/app.json index 1ad8d0d..458bb79 100644 --- a/app.json +++ b/app.json @@ -1,8 +1,8 @@ { "id": "nl.nielsdeklerk.XiaomiYeelightCandela", "version": "0.0.5", - "compatibility": ">2.4.0", - "sdk": 2, + "compatibility": ">=5.0.0", + "sdk": 3, "brandColor": "#DF2D31", "permissions": ["homey:wireless:ble"], "name": { @@ -28,6 +28,10 @@ { "name": "Niels de Klerk", "email": "mail@nielsdeklerk.nl" + }, + { + "name": "Martijn Poppen", + "email": "yeelight@martijnpoppen.nl" } ] }, @@ -42,7 +46,6 @@ "url": "https://github.com/nklerk/nl.nielsdeklerk.XiaomiYeelightCandela" }, "homeyCommunityTopicId": 16518, - "capabilities": {}, "drivers": [ { "id": "candela", @@ -80,12 +83,7 @@ "id": "add_devices", "template": "add_devices" } - ], - "settings": [] + ] } - ], - "flow": { - "triggers": [], - "actions": [] - } + ] } diff --git a/drivers/candela/device.js b/drivers/candela/device.js index 3c1e697..693f3d3 100644 --- a/drivers/candela/device.js +++ b/drivers/candela/device.js @@ -1,5 +1,3 @@ -"use strict"; - const Homey = require("homey"); const COMMAND_ON = Buffer.from("4340010101f4", "hex"); @@ -7,7 +5,7 @@ const COMMAND_OFF = Buffer.from("4340020101f4", "hex"); const COMMAND_DIM_HEADER = "4342"; const COMMAND_DIM_FOOTER = "0101f4"; -const SERVICE_UUID = "fe87"; +const SERVICE_UUID = "0000fe8700001000800000805f9b34fb"; const SERVICE_NOTIFY_UUID = "8f65073d9f574aaaafea397d19d5bbeb"; const SERVICE_COMMAND_UUID = "aa7d3f342d4f41e0807f52fbf8cf7443"; @@ -20,15 +18,11 @@ class CandelaBle extends Homey.Device { async connectBleService() { try { - const BLEdevice = await Homey.ManagerBLE.find(this.getData().id); - - //Workaround for BUGs in ManagerBLE, (Cashing Bug, Connection Bug) - if (BLEdevice.__peripheral) { - BLEdevice.__peripheral = null; - } + const BLEdevice = await this.homey.ble.find(this.getData().id); - this.log("Connecting to BLE device"); + this.log("Connecting to BLE device", BLEdevice); this.connectedBLEdevice = await BLEdevice.connect(); + const BleService = await this.connectedBLEdevice.getService(SERVICE_UUID); return Promise.resolve(BleService); @@ -60,30 +54,43 @@ class CandelaBle extends Homey.Device { registerAtHomey() { this.registerCapabilityListener("onoff", async value => { this.log(`Power is set to: ${value}`); - if (value) { + if (value && this.getCapabilityValue('dim') === 0) { + const brightnessHex = ("0" + Number(10).toString(16)).slice(-2); + const command = COMMAND_DIM_HEADER + brightnessHex + COMMAND_DIM_FOOTER; + + const levelBuffer = Buffer.from(command, "hex"); + + await this.sendCommand(COMMAND_ON); + await this.sendCommand(levelBuffer); + + return Promise.resolve(true); + } else if (value) { + await this.sendCommand(COMMAND_ON); + return Promise.resolve(true); } else { await this.sendCommand(COMMAND_OFF); + return Promise.resolve(true); } - return Promise.resolve(true); }); this.registerCapabilityListener("dim", async value => { this.log(`Brightness is set to ${value}`); const brightness = parseInt(100 * value); - let command = ""; + if (brightness == 0) { - command = COMMAND_OFF; + await this.sendCommand(COMMAND_OFF); + return Promise.resolve(true); } else { const brightnessHex = ("0" + Number(brightness).toString(16)).slice(-2); - command = COMMAND_DIM_HEADER + brightnessHex + COMMAND_DIM_FOOTER; - } - let levelBuffer = Buffer.from(command, "hex"); + const command = COMMAND_DIM_HEADER + brightnessHex + COMMAND_DIM_FOOTER; - await this.sendCommand(levelBuffer); //this.ds.dimLevel(value)); + const levelBuffer = Buffer.from(command, "hex"); - return Promise.resolve(true); + await this.sendCommand(levelBuffer); //this.ds.dimLevel(value)); + return Promise.resolve(true); + } }); } } diff --git a/drivers/candela/driver.js b/drivers/candela/driver.js index 037c445..af77646 100644 --- a/drivers/candela/driver.js +++ b/drivers/candela/driver.js @@ -12,29 +12,34 @@ class CandelaBleDriver extends Homey.Driver { async discoverLights() { this.log("Discovering Candela BLE devices."); try { - const discoveredDevices = await Homey.ManagerBLE.discover([SERVICE_UUID]); - const mappedDiscoveredDevices = discoveredDevices.map(bleDevice => { - const device = { - name: `${PRESENTATION_NAME} ${bleDevice.address.substr(bleDevice.address.length - 5)}`, - data: { id: bleDevice.uuid } - }; + const discoveredDevices = await this.homey.ble.discover([SERVICE_UUID]); + const mappedDiscoveredDevices = discoveredDevices.map((bleDevice) => ({ + name: `${PRESENTATION_NAME} ${bleDevice.address.substr( + bleDevice.address.length - 5 + )}`, + data: { id: bleDevice.uuid }, + })); - return device; - }); return Promise.resolve(mappedDiscoveredDevices); } catch (error) { return Promise.reject(error); } } - onPairListDevices(data, callback) { - this.discoverLights() - .then(deviceList => { - callback(null, deviceList); - }) - .catch(error => { - callback(error); - }); + async onPair(session) { + session.setHandler("list_devices", async () => { + try { + const devices = await this.discoverLights(); + + if(devices.length) { + return devices; + } + + return []; + } catch (error) { + this.log(error); + } + }); } } diff --git a/locales/en.json b/locales/en.json deleted file mode 100644 index d920faf..0000000 --- a/locales/en.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "settings": {} -} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +