@@ -171,13 +171,12 @@ local function get_output_timing(device, suffix)
171171 local info = OUTPUT_INFO [suffix ]
172172 if not info then return 0 , 0 end
173173 local child = device :get_child_by_parent_assigned_key (info .key )
174- if child then
175- local on_time = math.floor ((sanitize_timing (child .preferences .configOnTime )) * 10 )
176- local off_wait = math.floor ((sanitize_timing (child .preferences .configOffWaitTime )) * 10 )
177- return on_time , off_wait
178- end
179174 local on_time = math.floor ((sanitize_timing (device .preferences [" configOnTime" .. suffix ]))* 10 )
180175 local off_wait = math.floor ((sanitize_timing (device .preferences [" configOffWaitTime" .. suffix ]))* 10 )
176+ if child then
177+ on_time = math.floor ((sanitize_timing (child .preferences .configOnTime )) * 10 )
178+ off_wait = math.floor ((sanitize_timing (child .preferences .configOffWaitTime )) * 10 )
179+ end
181180 return on_time , off_wait
182181end
183182
@@ -195,12 +194,7 @@ local function handle_output_command(device, suffix, command_name)
195194 data_types .Uint16 (config_on_time ), data_types .Uint16 (config_off_wait_time )):to_endpoint (endpoint ))
196195 end
197196 else
198- if config_on_time == 0 then
199- device :send (OnOff .server .commands .Off (device ):to_endpoint (endpoint ))
200- else
201- device :send (OnOff .server .commands .OnWithTimedOff (device , data_types .Uint8 (0 ),
202- data_types .Uint16 (config_on_time ), data_types .Uint16 (config_off_wait_time )):to_endpoint (endpoint ))
203- end
197+ device :send (OnOff .server .commands .Off (device ):to_endpoint (endpoint ))
204198 end
205199end
206200
@@ -437,60 +431,33 @@ local function on_off_default_response_handler(driver, device, zb_rx)
437431 end
438432end
439433
440- local function switch_on_handler (driver , device , command )
441- local parent = device :get_parent_device ()
442- if parent then
443- local info = OUTPUT_BY_KEY [device .parent_assigned_child_key ]
444- if info then
445- handle_output_command (parent , info .suffix , " on" )
446- return
447- end
448- end
449-
450- local num = command .component and command .component :match (" output(%d)" )
451- if num then
452- handle_output_command (device , num , " on" )
453- return
454- end
455- num = command .component :match (" input(%d)" )
456- if num then
457- local component = device .profile .components [command .component ]
458- local value = device :get_latest_state (command .component , Switch .ID , Switch .switch .NAME )
459- if value == " on" then
460- device :emit_component_event (component ,
461- Switch .switch .on ({ state_change = true , visibility = { displayed = false } }))
462- elseif value == " off" then
463- device :emit_component_event (component ,
464- Switch .switch .off ({ state_change = true , visibility = { displayed = false } }))
434+ local function make_switch_handler (command_name )
435+ return function (driver , device , command )
436+ local parent = device :get_parent_device ()
437+ if parent then
438+ local info = OUTPUT_BY_KEY [device .parent_assigned_child_key ]
439+ if info then
440+ handle_output_command (parent , info .suffix , command_name )
441+ return
442+ end
465443 end
466- end
467- end
468444
469- local function switch_off_handler (driver , device , command )
470- local parent = device :get_parent_device ()
471- if parent then
472- local info = OUTPUT_BY_KEY [device .parent_assigned_child_key ]
473- if info then
474- handle_output_command (parent , info .suffix , " off" )
445+ local num = command .component and command .component :match (" output(%d)" )
446+ if num then
447+ handle_output_command (device , num , command_name )
475448 return
476449 end
477- end
478-
479- local num = command .component and command .component :match (" output(%d)" )
480- if num then
481- handle_output_command (device , num , " off" )
482- return
483- end
484- num = command .component :match (" input(%d)" )
485- if num then
486- local component = device .profile .components [command .component ]
487- local value = device :get_latest_state (command .component , Switch .ID , Switch .switch .NAME )
488- if value == " on" then
489- device :emit_component_event (component ,
490- Switch .switch .on ({ state_change = true , visibility = { displayed = false } }))
491- elseif value == " off" then
492- device :emit_component_event (component ,
493- Switch .switch .off ({ state_change = true , visibility = { displayed = false } }))
450+ num = command .component :match (" input(%d)" )
451+ if num then
452+ local component = device .profile .components [command .component ]
453+ local value = device :get_latest_state (command .component , Switch .ID , Switch .switch .NAME )
454+ if value == " on" then
455+ device :emit_component_event (component ,
456+ Switch .switch .on ({ state_change = true , visibility = { displayed = false } }))
457+ elseif value == " off" then
458+ device :emit_component_event (component ,
459+ Switch .switch .off ({ state_change = true , visibility = { displayed = false } }))
460+ end
494461 end
495462 end
496463end
@@ -516,8 +483,8 @@ local frient_bridge_handler = {
516483 },
517484 capability_handlers = {
518485 [Switch .ID ] = {
519- [Switch .commands .on .NAME ] = switch_on_handler ,
520- [Switch .commands .off .NAME ] = switch_off_handler
486+ [Switch .commands .on .NAME ] = make_switch_handler ( " on " ) ,
487+ [Switch .commands .off .NAME ] = make_switch_handler ( " off " )
521488 }
522489 },
523490 lifecycle_handlers = {
0 commit comments