Skip to content

Commit

Permalink
HmIP-BDT virtual channels (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Jun 15, 2019
1 parent 636f6f3 commit ce832be
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions homematic-devices/hmip-bdt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,50 @@ const Accessory = require('./lib/accessory');
module.exports = class HmipBdt extends Accessory {
init(config, node) {
const {ccu} = node;
const name = ccu.channelNames[config.deviceAddress + ':4'];

let valueBrightness = 0;

this.addService('Lightbulb', name)

.get('On', config.deviceAddress + ':4.LEVEL', value => {
valueBrightness = value;
return value > 0;
})

.set('On', (value, callback) => {
if (value) {
setTimeout(() => {
if (valueBrightness === 0) {
value = 1;
} else {
value = valueBrightness / 100;
}

this.ccuSetValue(config.deviceAddress + ':4.LEVEL', value, callback);
}, 100);
} else {
this.ccuSetValue(config.deviceAddress + ':4.LEVEL', 0, callback);
}
})

.get('Brightness', config.deviceAddress + ':4.LEVEL', value => {
valueBrightness = value * 100;
return value * 100;
})

.set('Brightness', config.deviceAddress + ':4.LEVEL', value => {
valueBrightness = value;
return value / 100;
});
for (let i = 4; i <= 6; i++) {
if ((i === 4 && this.option(i)) || (i !== 4 && this.option(i, 'enabled'))) {
const channel = config.deviceAddress + ':' + i;
const name = ccu.channelNames[channel];

this.addService('Lightbulb', name)

.get('On', channel + '.LEVEL', value => {
valueBrightness = value;
return value > 0;
})

.set('On', (value, callback) => {
if (value) {
setTimeout(() => {
if (valueBrightness === 0) {
value = 1;
} else {
value = valueBrightness / 100;
}

this.ccuSetValue(channel + '.LEVEL', value, callback);
}, 100);
} else {
this.ccuSetValue(channel + '.LEVEL', 0, callback);
}
})

.get('Brightness', channel + '.LEVEL', value => {
valueBrightness = value * 100;
return value * 100;
})

.set('Brightness', channel + '.LEVEL', value => {
valueBrightness = value;
return value / 100;
});

}
}


}
};

0 comments on commit ce832be

Please sign in to comment.