@@ -45,34 +45,34 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
4545
4646 // show configuration
4747 let twoSensorMode = ( ( this . address_sensor_close !== undefined ) && ( this . address_sensor_open !== undefined ) )
48- this . log . info ( 'Garage Door Config: %s sensor mode' , twoSensorMode ? 'two' : 'one' )
48+ this . log . info ( '[GDS] Garage Door Config: %s sensor mode' , twoSensorMode ? 'two' : 'one' )
4949 if ( twoSensorMode ) {
50- this . log . info ( 'Sensor open is %s' , this . address_sensor_open )
51- this . log . info ( 'Sensor open value is %s' , this . state_sensor_open )
50+ this . log . info ( '[GDS] Sensor open is %s' , this . address_sensor_open )
51+ this . log . info ( '[GDS] Sensor open value is %s' , this . state_sensor_open )
5252 }
53- this . log . info ( 'Sensor close is %s' , this . address_sensor_close )
54- this . log . info ( 'Sensor close value is %s' , this . state_sensor_close )
53+ this . log . info ( '[GDS] Sensor close is %s' , this . address_sensor_close )
54+ this . log . info ( '[GDS] Sensor close value is %s' , this . state_sensor_close )
5555
5656 this . targetCommand = false
5757
5858 // validate stuff
5959 if ( this . isDatapointAddressValid ( this . address_sensor_close , false ) === false ) {
60- this . log . error ( 'cannot initialize garage device adress for close sensor is invalid' )
60+ this . log . error ( '[GDS] cannot initialize garage device adress for close sensor is invalid' )
6161 return
6262 }
6363
6464 if ( this . isDatapointAddressValid ( this . address_sensor_open , true ) === false ) {
65- this . log . error ( 'cannot initialize garage device adress for open sensor is invalid' )
65+ this . log . error ( '[GDS] cannot initialize garage device adress for open sensor is invalid' )
6666 return
6767 }
6868
6969 if ( this . isDatapointAddressValid ( this . address_actor_open , false ) === false ) {
70- this . log . error ( 'cannot initialize garage device adress for open actor is invalid' )
70+ this . log . error ( '[GDS] cannot initialize garage device adress for open actor is invalid' )
7171 return
7272 }
7373
7474 if ( this . isDatapointAddressValid ( this . address_actor_close , true ) === false ) {
75- this . log . error ( 'cannot initialize garage device adress for close actor is invalid' )
75+ this . log . error ( '[GDS] cannot initialize garage device adress for close actor is invalid' )
7676 return
7777 }
7878
@@ -91,15 +91,15 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
9191
9292 if ( ( that . address_sensor_close !== undefined ) && ( that . address_sensor_open !== undefined ) ) {
9393 // We have two contacts so ask for boath levels
94- that . log . debug ( 'Two sensor mode. Fetching value for Close Sensor %s' , that . address_sensor_close )
94+ that . log . debug ( '[GDS] Two sensor mode. Fetching value for Close Sensor %s' , that . address_sensor_close )
9595 that . remoteGetDataPointValue ( that . address_sensor_close , function ( closeValue ) {
96- that . log . debug ( 'get close value result is %s' , closeValue )
97- that . log . debug ( 'Fetching value for Open Sensor %s' , that . address_sensor_close )
96+ that . log . debug ( '[GDS] get close value result is %s' , closeValue )
97+ that . log . debug ( '[GDS] Fetching value for Open Sensor %s' , that . address_sensor_close )
9898 that . remoteGetDataPointValue ( that . address_sensor_open , function ( openValue ) {
99- that . log . debug ( 'get open value result is %s' , openValue )
99+ that . log . debug ( '[GDS] get open value result is %s' , openValue )
100100
101101 if ( ( that . didMatch ( closeValue , that . state_sensor_close ) ) && ( ! that . didMatch ( openValue , that . state_sensor_open ) ) ) {
102- that . log . debug ( 'values shows CurrentDoorState is closed' )
102+ that . log . debug ( '[GDS] values shows CurrentDoorState is closed' )
103103 returnValue = Characteristic . CurrentDoorState . CLOSED
104104 if ( that . targetCommand ) {
105105 that . targetDoorState . updateValue ( that . characteristic . TargetDoorState . CLOSED , null )
@@ -124,16 +124,19 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
124124
125125 if ( ( that . address_sensor_close !== undefined ) && ( that . address_sensor_open === undefined ) ) {
126126 // There is only one contact
127- that . log . debug ( 'One sensor mode. Fetching value for Close Sensor %s' , that . address_sensor_close )
127+ that . log . debug ( '[GDS] One sensor mode. Fetching value for Close Sensor %s' , that . address_sensor_close )
128+
128129 that . remoteGetDataPointValue ( that . address_sensor_close , function ( closeValue ) {
129- that . log . debug ( 'get close value result is %s' , closeValue )
130+ that . log . debug ( '[GDS] get close value result is %s' , closeValue )
130131 if ( that . didMatch ( closeValue , that . state_sensor_close ) ) {
131- that . log . debug ( 'values match close state' )
132+ that . log . debug ( '[GDS] values match close state' )
132133 returnValue = Characteristic . CurrentDoorState . CLOSED
133134 } else {
134- that . log . debug ( 'values %s vs %s did not match close state set door to open' , closeValue , that . state_sensor_close )
135+ that . log . debug ( '[GDS] values %s vs %s did not match close state set door to open' , closeValue , that . state_sensor_close )
135136 returnValue = Characteristic . CurrentDoorState . OPEN
136137 }
138+ let parts = that . address_sensor_close . split ( '.' )
139+ that . event ( parts [ 0 ] + '.' + parts [ 1 ] , parts [ 2 ] , parseInt ( closeValue ) )
137140 if ( callback ) callback ( null , returnValue )
138141 } )
139142 }
@@ -159,7 +162,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
159162 that . requeryTimer = setTimeout ( function ( ) {
160163 // reset Command Switch to override target
161164 that . targetCommand = false
162- that . log . debug ( 'garage door requery sensors ...' )
165+ that . log . debug ( '[GDS] garage door requery sensors ...' )
163166 that . querySensors ( )
164167 } , 1000 * that . sensor_requery_time )
165168 } else {
@@ -171,7 +174,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
171174 // reset Command Switch to override target
172175 that . targetCommand = false
173176 that . requeryTimer = setTimeout ( function ( ) {
174- that . log . debug ( 'garage door requery sensors ...' )
177+ that . log . debug ( '[GDS] garage door requery sensors ...' )
175178 that . querySensors ( )
176179 } , 1000 * that . sensor_requery_time )
177180 } else {
@@ -182,7 +185,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
182185 // reset Command Switch to override target
183186 that . targetCommand = false
184187 that . requeryTimer = setTimeout ( function ( ) {
185- that . log . debug ( 'garage door requery sensors ...' )
188+ that . log . debug ( '[GDS] garage door requery sensors ...' )
186189 that . querySensors ( )
187190 } , 1000 * that . sensor_requery_time )
188191 }
@@ -197,7 +200,7 @@ HomeMaticHomeKitGarageDoorService.prototype.createDeviceService = function (Serv
197200 // this is dirty shit .. ¯\_(ツ)_/¯ it works so we do not change that ...
198201 // query sensors at launch delayed by 60 seconds
199202 this . inittimer = setTimeout ( function ( ) {
200- that . log . debug ( 'garage door inital query ...' )
203+ that . log . debug ( '[GDS] garage door inital query ...' )
201204 that . querySensors ( )
202205 } , 30000 )
203206}
@@ -220,43 +223,43 @@ HomeMaticHomeKitGarageDoorService.prototype.querySensors = function () {
220223
221224 if ( this . address_sensor_close !== undefined ) {
222225 that . remoteGetDataPointValue ( that . address_sensor_close , function ( newValue ) {
223- that . log . debug ( 'result for close sensor %s' , newValue )
226+ that . log . debug ( '[GDS] result for close sensor %s' , newValue )
224227 let parts = that . address_sensor_close . split ( '.' )
225- that . event ( parts [ 0 ] + '.' + parts [ 1 ] , parts [ 2 ] , newValue )
228+ that . event ( parts [ 0 ] + '.' + parts [ 1 ] , parts [ 2 ] , parseInt ( newValue ) )
226229 } )
227230 }
228231
229232 if ( this . address_sensor_open !== undefined ) {
230233 this . remoteGetDataPointValue ( that . address_sensor_open , function ( newValue ) {
231- that . log . debug ( 'result for open sensor %s' , newValue )
234+ that . log . debug ( '[GDS] result for open sensor %s' , newValue )
232235 let parts = that . address_sensor_close . split ( '.' )
233- that . event ( parts [ 0 ] + '.' + parts [ 1 ] , parts [ 2 ] , newValue )
236+ that . event ( parts [ 0 ] + '.' + parts [ 1 ] , parts [ 2 ] , parseInt ( newValue ) )
234237 } )
235238 }
236239}
237240
238241HomeMaticHomeKitGarageDoorService . prototype . event = function ( channel , dp , newValue ) {
239242 // Chech sensors
240243 let that = this
241- this . log . debug ( 'garage event %s,%s,%s Target Command State %s' , channel , dp , newValue , this . targetCommand )
244+ this . log . debug ( '[GDS] garage event %s,%s,%s Target Command State %s' , channel , dp , newValue , this . targetCommand )
242245 let eventAddress = channel + '.' + dp
243246 // Kill requery timer
244247 clearTimeout ( this . requeryTimer )
245248 clearTimeout ( this . inittimer )
246249
247250 if ( ( this . address_sensor_close !== undefined ) && ( this . address_sensor_open !== undefined ) ) {
248251 // we have two sensors
249- this . log . debug ( 'Two Sensor Mode' )
252+ this . log . debug ( '[GDS] Two Sensor Mode' )
250253 if ( ( eventAddress === this . address_sensor_close ) && ( this . didMatch ( newValue , this . state_sensor_close ) ) ) {
251254 // Sensor Close said its closed
252- this . log . debug ( 'close sensor is %s set CurrentDoorState to close' , newValue )
255+ this . log . debug ( '[GDS] close sensor is %s set CurrentDoorState to close' , newValue )
253256 this . currentDoorState . updateValue ( this . characteristic . CurrentDoorState . CLOSED , null )
254257 this . targetCommand = false
255258 }
256259
257260 if ( ( eventAddress === this . address_sensor_close ) && ( ! ( this . didMatch ( newValue , this . state_sensor_close ) ) ) ) {
258261 // Sensor Close just opened so the door is moving to open position
259- this . log . debug ( 'close sensor is %s set TargetDoorState to open CurrentDoorState to opening' , newValue )
262+ this . log . debug ( '[GDS] close sensor is %s set TargetDoorState to open CurrentDoorState to opening' , newValue )
260263 if ( this . targetCommand ) {
261264 this . targetDoorState . updateValue ( this . characteristic . TargetDoorState . OPEN )
262265 }
@@ -265,47 +268,47 @@ HomeMaticHomeKitGarageDoorService.prototype.event = function (channel, dp, newVa
265268
266269 if ( ( eventAddress === this . address_sensor_open ) && ( this . didMatch ( newValue , this . state_sensor_open ) ) ) {
267270 // Sensor Open said its open
268- this . log . debug ( 'open sensor is %s set CurrentDoorState to open' , newValue )
271+ this . log . debug ( '[GDS] open sensor is %s set CurrentDoorState to open' , newValue )
269272 this . currentDoorState . updateValue ( this . characteristic . CurrentDoorState . OPEN , null )
270273 this . targetCommand = false
271274 }
272275
273276 if ( ( eventAddress === this . address_sensor_open ) && ( ! ( this . didMatch ( newValue , this . state_sensor_open ) ) ) ) {
274277 // Sensor open just went to false so the door is moving to close position
275- this . log . debug ( 'open sensor is %s set TargetDoorState to close CurrentDoorState to closing' , newValue )
278+ this . log . debug ( '[GDS] open sensor is %s set TargetDoorState to close CurrentDoorState to closing' , newValue )
276279 if ( this . targetCommand ) {
277280 this . targetDoorState . updateValue ( this . characteristic . TargetDoorState . CLOSED )
278281 }
279282 this . currentDoorState . updateValue ( this . characteristic . CurrentDoorState . CLOSING , null )
280283 }
281284 } else {
282- this . log . debug ( 'One Sensor Mode Close is %s' , that . state_sensor_close )
285+ this . log . debug ( '[GDS] One Sensor Mode Close is %s' , that . state_sensor_close )
283286 // we only have one sensor if its the close sensor the door is closed on sensor true
284287 if ( eventAddress === this . address_sensor_close ) {
285288 // first set a new target state but ony if the target was not set by homekit first
286289 if ( this . targetCommand === false ) {
287290 let newState = ( this . didMatch ( newValue , that . state_sensor_close ) ) ? this . characteristic . TargetDoorState . CLOSED : this . characteristic . TargetDoorState . OPEN
288- this . log . debug ( 'Close sensor is %s set targetDoorState %s' , newValue , newState )
291+ this . log . debug ( '[GDS] Close sensor is %s set targetDoorState %s' , newValue , newState )
289292 this . targetDoorState . updateValue ( newState , null )
290293 }
291294 // wait one second cause we have a really fast going garage door
292295 setTimeout ( function ( ) {
293296 let newState = ( that . didMatch ( newValue , that . state_sensor_close ) ) ? that . characteristic . CurrentDoorState . CLOSED : that . characteristic . CurrentDoorState . OPEN
294- that . log . debug ( 'timer fired close sensor is %s set new current state %s' , newState , newState )
297+ that . log . debug ( '[GDS] timer fired close sensor is %s set new current state %s' , newState , newState )
295298 that . currentDoorState . updateValue ( newState , null )
296299 } , 1000 )
297300 }
298301
299302 if ( eventAddress === this . address_sensor_open ) {
300303 if ( this . targetCommand === false ) {
301304 let newState = ( this . didMatch ( newValue , this . state_sensor_open ) ) ? that . characteristic . TargetDoorState . OPEN : this . characteristic . TargetDoorState . CLOSED
302- this . log . debug ( 'open sensor is %s set new target state %s' , newValue , newState )
305+ this . log . debug ( '[GDS] open sensor is %s set new target state %s' , newValue , newState )
303306 this . targetDoorState . updateValue ( newState , null )
304307 }
305308
306309 setTimeout ( function ( ) {
307310 let newState = ( that . didMatch ( newValue , that . state_sensor_open ) ) ? that . characteristic . CurrentDoorState . OPEN : that . characteristic . CurrentDoorState . CLOSED
308- that . log . debug ( 'fired open sensor is %s set new state %s' , newValue , newState )
311+ that . log . debug ( '[GDS] fired open sensor is %s set new state %s' , newValue , newState )
309312 that . currentDoorState . updateValue ( newState , null )
310313 } , 1000 )
311314 }
0 commit comments