Skip to content

Commit

Permalink
Release 2.12.0
Browse files Browse the repository at this point in the history
jghaanstra committed Jul 11, 2019
1 parent fc48e86 commit 3472ddb
Showing 10 changed files with 426 additions and 17 deletions.
7 changes: 4 additions & 3 deletions APPSTORE.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@ This app uses an unofficial library called the [miIO Device Library](https://git
## Supported devices
Below is a list of supported devices and devices. Post a comment in the [support topic](https://forum.athom.com/discussion/3295/) if you would like to see support for a specific device, some devices might already be supported by the miio library but just need to be implemented. For devices not yet support by the miio library you need technical knowledge to discover the device properties yourself as described [here](https://github.com/aholstenson/miio/blob/master/docs/missing-devices.md).
* Yeelights: Bulbs Wi-Fi, LED strips, Bedside Lamp II, Ceiling Lights, Desk Lamp
* Xiaomi Philips Lights
* Xiaomi Philips Light Bulbs
* Philips Eyecare Light
* Xiaomi Robot Vacuum Cleaner V1 and V2/S50, S6
* Xiaomi Air Purifiers 2, 2S and Pro
* Xiamomi Humidifier v1 & v2
@@ -27,5 +28,5 @@ For Homey to be able to communicate with devices over the miIO protocol a unique
Xiaomi has released an update for the vacuum cleaners that enables zone cleaning and goto function. Using the action cards that utilize these functions are a bit challenging. If you want to use these cards please read the instructions [here](https://github.com/jghaanstra/com.xiaomi-miio/blob/master/docs/mirobot_zonecleanup.md).

## Changelog
### v2.11.11 - 2019-06-21
* FIX: fix for support for Yeelight Meteorite
### v2.12.0 - 2019-07-11
* NEW: re-added support for the Philips Eyecare lamp
65 changes: 64 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
"en": [ "Xiaomi", "Mi", "Mi Home", "miio", "vacuumcleaner", "robot", "yeelight", "yeelights", "purifier", "humidifier", "philips", "eyecare", "powerplug", "gateway" ],
"nl": [ "Xiaomi", "Mi", "Mi home", "miio", "stofzuiger", "robot", "yeelight", "yeelights", "luchtreiniger", "luchtbevochtiger", "philips", "eyecare", "powerplug", "gateway" ]
},
"version": "2.11.11",
"version": "2.12.0",
"compatibility": ">=2.0.0",
"author": {
"name": "Jelger Haanstra",
@@ -173,6 +173,69 @@
}
]
},
{
"id": "philips-eyecare",
"name": {
"en": "Philips Eyecare Lamp",
"nl": "Philips Eyecare Lamp"
},
"images": {
"large": "drivers/philips-eyecare/assets/images/large.jpg",
"small": "drivers/philips-eyecare/assets/images/small.jpg"
},
"class": "light",
"capabilities": [
"onoff",
"dim"
],
"pair": [
{
"id": "start"
}
],
"settings": [
{
"type": "group",
"label": {
"en": "Philips Eyecare Lamp Settings",
"nl": "Philips Eyecare Lamp Instellingen"
},
"children": [
{
"id": "address",
"type": "text",
"value": "0.0.0.0",
"label": {
"en": "IP Address",
"nl": "IP Adres"
}
},
{
"id": "token",
"type": "text",
"value": "",
"label": {
"en": "Philips Light Bulb Token",
"nl": "Philips Light Bulb Token"
}
},
{
"id": "polling",
"type": "number",
"value": 10,
"attr": {
"min": 5,
"max": 3600
},
"label": {
"en": "Philips Light Bulb Polling",
"nl": "Philips Light Bulb Polling"
}
}
]
}
]
},
{
"id": "mi-robot",
"name": {
35 changes: 35 additions & 0 deletions drivers/philips-eyecare/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/philips-eyecare/assets/images/large.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/philips-eyecare/assets/images/small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions drivers/philips-eyecare/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

const Homey = require('homey');
const util = require('/lib/util.js');
const miio = require('miio');

class PhilipsEyecareDevice extends Homey.Device {

onInit() {
this.createDevice();

this.registerCapabilityListener('onoff', this.onCapabilityOnoff.bind(this));
this.registerCapabilityListener('dim', this.onCapabilityDim.bind(this));
}

onDeleted() {
clearInterval(this.pollingInterval);
this.miio.destroy();
}

// LISTENERS FOR UPDATING CAPABILITIES
onCapabilityOnoff(value, opts, callback) {
this.miio.setPower(value)
.then(result => { callback(null, value) })
.catch(error => { callback(error, false) });
}

onCapabilityDim(value, opts, callback) {
var brightness = value * 100;
this.miio.setBrightness(brightness)
.then(result => { callback(null, value) })
.catch(error => { callback(error, false) });
}

// HELPER FUNCTIONS
createDevice() {
miio.device({
address: this.getSetting('address'),
token: this.getSetting('token')
}).then(miiodevice => {
this.miio = miiodevice;

var interval = this.getSetting('polling') || 60;
this.pollDevice(interval);
}).catch(function (error) {
this.log(error);
});
}

pollDevice(interval) {
clearInterval(this.pollingInterval);

this.pollingInterval = setInterval(() => {
const getData = async () => {
try {
const power = await this.miio.power();
const brightness = await this.miio.brightness()
const mode = await this.miio.mode();
const eyecare = await this.miio.eyeCareMode();

if (this.getCapabilityValue('onoff') != power) {
this.setCapabilityValue('onoff', power);
}
var dim = brightness / 100;
if (this.getCapabilityValue('dim') != dim) {
this.setCapabilityValue('dim', dim);
}
if (this.getStoreValue('mode') != mode) {
this.setStoreValue('mode', mode);
}
if (this.getStoreValue('eyecare') != eyecare) {
this.setStoreValue('eyecare', eyecare);
}
if (!this.getAvailable()) {
this.setAvailable();
}
} catch (error) {
this.setUnavailable(Homey.__('unreachable'));
this.log(error);
}
}
getData();
}, 1000 * interval);
}
}

module.exports = PhilipsEyecareDevice;
42 changes: 42 additions & 0 deletions drivers/philips-eyecare/driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";

const Homey = require('homey');
const miio = require('miio');

class PhilipsEyecareDriver extends Homey.Driver {

onPair(socket) {
socket.on('testConnection', function(data, callback) {
miio.device({
address: data.address,
token: data.token
}).then(device => {
const getData = async () => {
try {
const power = await device.power();
const brightness = await device.brightness()
const mode = await device.mode();
const eyecare = await device.eyeCareMode();

let result = {
onoff: power,
brightness: brightness,
mode: mode,
eyecare: eyecare
}

callback(null, result);
} catch (error) {
callback(error, null);
}
}
getData();
}).catch(function (error) {
callback(error, null);
});
});
}

}

module.exports = PhilipsEyecareDriver;
156 changes: 156 additions & 0 deletions drivers/philips-eyecare/pair/start.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<script type="text/javascript">

Homey.setTitle( __('pair.title') );

$(function() {
$('#test-connection').click(function() {
$('.mi-device-test').hide();
$('.mi-device-error').hide();
$('.mi-device-ok').hide();

var inputaddress = $('#address').val();
var inputtoken = $('#token').val();

if (inputaddress != '' && inputtoken != '') {
var device_data = {
address: inputaddress,
token: inputtoken
};

Homey.emit('testConnection', device_data, function(error, result) {
if(error) {
$('.mi-device-error').show();
$('.mi-device-error-msg').html(error.message || error.toString());
} else if (result) {
$('#mode').val(result.mode);
var powered = ((result.onoff) ? "On" : "Off");
var eyecare = ((result.eyecare) ? "On" : "Off");
var mideviceinfo = "<h2 data-i18n='pair.philipseyecare'>Philips Eyecare Lamp</h2><div class='info-row'><span class='info-label' data-i18n='pair.powered'>Powered:</span><span class='info-value'> "+ powered +"</span></div><div class='info-row'><span class='info-label' data-i18n='pair.dim'>Dim Level:</span><span class='info-value'> "+ result.brightness +"</span></div><div class='info-row'><span class='info-label' data-i18n='pair.mode'>Mode:</span><span class='info-value'> "+ result.mode +"</span></div><div class='info-row'><span class='info-label' data-i18n='pair.eyecare'>Eyecare:</span><span class='info-value'> "+ result.eyecare +"</span></div>";
$('.mi-device-info').show();
$('.mi-device-info').html(mideviceinfo);
$('.mi-device-test').show();
$('#connect').prop('disabled', false);
} else {
$('.mi-device-error').show();
$('.mi-device-error-msg').html( __('pair.unknownerror') );
}
});

} else {
$('.mi-device-error').show();
$('.mi-device-error-msg').html( __('pair.nosettings') );
}

});

$('#connect').click(function(){
var inputaddress = $('#address').val();
var inputtoken = $('#token').val();
var inputpolling = Number($('#polling').val()) || 10;
var inputmode = $('#mode').val() || 'reading';

if( inputaddress != '' && inputtoken != '' && inputpolling != '') {
var device_data = {
id: inputtoken
};
var settings = {
address: inputaddress,
token: inputtoken,
polling: inputpolling
};
var store = {
mode: inputmode,
eyecare: false
};

Homey.addDevice({
name : 'Philips Eyecare Lamp',
data : device_data,
settings : settings,
store : store
}, function(error, result) {
if (error) {
$('.mi-device-test').hide();
$('.mi-device-error').show();
$('.mi-device-error-msg').html(error.message || error.toString());
}
$('.mi-device-test').hide();
$('.mi-device-ok').show();

Homey.done();
})

} else {
$('.mi-device-test').hide();
$('.mi-device-error').show();
$('.mi-device-error-msg').html( __('pair.nosettings') );
}

});
})
</script>

<style type="text/css">
.mi-device-pairing {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.mi-device-pairing .col1, .mi-device-pairing .col2 {
width: 48%;
}
.mi-device-status, .mi-device-info {
display: none;
}
.mi-device-info {
font-size: 12px;
}
.mi-device-info .info-row {
min-width: 150px;
padding-bottom: 4px;
font-weight: 700;
}
.mi-device-info .info-label {
display: inline-block;
min-width: 100px;
font-weight: 700;
}
.form-group input[type="text"] {
width: 80% !important;
}
.buttons, .messages {
padding-top: 14px;
}
</style>

<p data-i18n="pair.intro">Enter the details of your Mi Home device.</p>
<div class="mi-device-pairing">
<div class="col1">
<div class="form-group">
<label for="address" data-i18n="pair.address">IP address</label>
<input type="text" class="form-control" id="address" placeholder="192.168.0.100">
</div>
<div class="form-group">
<label for="token" data-i18n="pair.token">Token (32 characters of numbers and letters)</label>
<input type="text" class="form-control" id="token" pattern="[a-zA-Z0-9]{32}" placeholder="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF">
</div>
<div class="form-group">
<label for="polling" data-i18n="pair.polling">Polling Frequency</label>
<input type="number" class="form-control" id="polling" min="5" max="3600" placeholder="10">
</div>
<input type="hidden" id="mode" value="">
<div class="form-group buttons">
<button id="test-connection" class="button" data-i18n="pair.test">Test Connection</button>
<button id="connect" class="button" data-i18n="pair.connect" disabled>Connect</button>
</div>
</div>
<div class="col2">
<div class="mi-device-info"></div>
</div>
</div>

<div class="messages">
<p class="mi-device-status mi-device-test" style="color: #008C23;"><i class="fa fa-check"></i> <span data-i18n="pair.testing">Connection test successfull, you can now connect the device.</span></p>
<p class="mi-device-status mi-device-ok" style="color: #008C23;"><i class="fa fa-check"></i> <span data-i18n="pair.success">Mi Home device added succesfully.</span></p>
<p class="mi-device-status mi-device-error" style="color: #ff6300;"><i class="fa fa-times"></i> <span class="mi-device-error-msg"></span></p>
</div>
49 changes: 37 additions & 12 deletions node_modules/miio/lib/devices/eyecare-lamp2.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.xiaomi-miio",
"version": "2.11.11",
"version": "2.12.0",
"description": "Xiaomi Mi Home",
"main": "app.js",
"dependencies": {

0 comments on commit 3472ddb

Please sign in to comment.