Skip to content

Commit

Permalink
manipulate immediatePosition on set (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Feb 18, 2019
1 parent ede45d6 commit 5624e4d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
8 changes: 7 additions & 1 deletion homematic-devices/hm-lc-bl1-fm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = class HmLcBl1 extends Accessory {
stable: false
}, msg => {
intermediatePosition = msg.value * 100;
node.debug(config.name + ' intermediatePosition ' + intermediatePosition);
});

const service = this.addService('WindowCovering', config.name);
Expand All @@ -30,8 +29,15 @@ module.exports = class HmLcBl1 extends Accessory {
}
return targetPosition * 100;
})

.set('TargetPosition', config.deviceAddress + ':1.LEVEL', value => {
targetPosition = value / 100;
if (value === 0 && intermediatePosition === 0) {
intermediatePosition = 1;
} else if (value === 100 && intermediatePosition === 100) {
intermediatePosition = 99;
}
node.debug(config.name + ' intermediatePosition ' + intermediatePosition);
service.update('CurrentPosition', intermediatePosition);
return targetPosition;
})
Expand Down
44 changes: 37 additions & 7 deletions homematic-devices/hmip-bbl.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
const Accessory = require('./lib/accessory');

module.exports = class HmipBbl extends Accessory {
init(config) {
this.addService('WindowCovering', config.name)
.get('CurrentPosition', config.deviceAddress + ':4.LEVEL', value => {
return value * 100;
})
init(config, node) {
const {ccu} = node;

let intermediatePosition;
let targetPosition;

ccu.subscribe({
datapointName: config.deviceAddress + ':4.LEVEL',
cache: true,
stable: false
}, msg => {
intermediatePosition = msg.value * 100;
});

const service = this.addService('WindowCovering', config.name);

service.get('CurrentPosition', config.deviceAddress + ':4.LEVEL', value => {
targetPosition = value;
intermediatePosition = value * 100;
return value * 100;
})

.get('TargetPosition', config.deviceAddress + ':4.LEVEL', value => {
return value * 100;
if (typeof targetPosition === 'undefined') {
targetPosition = value;
}
return targetPosition * 100;
})

.set('TargetPosition', config.deviceAddress + ':4.LEVEL', value => {
return value / 100;
targetPosition = value / 100;
targetPosition = value / 100;
if (value === 0 && intermediatePosition === 0) {
intermediatePosition = 1;
} else if (value === 100 && intermediatePosition === 100) {
intermediatePosition = 99;
}
node.debug(config.name + ' intermediatePosition ' + intermediatePosition);
service.update('CurrentPosition', intermediatePosition);
return targetPosition;
})

.get('PositionState', config.deviceAddress + ':4.ACTIVITY_STATE', (value, c) => {
Expand All @@ -32,6 +61,7 @@ module.exports = class HmipBbl extends Accessory {
.get('TargetVerticalTiltAngle', config.deviceAddress + ':4.LEVEL_2', value => {
return (value * 180) - 90;
})

.set('TargetVerticalTiltAngle', config.deviceAddress + ':4.LEVEL_2', value => {
return (value + 90) / 180;
});
Expand Down
9 changes: 8 additions & 1 deletion homematic-devices/hmip-broll.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = class HmipBroll extends Accessory {
stable: false
}, msg => {
intermediatePosition = msg.value * 100;
node.debug(config.name + ' intermediatePosition ' + intermediatePosition);
});

const service = this.addService('WindowCovering', config.name);
Expand All @@ -30,8 +29,16 @@ module.exports = class HmipBroll extends Accessory {
}
return targetPosition * 100;
})

.set('TargetPosition', config.deviceAddress + ':4.LEVEL', value => {
targetPosition = value / 100;
targetPosition = value / 100;
if (value === 0 && intermediatePosition === 0) {
intermediatePosition = 1;
} else if (value === 100 && intermediatePosition === 100) {
intermediatePosition = 99;
}
node.debug(config.name + ' intermediatePosition ' + intermediatePosition);
service.update('CurrentPosition', intermediatePosition);
return targetPosition;
})
Expand Down

0 comments on commit 5624e4d

Please sign in to comment.