From 71760b93bbdee160c7798680d3e295985d84273f Mon Sep 17 00:00:00 2001 From: sreinhold95 Date: Mon, 6 Jun 2022 15:30:54 +0200 Subject: [PATCH 1/2] fix HMIPW-DRD3 Multi accessory --- homematic-devices/hmipw-drd3.js | 150 +++++++++++++----- nodes/redmatic-homekit-homematic-devices.html | 4 +- 2 files changed, 115 insertions(+), 39 deletions(-) diff --git a/homematic-devices/hmipw-drd3.js b/homematic-devices/hmipw-drd3.js index 18d5b08..35865f3 100644 --- a/homematic-devices/hmipw-drd3.js +++ b/homematic-devices/hmipw-drd3.js @@ -1,52 +1,128 @@ +/* eslint-disable no-new */ + const Accessory = require('./lib/accessory'); -module.exports = class HmipwDrd extends Accessory { - init(config, node) { - const {ccu} = node; +function addService(type, name, channel) { + let service + this.node.debug("HMIPW-DRD3: "+ name +" "+channel); + switch (type) { + case 'ValveIrrigation': + // intentional fallthrough + case 'Valve': + // intentional fallthrough + case 'Lightbulb': + service=this.addService(type,name); + service.get('On', channel + '.LEVEL', value => { + this.node.debug("HMIPW-DRD3 get : "+channel); + valueBrightness = value; + return value > 0; + }) - let valueBrightness = 0; + service.set('On', (value, callback) => { + this.node.debug("HMIPW-DRD3 set : "+channel); + 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); + } + }) + + service.get('Brightness', channel + '.LEVEL', value => { + valueBrightness = value * 100; + return value * 100; + }) + + service.set('Brightness', channel + '.LEVEL', value => { + valueBrightness = value; + return value / 100; + }); + case 'Fan': + // intentional fallthrough + case 'Outlet': + // intentional fallthrough + default: + /*this.addService(type, name, type === 'Switch' ? '' : type) + .get('On', dp) + .set('On', dp);*/ + } +} + +class AccSingleService extends Accessory { + init(config, node) { + const {ccu} = node; + node.debug(config.accChannel + ' ' + "Lightbulb" + ' '); + addService.call(this, "Lightbulb", config.accChannelName, config.accChannel); + } +} + +class AccMultiService extends Accessory { + init(config, node) { + const {ccu} = node; + for (let j = 0; j < 3; j++) { for (let c = 0; c < 3; c++) { const i = (j * 4) + (c + 2); if ((c === 0 && this.option(i)) || (c !== 0 && this.option(i, 'enabled'))) { const channel = config.deviceAddress + ':' + i; const name = ccu.channelNames[channel]; + this.node.debug("HMIPW-DRD3 call MultiService Channel: "+name+" "+channel); + addService.call(this,"Lightbulb",name,channel) + } + } + } + } +} + +module.exports = class HmipwDrd { + option(id, option) { + let addr = this.config.description.ADDRESS; + if (!addr.includes(':')) { + addr = addr + ':' + id; + } + + let res; + + if (option) { + res = this.config.options[addr] && this.config.options[addr][option]; + } else { + res = !(this.config.options[addr] && this.config.options[addr].disabled); + } + + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); + return res; + } + + constructor(config, node) { + const {ccu} = node; + this.node = node; + this.ccu = ccu; + this.config = config; + if (this.option('SingleAccessory')) { + new AccMultiService(config, node); + } else { + for (let j = 0; j < 3; j++) { + for (let c = 0; c < 3; c++) { + const i = (j * 4) + (c + 2); + if ((c === 0 && this.option(i)) || (c !== 0 && this.option(i, 'enabled'))) { + const channel = config.deviceAddress + ':' + i; + const name = ccu.channelNames[channel]; + this.node.debug("HMIPW-DRD3 call SingleService Channel: "+name+" "+channel); + + const chConfig = Object.assign({}, config, {accChannel: channel,accChannelName: name}); + chConfig.description = Object.assign({}, config.description, {ADDRESS: 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; - }); + new AccSingleService(chConfig, node); + } } } } } -}; +}; \ No newline at end of file diff --git a/nodes/redmatic-homekit-homematic-devices.html b/nodes/redmatic-homekit-homematic-devices.html index 369ba46..91b1794 100644 --- a/nodes/redmatic-homekit-homematic-devices.html +++ b/nodes/redmatic-homekit-homematic-devices.html @@ -597,10 +597,10 @@ break; case 'hmipw-drd3': - addVirtualChannels(addr, 2, 12, 4); + addOption(addr, 'SingleAccessory'); + addVirtualChannels(addr, 2, channelCount -1, 4); break; - case 'hmipw-drs4': case 'hmipw-drs8': addOption(addr, 'SingleAccessory'); From b7710be4a73ec934c97af96e5e14827f53fba4c7 Mon Sep 17 00:00:00 2001 From: sreinhold95 Date: Sun, 12 Jun 2022 11:59:24 +0200 Subject: [PATCH 2/2] add hmip-drdi3 from hmipw-drd3 --- homematic-devices/hmip-drdi3.js | 128 ++++++++++++++++++ nodes/redmatic-homekit-homematic-devices.html | 4 + 2 files changed, 132 insertions(+) create mode 100644 homematic-devices/hmip-drdi3.js diff --git a/homematic-devices/hmip-drdi3.js b/homematic-devices/hmip-drdi3.js new file mode 100644 index 0000000..89c3704 --- /dev/null +++ b/homematic-devices/hmip-drdi3.js @@ -0,0 +1,128 @@ +/* eslint-disable no-new */ + +const Accessory = require('./lib/accessory'); + +function addService(type, name, channel) { + let service + this.node.debug("HMIP-DRDI3: "+ name +" "+channel); + switch (type) { + case 'ValveIrrigation': + // intentional fallthrough + case 'Valve': + // intentional fallthrough + case 'Lightbulb': + service=this.addService(type,name); + service.get('On', channel + '.LEVEL', value => { + this.node.debug("HMIPW-DRD3 get : "+channel); + valueBrightness = value; + return value > 0; + }) + + service.set('On', (value, callback) => { + this.node.debug("HMIPW-DRD3 set : "+channel); + 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); + } + }) + + service.get('Brightness', channel + '.LEVEL', value => { + valueBrightness = value * 100; + return value * 100; + }) + + service.set('Brightness', channel + '.LEVEL', value => { + valueBrightness = value; + return value / 100; + }); + case 'Fan': + // intentional fallthrough + case 'Outlet': + // intentional fallthrough + default: + /*this.addService(type, name, type === 'Switch' ? '' : type) + .get('On', dp) + .set('On', dp);*/ + } +} + +class AccSingleService extends Accessory { + init(config, node) { + const {ccu} = node; + node.debug(config.accChannel + ' ' + "Lightbulb" + ' '); + addService.call(this, "Lightbulb", config.accChannelName, config.accChannel); + } +} + +class AccMultiService extends Accessory { + init(config, node) { + const {ccu} = node; + + for (let j = 0; j < 3; j++) { + for (let c = 0; c < 3; c++) { + const i = (j * 4) + (c + 2); + if ((c === 0 && this.option(i)) || (c !== 0 && this.option(i, 'enabled'))) { + const channel = config.deviceAddress + ':' + i; + const name = ccu.channelNames[channel]; + this.node.debug("HMIP-DRDI3 call MultiService Channel: "+name+" "+channel); + addService.call(this,"Lightbulb",name,channel) + } + } + } + } +} + +module.exports = class HmipwDrd { + option(id, option) { + let addr = this.config.description.ADDRESS; + if (!addr.includes(':')) { + addr = addr + ':' + id; + } + + let res; + + if (option) { + res = this.config.options[addr] && this.config.options[addr][option]; + } else { + res = !(this.config.options[addr] && this.config.options[addr].disabled); + } + + this.node.debug('option ' + addr + ' ' + id + ' ' + option + ' ' + res); + return res; + } + + constructor(config, node) { + const {ccu} = node; + this.node = node; + this.ccu = ccu; + this.config = config; + if (this.option('SingleAccessory')) { + new AccMultiService(config, node); + } else { + for (let j = 0; j < 3; j++) { + for (let c = 0; c < 3; c++) { + const i = (j * 4) + (c + 2); + if ((c === 0 && this.option(i)) || (c !== 0 && this.option(i, 'enabled'))) { + const channel = config.deviceAddress + ':' + i; + const name = ccu.channelNames[channel]; + this.node.debug("HMIP-DRDI3 call SingleService Channel: "+name+" "+channel); + + const chConfig = Object.assign({}, config, {accChannel: channel,accChannelName: name}); + chConfig.description = Object.assign({}, config.description, {ADDRESS: channel}); + + new AccSingleService(chConfig, node); + } + } + } + } + } +}; \ No newline at end of file diff --git a/nodes/redmatic-homekit-homematic-devices.html b/nodes/redmatic-homekit-homematic-devices.html index 91b1794..970041a 100644 --- a/nodes/redmatic-homekit-homematic-devices.html +++ b/nodes/redmatic-homekit-homematic-devices.html @@ -600,6 +600,10 @@ addOption(addr, 'SingleAccessory'); addVirtualChannels(addr, 2, channelCount -1, 4); break; + case 'hmip-drdi3': + addOption(addr, 'SingleAccessory'); + addVirtualChannels(addr, 2, channelCount -1, 4); + break; case 'hmipw-drs4': case 'hmipw-drs8':