Skip to content

Commit

Permalink
improve blind direction state behavior (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Feb 17, 2019
1 parent 58ac4eb commit ede45d6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
36 changes: 29 additions & 7 deletions homematic-devices/hm-lc-bl1-fm.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
const Accessory = require('./lib/accessory');

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

let intermediatePosition;
let targetPosition;

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

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

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

.get('TargetPosition', config.deviceAddress + ':1.LEVEL', value => {
return value * 100;
if (typeof targetPosition === 'undefined') {
targetPosition = value;
}
return targetPosition * 100;
})
.set('TargetPosition', config.deviceAddress + ':1.LEVEL', value => {
return value / 100;
targetPosition = value / 100;
service.update('CurrentPosition', intermediatePosition);
return targetPosition;
})

.get('PositionState', config.deviceAddress + ':1.DIRECTION', (value, c) => {
Expand Down
36 changes: 29 additions & 7 deletions homematic-devices/hmip-broll.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
const Accessory = require('./lib/accessory');

module.exports = class HmipBroll 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;
node.debug(config.name + ' intermediatePosition ' + intermediatePosition);
});

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;
service.update('CurrentPosition', intermediatePosition);
return targetPosition;
})

.get('PositionState', config.deviceAddress + ':4.ACTIVITY_STATE', (value, c) => {
Expand Down
8 changes: 5 additions & 3 deletions homematic-devices/lib/accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ module.exports = class Accessory {
}

ccuSetValue(address, value, callback) {
const force = this.ccu.values[address] && this.ccu.values[address].stable === false;
const [iface, channel, dp] = address.split('.');
this.ccu.setValueQueued(iface, channel, dp, value)
this.ccu.setValueQueued(iface, channel, dp, value, false, force)
.then(() => {
if (typeof callback === 'function') {
callback();
Expand Down Expand Up @@ -200,7 +201,7 @@ module.exports = class Accessory {
this.subscriptions.push(this.ccu.subscribe({
cache: true,
change: true,
stable: true,
stable: !datapointName.endsWith('.DIRECTION') && !datapointName.endsWith('.ACTIVITY_STATE'),
datapointName
}, msg => {
const valueOrig = msg.value;
Expand All @@ -219,9 +220,10 @@ module.exports = class Accessory {
if (typeof transform === 'function') {
value = transform(value, this.hap.Characteristic[characteristic]);
}
const force = this.ccu.values[datapointName] && this.ccu.values[datapointName].stable === false;
const [iface, channel, dp] = datapointName.split('.');
this.node.debug('set ' + this.config.name + ' (' + subtype + ') ' + characteristic + ' ' + valueOrig + ' -> ' + datapointName + ' ' + value);
this.ccu.setValueQueued(iface, channel, dp, value)
this.ccu.setValueQueued(iface, channel, dp, value, false, force)
.then(() => {
callback();
})
Expand Down

0 comments on commit ede45d6

Please sign in to comment.