forked from vieira/homebridge-yeelight-wifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of homebridge-yeelight-wifi
- Loading branch information
Joao Vieira
committed
Jan 31, 2018
0 parents
commit 406cbe1
Showing
11 changed files
with
1,694 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extends: airbnb-base | ||
rules: | ||
func-names: off | ||
no-param-reassign: | ||
- error | ||
- props: false | ||
no-underscore-dangle: off | ||
no-bitwise: off | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 João Vieira | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Homebridge YeeLight Wi-Fi | ||
|
||
[YeeLight](https://www.yeelight.com) plugin for [Homebridge](https://github.com/nfarina/homebridge) supporting Wi-Fi lighting devices. | ||
|
||
This allows you to control your **YeeLight** wi-fi devices, such as the YeeLight Bulb and the YeeLight Stripe with [HomeKit](https://www.apple.com/ios/home) and Siri. No apps required. | ||
|
||
## Requirements | ||
|
||
- Node.js >= 7.6.0 | ||
- Avahi | ||
|
||
## Installation | ||
|
||
1. Install homebridge, `sudo npm install -g homebridge` | ||
2. Install this plugin using, `npm install -g homebridge-yeelight-wifi` | ||
|
||
## Setting up devices | ||
|
||
Devices that already have the API enabled should be autodiscovered without any other | ||
actions on your part. | ||
|
||
However, out of the factory, the YeeLight devices do come with the API disabled and | ||
you will have to enable it for them to work with Homebridge. To do so, go to settings | ||
and enable **Developer Mode**. | ||
|
||
## Motivation | ||
|
||
When I got my first YeeLight bulb, there was already a homebridge plugin supporting | ||
it, however, it did not deal with transient failures. Frequently I would turn on a | ||
lamp, it would report it as *On* but no sign of light could be seen. Manually turning | ||
the lamp off and on would solve the issue but was a nuisance. | ||
|
||
This plugin was born to solve this issue and end up being a complete rewrite fixing | ||
a lot of other bugs and minor problems and also implementing a cleaner architecture. | ||
|
||
This plugin keeps track of all your commands until a successful response is received | ||
from the lamp. It implements [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) to retry commands to which no response was received or a failure | ||
was reported by the lamp. | ||
|
||
It also keeps track of known lamps and will continue to ocasionally look for them if | ||
they suddenly disappear. This is useful when you accidentally power off a lamp and | ||
later turn it on. | ||
|
||
## Bugs and feature requests | ||
|
||
Please report any issues you might find, on [GitHub](https://github.com/vieira/homebridge-yeelight-wifi/issues). | ||
|
||
Feature requests and specially pull requests are very welcome. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const YeeWhite = require('./white'); | ||
|
||
class YeeColor extends YeeWhite { | ||
constructor(did, model, platform) { | ||
super(did, model, platform); | ||
this.transitions.color = this.transitions.color || 1500; | ||
this.setColor = YeeColor.setColor(); | ||
} | ||
|
||
get hue() { | ||
return this._hue; | ||
} | ||
|
||
set hue(hue) { | ||
this._hue = Number(hue); | ||
} | ||
|
||
get sat() { | ||
return this._sat; | ||
} | ||
|
||
set sat(sat) { | ||
this._sat = Number(sat); | ||
} | ||
|
||
configureServices() { | ||
super.configureServices(); | ||
|
||
const lightbulbService = | ||
this.accessory.getService(global.Service.Lightbulb); | ||
|
||
(lightbulbService.getCharacteristic(global.Characteristic.Hue) | ||
|| lightbulbService.addCharacteristic(global.Characteristic.Hue)) | ||
.on('set', async (value, callback) => { | ||
try { | ||
await this.setColor(value, null); | ||
callback(null, this.hue); | ||
} catch (err) { | ||
callback(err, this.hue); | ||
} | ||
}).updateValue(this.hue); | ||
|
||
(lightbulbService.getCharacteristic(global.Characteristic.Saturation) | ||
|| lightbulbService.addCharacteristic(global.Characteristic.Saturation)) | ||
.on('set', async (value, callback) => { | ||
try { | ||
await this.setColor(null, value); | ||
callback(null, this.sat); | ||
} catch (err) { | ||
callback(err, this.sat); | ||
} | ||
}).updateValue(this.sat); | ||
} | ||
|
||
static setColor() { | ||
let hue; | ||
let sat; | ||
return function (h, s) { | ||
hue = hue || h; | ||
sat = sat || s; | ||
if (!hue || !sat) return Promise.resolve(); | ||
this.setPower(1); | ||
const req = { | ||
method: 'set_hsv', | ||
params: [ | ||
hue, | ||
sat, | ||
'smooth', | ||
this.transitions.color, | ||
], | ||
}; | ||
return this.sendCmd(req).then(() => { | ||
this._hue = hue; | ||
this._sat = sat; | ||
hue = null; | ||
sat = null; | ||
}); | ||
}; | ||
} | ||
} | ||
|
||
module.exports = YeeColor; |
Oops, something went wrong.