Skip to content

Commit

Permalink
Merge branch 'master' into feat/auto-toggle-night_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jghaanstra authored Jun 30, 2018
2 parents ceee661 + 614ad17 commit 9e1d275
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class XiaomiMiioApp extends Homey.App {
return Promise.resolve(customcommand);
})

new Homey.FlowCardAction('yeelightNightMode')
.register()
.registerRunListener((args, state) => {
return args.device.triggerCapabilityListener('night_mode', args.value === 'true');
})

// MI ROBOT: CONDITION AND ACTION FLOW CARDS
new Homey.FlowCardAction('findVacuum')
.register()
Expand Down
56 changes: 56 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
"dependencies": {
"net": "*"
},
"capabilities": {
"night_mode": {
"type": "boolean",
"title": {
"en": "Night Mode"
},
"getable": true,
"setable": true
}
},
"drivers": [
{
"id": "yeelights",
Expand Down Expand Up @@ -1069,6 +1079,52 @@
}
]
},
{
"id": "yeelightNightMode",
"title": {
"en": "Toggle Night Mode",
"nl": "Schakel Nacht Modus"
},
"hint": {
"en": "Use this card to switch the light between night mode and normal mode",
"nl": "Gebruik deze actie om de lamp tussen nacht modus en gewone modus te schakelen"
},
"args": [
{
"name": "value",
"type": "dropdown",
"placeholder": {
"en": "Finish action",
"nl": "Afrondactie"
},
"values": [
{
"id": "false",
"label": {
"en": "Normal Mode",
"nl": "Normale Modus"
}
},
{
"id": "true",
"label": {
"en": "Night Mode",
"nl": "Nacht Modus"
}
}
]
},
{
"name": "device",
"type": "device",
"placeholder": {
"en": "Select Yeelight",
"nl": "Selecteer Yeelight"
},
"filter": "driver_id=yeelights&capabilities=night_mode"
}
]
},
{
"id": "findVacuum",
"title": {
Expand Down
16 changes: 15 additions & 1 deletion drivers/yeelights/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class YeelightDevice extends Homey.Device {
this.registerCapabilityListener('dim', this.onCapabilityDim.bind(this));
this.registerMultipleCapabilityListener(['light_hue', 'light_saturation'], this.onCapabilityHueSaturation.bind(this), 500);
this.registerCapabilityListener('light_temperature', this.onCapabilityLightTemperature.bind(this));
this.registerCapabilityListener('night_mode', this.onCapabilityNightMode.bind(this));

let id = this.getData().id;
yeelights[id] = {};
Expand Down Expand Up @@ -79,7 +80,6 @@ class YeelightDevice extends Homey.Device {
this.dimMinTime = 0;
this.dimMaxTime = 0;
}
}

if(typeof opts.duration !== 'undefined') {
this.sendCommand(this.getData().id, '{"id":1,"method":"set_bright","params":['+ brightness +', "smooth", '+ opts.duration +']}');
Expand All @@ -93,6 +93,15 @@ class YeelightDevice extends Homey.Device {
this.setCapabilityValue('dim', overWriteDimVal);
}
}

onCapabilityNightMode(value, opts, callback) {
if (value) {
this.sendCommand(this.getData().id, '{"id": 1, "method": "set_power", "params":["on", "smooth", 500, 5]}');
} else {
this.sendCommand(this.getData().id, '{"id": 1, "method": "set_power", "params":["on", "smooth", 500, 1]}');
}
callback(null, value);
}

onCapabilityHueSaturation(valueObj, optsObj) {
if (typeof valueObj.light_hue !== 'undefined') {
Expand Down Expand Up @@ -126,6 +135,10 @@ class YeelightDevice extends Homey.Device {
}
this.sendCommand(this.getData().id, '{"id":1,"method":"set_ct_abx","params":['+ color_temp +', "smooth", 500]}');
callback(null, value);

if(this.hasCapability('night_mode')){
this.setCapabilityValue('night_mode', false);
}
}

// HELPER FUNCTIONS
Expand Down Expand Up @@ -296,6 +309,7 @@ class YeelightDevice extends Homey.Device {

/* send commands to devices using their socket connection */
sendCommand(id, command) {
console.log(command);
if (yeelights[id].connected === false && yeelights[id].socket !== null) {
yeelights[id].socket.emit('error', new Error('Connection to device broken'));
} else if (yeelights[id].socket === null) {
Expand Down
8 changes: 6 additions & 2 deletions drivers/yeelights/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const typeCapabilityMap = {
'color' : [ 'onoff', 'dim', 'light_hue', 'light_saturation', 'light_temperature', 'light_mode' ],
'stripe' : [ 'onoff', 'dim', 'light_hue', 'light_saturation', 'light_temperature', 'light_mode' ],
'bslamp' : [ 'onoff', 'dim', 'light_hue', 'light_saturation', 'light_temperature', 'light_mode' ],
'ceiling' : [ 'onoff', 'dim', 'light_temperature', 'light_mode' ],
'ceiling' : [ 'onoff', 'dim', 'light_temperature', 'light_mode', 'night_mode' ],
'ceiling4' : [ 'onoff', 'dim', 'light_hue', 'light_saturation', 'light_temperature', 'light_mode' ],
'desklamp' : [ 'onoff', 'dim', 'light_temperature', 'light_mode' ]
}
Expand Down Expand Up @@ -42,7 +42,11 @@ class YeelightDriver extends Homey.Driver {
var name = Homey.__('yeelight_led_strip')+ ' (' + result[i].address + ')';
} else if (result[i].model == 'bslamp') {
var name = Homey.__('yeelight_bedside_lamp')+ ' (' + result[i].address + ')';
} else if (result[i].model == 'ceiling' || result[i].model == 'ceiling4') {
} else if (result[i].model.startsWith('ceiling')) {
if(result[i].model !== 'ceiling4') {
// Default the ceiling light to the default ceiling light.
result[i].model = 'ceiling';
}
var name = Homey.__('yeelight_ceiling_light')+ ' (' + result[i].address + ')';
} else if (result[i].model == 'desklamp') {
var name = Homey.__('yeelight_desklamp')+ ' (' + result[i].address + ')';
Expand Down

0 comments on commit 9e1d275

Please sign in to comment.