@@ -144,10 +144,12 @@ sub_()
144144 local sub=" #"
145145 local count=1
146146 local expect=" "
147-
147+ local delay=1
148+
148149 [ " $1 " = " " ] || sub=" $1 "
149150 [ " $2 " = " " ] || expect=" $2 "
150151 [ " $3 " = " " ] || count=" $3 "
152+ [ " $4 " = " " ] || delay=" $4 "
151153
152154 printf " ${cyan} sub: $sub ${nocol} (count=${count} )\n"
153155 mosquitto_sub -v -t " $sub " -C $count | tee " $mqtt_sub_log "
@@ -160,6 +162,7 @@ sub_()
160162 cat " $mqtt_sub_log " ;
161163 exit_ 11; }
162164 fi
165+ sleep $delay
163166}
164167
165168
@@ -367,13 +370,19 @@ play_net_add_node_()
367370 pubsub_ " $pub " " $message " " $sub "
368371
369372 log_ " Find controller"
373+
370374 sub=" ucl/by-unid/+/ProtocolController/NetworkManagement"
371375 message=" {}"
372376 json=' {"State":"idle","SupportedStateList":["add node","remove node","reset"]}'
373377 expect=' {"State":"idle","SupportedStateList":\["add node","remove node","reset"\]}'
374378 expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
375379 pubsub_ " $pub " " $message " " $sub " " $expect "
376380
381+ sub=" ucl/by-unid/$contunid /State"
382+ json=' {"MaximumCommandDelay":0,"NetworkList":[""],"NetworkStatus":"Online functional","Security":"Z-Wave S2 Access Control"}'
383+ expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
384+ sub_ " $sub " " $expect "
385+
377386 log_ " net: ${command} : node: Set to learn mode"
378387 node_cli_ " $node " n
379388 [ 0 -eq 0$nodeid ] || exit_ 16
@@ -396,34 +405,38 @@ play_net_add_node_()
396405 node_cli_ " $node " d
397406 node_cli_ " $node " n
398407
399- log_ " Takes time from interviewing to functional"
408+ log_ " Takes time from interviewing to functional"
400409 pub=" ucl/by-unid/$contunid /ProtocolController/NetworkManagement/Write"
401410 message=' {"State":"add node","StateParameters":{"UserAccept":true,"SecurityCode":"' ${SecurityCode} ' ","AllowMultipleInclusions":false}}'
402411 sub=" ucl/by-unid/$nodeunid /State"
412+ pub_ " $pub " " $message "
413+
414+ NetworkStatus=' .*' # Match: [ "Online interviewing", "Online functional" ]
403415 MaximumCommandDelay=' .*' # Variable: 1, 300
404- NetworkStatus=' .*' #
405- NetworkStatus=' "Online interviewing"'
406- json=' {"MaximumCommandDelay":' ${MaximumCommandDelay} ' ,"NetworkList":[""],"NetworkStatus":' ${NetworkStatus} ' ,"Security":"Z-Wave S2 Authenticated"}'
416+ Security=' .*'
417+ json=' {"MaximumCommandDelay":' ${MaximumCommandDelay} ' ,"NetworkList":[""],"NetworkStatus":"' ${NetworkStatus} ' ","Security":"' ${Security} ' "}'
407418 expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
408419 expect=" $sub $expect "
409- count=" 2" # "NetworkStatus": "Online interviewing" *2
410- count=" 3"
411- pubsub_ " $pub " " $message " " $sub " " $expect " " $count "
412420
413- NetworkStatus=' "Online functional"'
414- json=' {"MaximumCommandDelay":' ${MaximumCommandDelay} ' ,"NetworkList":[""],"NetworkStatus":' ${NetworkStatus} ' ,"Security":"Z-Wave S2 Authenticated"}'
415- expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
416- expect=" $sub $expect "
417- pubsub_ " $pub " " $message " " $sub " " $expect "
418-
419- pub=" "
420- message=" "
421+ NetworkStatus=' Online functional'
422+ Security=" Z-Wave S2 Authenticated"
423+ json=' {"MaximumCommandDelay":' ${MaximumCommandDelay} ' ,"NetworkList":[""],"NetworkStatus":"' ${NetworkStatus} ' ","Security":"' ${Security} ' "}'
424+ over_expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
425+ over_expect=" $sub $over_expect "
426+ over=false
427+ while ! $over ; do # Multiple steps: "Online interviewing"+
428+ log_ " is it over ?"
429+ sub_ " $sub " " $expect "
430+ # "Z-Wave S2 Authenticated"
431+ grep -E " $over_expect " " $mqtt_sub_log " && over=true || :
432+ done
433+
421434 sub=" ucl/by-unid/+/State/Attributes/EndpointIdList/Reported"
422435 sub=$( echo " $sub " | sed -e " s|/+/|/$nodeunid /|g" )
423436 json=' {"value":[0]}'
424437 expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
425438 expect=" $sub $expect "
426- pubsub_ " $pub " " $message " " $ sub" " $expect " 2
439+ # sub_ "$sub" "$expect"
427440
428441 node_cli_ " $node " H # expected on 1st time
429442 [ $conthomeid = $nodehomeid ] || exit 17_
@@ -448,7 +461,9 @@ play_net_remove_node_()
448461 message=' {"State":"remove node"}'
449462 sub=" ucl/by-unid/+/State/SupportedCommands"
450463 node_cli_ " $node " n > /dev/null
451- expect=$( echo " $sub (null)" | sed -e " s|/+/|/$nodeunid /|g" )
464+ expect=' (null)'
465+ expect=$( echo " $expect " | sed sed ' s|[()]|\\&|g' )
466+ expect=$( echo " $sub $expect " | sed -e " s|/+/|/$nodeunid /|g" )
452467 node_cli_ " $node " l
453468 pubsub_ " $pub " " $message " " $sub " " $expect " 3
454469 node_cli_ " $node " n
0 commit comments