Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit c7180d4

Browse files
committed
still working on #206
1 parent 45eb7aa commit c7180d4

1 file changed

Lines changed: 48 additions & 12 deletions

File tree

ChannelServices/HomeMaticHomeKitGarageDoorService.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function(Servi
3636
this.delay_actor_open = this.getClazzConfigValue('delay_actor_open',5)
3737
this.delay_actor_close = this.getClazzConfigValue('delay_actor_close',5)
3838

39+
this.targetCommand = false
3940

4041
if ((this.adress_close == undefined) && (this.adress_open == undefined)) {
4142
this.log.error('Cannot initialize Garage Device adress for open or close detection is missing')
@@ -49,6 +50,13 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function(Servi
4950
var garagedoorService = new Service.GarageDoorOpener(this.name);
5051
this.services.push(garagedoorService);
5152

53+
54+
this.obstacle = garagedoorService.getCharacteristic(Characteristic.ObstructionDetected)
55+
.on('get', function(callback) {
56+
if (callback) callback(null,false);
57+
}.bind(this));
58+
59+
5260
this.currentDoorState = garagedoorService.getCharacteristic(Characteristic.CurrentDoorState)
5361

5462
.on('get', function(callback) {
@@ -60,7 +68,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function(Servi
6068
that.remoteGetDeviceValue(that.adress_open,'STATE',function(open_value){
6169
if ((close_value == that.state_close) && (open_value != that.state_open)) {
6270
return_value = Characteristic.CurrentDoorState.CLOSED
63-
that.targetDoorState.updateValue(that.characteristic.TargetDoorState.CLOSED,null)
71+
if (that.targetCommand) {that.targetDoorState.updateValue(that.characteristic.TargetDoorState.CLOSED,null)}
6472
}
6573

6674
if ((close_value != that.state_close) && (open_value != that.state_open)) {
@@ -69,7 +77,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function(Servi
6977

7078
if ((close_value != that.state_close) && (open_value == that.state_open)) {
7179
return_value = Characteristic.CurrentDoorState.OPEN
72-
that.targetDoorState.updateValue(that.characteristic.TargetDoorState.OPEN,null)
80+
if (that.targetCommand) {that.targetDoorState.updateValue(that.characteristic.TargetDoorState.OPEN,null)}
7381
}
7482

7583
if (callback) callback(null,return_value);
@@ -94,22 +102,32 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function(Servi
94102

95103
this.targetDoorState = garagedoorService.getCharacteristic(Characteristic.TargetDoorState)
96104
.on('set', function(value,callback) {
97-
105+
that.targetCommand = true
98106
if ((that.adress_actor_open != undefined) && (that.adress_actor_close == undefined)) {
99107
// there is only one actor
108+
if (value == Characteristic.TargetDoorState.OPEN) {
109+
that.currentDoorState.updateValue(that.characteristic.CurrentDoorState.OPENING,null)
110+
} else {
111+
that.currentDoorState.updateValue(that.characteristic.CurrentDoorState.CLOSING,null)
112+
}
113+
114+
100115
that.remoteSetDeviceValue(that.adress_actor_open,'STATE',true)
101116
setTimeout(function() {
102117
that.remoteSetDeviceValue(that.adress_actor_open,'STATE',false)
103118
},1000*that.delay_actor_open)
119+
104120
} else {
105121
// there is a actor for every direction so
106122
if (value == Characteristic.TargetDoorState.OPEN) {
123+
that.currentDoorState.updateValue(that.characteristic.CurrentDoorState.OPENING,null)
107124
that.remoteSetDeviceValue(that.adress_actor_open,'STATE',true)
108125
setTimeout(function() {
109126
that.remoteSetDeviceValue(that.adress_actor_open,'STATE',false)
110127
},1000*that.delay_actor_open)
111128
} else {
112129
that.remoteSetDeviceValue(that.adress_actor_close,'STATE',true)
130+
that.currentDoorState.updateValue(that.characteristic.CurrentDoorState.CLOSING,null)
113131
setTimeout(function() {
114132
that.remoteSetDeviceValue(that.adress_actor_close,'STATE',false)
115133
},1000*that.delay_actor_close)
@@ -142,44 +160,62 @@ HomeMaticHomeKitGarageDoorService.prototype.event = function(channel,dp,newValue
142160
// we have two sensors
143161
if ((channel == this.adress_close) && (newValue == this.state_close)) {
144162
// Sensor Close said its closed
145-
that.currentDoorState.updateValue(that.characteristic.CurrentDoorState.CLOSED,null)
163+
this.currentDoorState.updateValue(this.characteristic.CurrentDoorState.CLOSED,null)
164+
this.targetCommand = false
146165
}
147166

148167
if ((channel == this.adress_close) && (newValue != this.state_close)) {
149168
// Sensor Close just opened so the door is moving to open position
150-
this.targetDoorState.updateValue(this.characteristic.TargetDoorState.OPEN)
169+
if (this.targetCommand) {this.targetDoorState.updateValue(this.characteristic.TargetDoorState.OPEN)}
151170
this.currentDoorState.updateValue(this.characteristic.CurrentDoorState.OPENING,null)
152171
}
153172

154173
if ((channel == this.adress_open) && (newValue == this.state_open)) {
155174
// Sensor Open said its open
156175
this.currentDoorState.updateValue(this.characteristic.CurrentDoorState.OPEN,null)
176+
this.targetCommand = false
157177
}
158178

159179
if ((channel == this.adress_open) && (newValue != this.state_open)) {
160180
// Sensor open just went to false so the door is moving to close position
161-
this.targetDoorState.updateValue(this.characteristic.TargetDoorState.CLOSED)
181+
if (this.targetCommand) {this.targetDoorState.updateValue(this.characteristic.TargetDoorState.CLOSED)}
162182
this.currentDoorState.updateValue(this.characteristic.CurrentDoorState.CLOSING,null)
163183
}
164184

185+
165186
} else {
166187
// we only have one sensor if its the close sensor the door is closed on sensor true
167188
if (channel == this.adress_close) {
168-
// first set a new target state
169-
that.targetDoorState.updateValue((newValue==that.state_close)?that.characteristic.TargetDoorState.CLOSED:that.characteristic.TargetDoorState.OPEN,null)
189+
// first set a new target state but ony if the target was not set by homekit first
190+
if (this.targetCommand == false) {
191+
let newState = (newValue==that.state_close) ? this.characteristic.TargetDoorState.CLOSED:this.characteristic.TargetDoorState.OPEN
192+
this.log.debug('Close sensor set new target state %s',newState)
193+
this.targetDoorState.updateValue(newState,null)
194+
}
170195
// wait one second cause we have a really fast going garage door
171196
setTimeout(function() {
172-
that.currentDoorState.updateValue((newValue==that.state_close)?that.characteristic.CurrentDoorState.CLOSED:that.characteristic.CurrentDoorState.OPEN,null)
197+
let newState = (newValue==that.state_close)?that.characteristic.CurrentDoorState.CLOSED:that.characteristic.CurrentDoorState.OPEN
198+
that.log.debug('Close sensor set new current state %s',newState)
199+
that.currentDoorState.updateValue(newState,null)
173200
},1000)
174201
}
175202

176203
if (channel == this.adress_open) {
177-
that.targetDoorState.updateValue((newValue==that.state_open)?that.characteristic.TargetDoorState.OPEN:that.characteristic.TargetDoorState.CLOSED,null)
204+
205+
if (this.targetCommand == false) {
206+
let newState = (newValue==this.state_open)?that.characteristic.TargetDoorState.OPEN:this.characteristic.TargetDoorState.CLOSED
207+
this.log.debug('open sensor set new target state %s',newState)
208+
this.targetDoorState.updateValue(newState,null)
209+
}
210+
178211
setTimeout(function() {
179-
that.currentDoorState.updateValue((newValue==that.state_open)?that.characteristic.CurrentDoorState.OPEN:that.characteristic.CurrentDoorState.CLOSED,null)
212+
let newState = (newValue==that.state_open)?that.characteristic.CurrentDoorState.OPEN:that.characteristic.CurrentDoorState.CLOSED
213+
that.log.debug('open sensor set new state %s',newState)
214+
that.currentDoorState.updateValue(newState,null)
180215
},1000)
181216
}
182-
217+
218+
this.targetCommand = false
183219
}
184220
}
185221

0 commit comments

Comments
 (0)