@@ -112,7 +112,7 @@ def __start(bot, update):
112
112
return SELECTION
113
113
114
114
115
- # set the target, member of group or group
115
+ # select targets
116
116
def __selection (bot , update ):
117
117
global target
118
118
target = update .message .text
@@ -148,10 +148,74 @@ def __selected_target(bot, update, selected_target):
148
148
logger .info ('Selection: {0}' .format (str (selected_target )))
149
149
__start_standby_timer (bot , update )
150
150
return DURATION
151
- # end: set targets
151
+ # end: select targets
152
152
153
153
154
- # set water duration
154
+ # [#31] grouping
155
+ def __grouping (bot , update , chat_data ):
156
+ global selection
157
+ query = update .callback_query
158
+ btn_click = str (query .data )
159
+
160
+ if not (btn_click == str (lib .btn_finished ) or btn_click == str (lib .cancel )):
161
+ if not selection .__contains__ (int (btn_click )):
162
+ selection += (int (btn_click ),)
163
+ bot .edit_message_text (text = lib .msg_grouping_selection .format (selection ),
164
+ chat_id = query .message .chat_id ,
165
+ message_id = query .message .message_id ,
166
+ parse_mode = ParseMode .MARKDOWN ,
167
+ reply_markup = reply_markup )
168
+
169
+ elif btn_click == str (lib .btn_finished ) and len (selection ) > 0 :
170
+ global target
171
+ target = lib .grouping
172
+ bot .edit_message_text (text = lib .msg_grouping_selection .format (selection ),
173
+ chat_id = query .message .chat_id ,
174
+ message_id = query .message .message_id ,
175
+ parse_mode = ParseMode .MARKDOWN )
176
+ bot .send_message (text = lib .msg_duration .format (target + str (selection )),
177
+ chat_id = query .message .chat_id ,
178
+ parse_mode = ParseMode .MARKDOWN ,
179
+ reply_markup = markup2 )
180
+ logger .info ('Selected: {0} {1}' .format (str (target ), str (selection )))
181
+ return DURATION
182
+
183
+ elif btn_click == lib .cancel :
184
+ selection = ()
185
+ bot .delete_message (chat_id = query .message .chat_id ,
186
+ message_id = query .message .message_id )
187
+ bot .send_message (text = lib .msg_new_choice ,
188
+ chat_id = query .message .chat_id ,
189
+ parse_mode = ParseMode .MARKDOWN ,
190
+ reply_markup = markup1 )
191
+ return SELECTION
192
+
193
+
194
+ def __group_menu (bot , update ):
195
+ global selection
196
+ selection = ()
197
+ logger .info ('Grouping mode called.' )
198
+ inline_keyboard = [
199
+ [__get_btn (lib .group1 [1 ], conf .RELAIS_01 ), __get_btn (lib .group1 [2 ], conf .RELAIS_02 ),
200
+ __get_btn (lib .group1 [3 ], conf .RELAIS_03 ), __get_btn (lib .group3 [1 ], conf .RELAIS_04 )],
201
+ [__get_btn (lib .group3 [2 ], conf .RELAIS_05 ), __get_btn (lib .group2 [1 ], conf .RELAIS_06 ),
202
+ __get_btn (lib .group2 [2 ], conf .RELAIS_07 ), __get_btn (lib .group2 [3 ], conf .RELAIS_08 )],
203
+ [InlineKeyboardButton (lib .btn_finished , callback_data = lib .btn_finished ),
204
+ InlineKeyboardButton (lib .btn_cancel , callback_data = lib .btn_cancel )]
205
+ ]
206
+
207
+ global reply_markup
208
+ reply_markup = InlineKeyboardMarkup (inline_keyboard )
209
+ update .message .reply_text (lib .msg_grouping , reply_markup = reply_markup , parse_mode = ParseMode .MARKDOWN )
210
+ return GROUPING
211
+
212
+
213
+ def __get_btn (text , callback ):
214
+ return InlineKeyboardButton ('{0} ({1})' .format (text , callback ), callback_data = callback )
215
+ # end: grouping
216
+
217
+
218
+ # water duration
155
219
def __duration (bot , update ):
156
220
global water_time
157
221
global g_duration_update
@@ -230,6 +294,7 @@ def __duration(bot, update):
230
294
231
295
__start_standby_timer (bot , update )
232
296
return SELECTION
297
+ # end: duration
233
298
234
299
235
300
# watering targets
@@ -393,68 +458,6 @@ def __cam_off():
393
458
# end: camera
394
459
395
460
396
- # [#31] grouping
397
- def __push_button (bot , update , chat_data ):
398
- global selection
399
- query = update .callback_query
400
- added_selection = str (query .data )
401
-
402
- if not (added_selection == str (lib .btn_finished ) or added_selection == str (lib .cancel )):
403
- if not selection .__contains__ (int (added_selection )):
404
- selection += (int (added_selection ),)
405
- bot .edit_message_text (text = lib .msg_grouping_selection .format (selection ),
406
- chat_id = query .message .chat_id ,
407
- message_id = query .message .message_id ,
408
- parse_mode = ParseMode .MARKDOWN ,
409
- reply_markup = reply_markup )
410
-
411
- elif added_selection == str (lib .btn_finished ) and len (selection ) > 0 :
412
- global target
413
- target = lib .grouping
414
- bot .delete_message (chat_id = query .message .chat_id ,
415
- message_id = query .message .message_id )
416
- bot .send_message (text = lib .msg_duration .format (target ),
417
- chat_id = query .message .chat_id ,
418
- parse_mode = ParseMode .MARKDOWN ,
419
- reply_markup = markup2 )
420
- logger .info ('Grouped selection: {0} {1}' .format (str (target ), str (selection )))
421
- return DURATION
422
-
423
- elif added_selection == lib .cancel :
424
- selection = ()
425
- bot .delete_message (chat_id = query .message .chat_id ,
426
- message_id = query .message .message_id )
427
- bot .send_message (text = lib .msg_new_choice ,
428
- chat_id = query .message .chat_id ,
429
- parse_mode = ParseMode .MARKDOWN ,
430
- reply_markup = markup1 )
431
- return SELECTION
432
-
433
-
434
- def __group_menu (bot , update ):
435
- global selection
436
- selection = ()
437
- logger .info ('Grouping mode called.' )
438
- inline_keyboard = [
439
- [__get_btn (lib .group1 [1 ], conf .RELAIS_01 ), __get_btn (lib .group1 [2 ], conf .RELAIS_02 ),
440
- __get_btn (lib .group1 [3 ], conf .RELAIS_03 ), __get_btn (lib .group3 [1 ], conf .RELAIS_04 )],
441
- [__get_btn (lib .group3 [2 ], conf .RELAIS_05 ), __get_btn (lib .group2 [1 ], conf .RELAIS_06 ),
442
- __get_btn (lib .group2 [2 ], conf .RELAIS_07 ), __get_btn (lib .group2 [3 ], conf .RELAIS_08 )],
443
- [InlineKeyboardButton (lib .btn_finished , callback_data = lib .btn_finished ),
444
- InlineKeyboardButton (lib .btn_cancel , callback_data = lib .btn_cancel )]
445
- ]
446
-
447
- global reply_markup
448
- reply_markup = InlineKeyboardMarkup (inline_keyboard )
449
- update .message .reply_text (lib .msg_grouping , reply_markup = reply_markup , parse_mode = ParseMode .MARKDOWN )
450
- return GROUPING
451
-
452
-
453
- def __get_btn (text , callback ):
454
- return InlineKeyboardButton ('{0} ({1})' .format (text , callback ), callback_data = callback )
455
- # end: grouping
456
-
457
-
458
461
def main ():
459
462
__init_bot_set_pins ()
460
463
@@ -486,7 +489,7 @@ def main():
486
489
DURATION : [RegexHandler ('^([0-9]+|{0}|{1})$' .format (str (lib .cancel ), str (lib .panic )), __duration ),
487
490
RegexHandler ('^{0}$' .format (lib .stop_bot ), __stop )],
488
491
489
- GROUPING : [CallbackQueryHandler (__push_button , pass_chat_data = True ),
492
+ GROUPING : [CallbackQueryHandler (__grouping , pass_chat_data = True ),
490
493
RegexHandler ('^({0}|{1}|{2})$' .format (
491
494
str (lib .cancel ), str (lib .btn_finished ), str (selection )),
492
495
__selection )]
0 commit comments