From d5040bff9aa65a829093a152aac937531548474d Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 14 Mar 2019 08:35:11 +0100 Subject: [PATCH 01/19] [#31] continue test grouping, changed timeout value --- bot/conf/lib_global.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/conf/lib_global.py b/bot/conf/lib_global.py index 79a58ca..b4956c5 100644 --- a/bot/conf/lib_global.py +++ b/bot/conf/lib_global.py @@ -14,7 +14,7 @@ """ timeout if no user activity """ -timeout = 6000000 +timeout = 600 """ language settings From 1d2995839d1d00cfa16703b8f79bd76272e759c5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 18:05:48 +0100 Subject: [PATCH 02/19] [#31] continue test grouping --- bot/conf/lib_ext_greenhouse.py | 2 +- bot/greenhouse.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/bot/conf/lib_ext_greenhouse.py b/bot/conf/lib_ext_greenhouse.py index 9f1cf47..0072b4e 100644 --- a/bot/conf/lib_ext_greenhouse.py +++ b/bot/conf/lib_ext_greenhouse.py @@ -29,7 +29,7 @@ msg_help = 'Usage and possible commands in special mode:{0}' \ '{1} - this info{0}' \ '{2} - restart the whole RSBPi{0}' \ - '{3} - force update{0}' \ + '{3} - force update from repository{0}' \ '{4} - force archiving and cleaning of log files{0}' \ '{5} - stop this mode{0}' \ '{6} - switch all on{0}' \ diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 8faf5e4..58093b3 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -40,7 +40,7 @@ group_three = conf.GROUP_03 # api and bot settings -SELECTION, DURATION = range(2) +SELECTION, DURATION, GROUP = range(3) # LIST_OF_ADMINS = ['mock to test'] list_of_admins = conf.admins token = conf.token @@ -434,7 +434,7 @@ def __button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - return DURATION + return GROUP elif added_selection == lib.cancel: selection = () @@ -491,7 +491,7 @@ def main(): entry_points=[CommandHandler('start', __start)], states={ SELECTION: [RegexHandler( - '^({0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11})$'.format( + '^({0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10})$'.format( str(lib.group1[1]), str(lib.group1[2]), str(lib.group1[3]), @@ -502,8 +502,7 @@ def main(): str(lib.group3[2]), str(lib.panic), str(lib.live_stream), - str(lib.reload), - str(selection)), + str(lib.reload)), __selection), RegexHandler( '^{0}$'.format( @@ -523,8 +522,14 @@ def main(): RegexHandler( '^{0}$'.format( lib.stop_bot), - __stop)] - }, + __stop) + ], + GROUP: [RegexHandler( + '^({0})$'.format( + str(selection)), + __selection) + ] + }, fallbacks=[CommandHandler('stop', __stop)], allow_reentry=True ) From fb1a8d8cfc0de6e9c92db989fb5596c7501fc229 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 18:16:14 +0100 Subject: [PATCH 03/19] [#31] continue test grouping --- bot/greenhouse.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 58093b3..6701d02 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -40,7 +40,7 @@ group_three = conf.GROUP_03 # api and bot settings -SELECTION, DURATION, GROUP = range(3) +SELECTION, DURATION, GROUPING = range(3) # LIST_OF_ADMINS = ['mock to test'] list_of_admins = conf.admins token = conf.token @@ -434,7 +434,7 @@ def __button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - return GROUP + return GROUPING elif added_selection == lib.cancel: selection = () @@ -524,14 +524,16 @@ def main(): lib.stop_bot), __stop) ], - GROUP: [RegexHandler( + GROUPING: [RegexHandler( '^({0})$'.format( str(selection)), __selection) ] }, fallbacks=[CommandHandler('stop', __stop)], - allow_reentry=True + allow_reentry=True, + per_chat=True, + per_user=True ) dp.add_handler(group_handler) From 51ff0609ba2ca06328461855354d1b47338d86a1 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 18:49:58 +0100 Subject: [PATCH 04/19] [#31] continue test grouping --- bot/greenhouse.py | 65 ++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 6701d02..8137f2c 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -407,7 +407,7 @@ def __cam_off(): # grouping -def __button(bot, update, chat_data): +def __push_button(bot, update, chat_data): global selection query = update.callback_query added_selection = str(query.data) @@ -434,7 +434,7 @@ def __button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - return GROUPING + return DURATION elif added_selection == lib.cancel: selection = () @@ -452,7 +452,7 @@ def __get_inline_btn(text, callback): return InlineKeyboardButton(text, callback_data=callback) -def __group(bot, update): +def __group_menu(bot, update): global selection selection = () logger.info('Grouping mode called.') @@ -468,6 +468,7 @@ def __group(bot, update): reply_markup = InlineKeyboardMarkup(inline_keyboard) update.message.reply_text(lib.msg_grouping, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN) __start_standby_timer(bot, update) + return GROUPING def main(): @@ -482,7 +483,7 @@ def main(): dp = updater.dispatcher - group_handler = CallbackQueryHandler(__button, pass_chat_data=True) + # group_handler = CallbackQueryHandler(__push_button, pass_chat_data=True) emergency_stop_handler = RegexHandler('^{0}$'.format(str(lib.emergency_stop)), __emergency_stop_handler, @@ -490,52 +491,30 @@ def main(): ch = ConversationHandler( entry_points=[CommandHandler('start', __start)], states={ - SELECTION: [RegexHandler( - '^({0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10})$'.format( - str(lib.group1[1]), - str(lib.group1[2]), - str(lib.group1[3]), - str(lib.group2[1]), - str(lib.group2[2]), - str(lib.group2[3]), - str(lib.group3[1]), - str(lib.group3[2]), - str(lib.panic), - str(lib.live_stream), - str(lib.reload)), + SELECTION: [RegexHandler('^({0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10})$'.format( + str(lib.group1[1]), str(lib.group1[2]), str(lib.group1[3]), + str(lib.group2[1]), str(lib.group2[2]), str(lib.group2[3]), + str(lib.group3[1]), str(lib.group3[2]), + str(lib.panic), str(lib.live_stream), str(lib.reload)), __selection), - RegexHandler( - '^{0}$'.format( - lib.stop_bot), - __stop), - RegexHandler( - '^{0}$'.format( - lib.grouping), - __group) - ], - - DURATION: [RegexHandler( - '^([0-9]+|{0}|{1})$'.format( - str(lib.cancel), - str(lib.panic)), - __duration), - RegexHandler( - '^{0}$'.format( - lib.stop_bot), - __stop) - ], - GROUPING: [RegexHandler( - '^({0})$'.format( - str(selection)), - __selection) - ] + + RegexHandler('^{0}$'.format(lib.stop_bot), __stop), + RegexHandler('^{0}$'.format(lib.grouping), __group_menu)], + + DURATION: [RegexHandler('^([0-9]+|{0}|{1})$'.format(str(lib.cancel), str(lib.panic)), __duration), + RegexHandler('^{0}$'.format(lib.stop_bot), __stop)], + + GROUPING: [CallbackQueryHandler(__push_button), + RegexHandler('^({0}|{1}|{2})$'.format( + str(lib.cancel), str(lib.btn_finished), str(selection)), + __selection)] }, fallbacks=[CommandHandler('stop', __stop)], allow_reentry=True, per_chat=True, per_user=True ) - dp.add_handler(group_handler) + # dp.add_handler(group_handler) dp.add_handler(emergency_stop_handler) From 3e1706ce9e11ac0226c5e6d4c4bf7964952d8862 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 18:58:40 +0100 Subject: [PATCH 05/19] [#31] continue test grouping --- bot/greenhouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 8137f2c..c3d8eb3 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -504,7 +504,7 @@ def main(): DURATION: [RegexHandler('^([0-9]+|{0}|{1})$'.format(str(lib.cancel), str(lib.panic)), __duration), RegexHandler('^{0}$'.format(lib.stop_bot), __stop)], - GROUPING: [CallbackQueryHandler(__push_button), + GROUPING: [CallbackQueryHandler(__push_button, pass_chat_data=True), RegexHandler('^({0}|{1}|{2})$'.format( str(lib.cancel), str(lib.btn_finished), str(selection)), __selection)] From 6b7c14c34430c6fca53c1826b70816b8ce0da32b Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 19:13:15 +0100 Subject: [PATCH 06/19] [#31] grouping added - updated ConversationHandler, CallbackQueryHandler included, new state GROUPING added - InlineKeyboard for Grouping added - some methods changed and updated - some refactorings --- bot/greenhouse.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index c3d8eb3..694a552 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -483,8 +483,6 @@ def main(): dp = updater.dispatcher - # group_handler = CallbackQueryHandler(__push_button, pass_chat_data=True) - emergency_stop_handler = RegexHandler('^{0}$'.format(str(lib.emergency_stop)), __emergency_stop_handler, pass_chat_data=True) @@ -511,10 +509,10 @@ def main(): }, fallbacks=[CommandHandler('stop', __stop)], allow_reentry=True, + per_message=True, per_chat=True, per_user=True ) - # dp.add_handler(group_handler) dp.add_handler(emergency_stop_handler) From 63107a5fd54714def1683da25bf7e52b0b54b58d Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 19:47:18 +0100 Subject: [PATCH 07/19] [#31] grouping - unnecessary logs removed - standby adapted - empty selection considered - CallbackQueryHandler, tracking warning disabled --- bot/greenhouse.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 694a552..6d66af1 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -219,7 +219,7 @@ def __duration(bot, update): __water(bot, update, group_three[1]) elif target == str(lib.grouping): - logger.warning("selected to water..." + str(selection)) + # TODO: display group! __water_group(bot, update, selection) else: @@ -425,8 +425,6 @@ def __push_button(bot, update, chat_data): elif added_selection == str(lib.btn_finished): global target target = lib.grouping - logger.info('current selection: ' + str(selection)) - logger.info('current target: ' + str(target)) bot.delete_message(chat_id=query.message.chat_id, message_id=query.message.message_id) bot.send_message(text=lib.msg_duration.format(target), @@ -434,22 +432,25 @@ def __push_button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - return DURATION + if selection.__len__() < 1: + __cancel_grouping(bot, query) + else: + return DURATION elif added_selection == lib.cancel: - selection = () - bot.delete_message(chat_id=query.message.chat_id, - message_id=query.message.message_id) - bot.send_message(text=lib.msg_new_choice, - chat_id=query.message.chat_id, - parse_mode=ParseMode.MARKDOWN, - reply_markup=markup1) - logger.info(lib.msg_new_choice) - return SELECTION + __cancel_grouping(bot, query) -def __get_inline_btn(text, callback): - return InlineKeyboardButton(text, callback_data=callback) +def __cancel_grouping(bot, query): + global selection + selection = () + bot.delete_message(chat_id=query.message.chat_id, + message_id=query.message.message_id) + bot.send_message(text=lib.msg_new_choice, + chat_id=query.message.chat_id, + parse_mode=ParseMode.MARKDOWN, + reply_markup=markup1) + return SELECTION def __group_menu(bot, update): @@ -467,10 +468,13 @@ def __group_menu(bot, update): global reply_markup reply_markup = InlineKeyboardMarkup(inline_keyboard) update.message.reply_text(lib.msg_grouping, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN) - __start_standby_timer(bot, update) return GROUPING +def __get_inline_btn(text, callback): + return InlineKeyboardButton(text, callback_data=callback) + + def main(): __init_bot_set_pins() From 8bc3852a4d035129dd142a7cf7e1f5cd5fea8b5a Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 19:53:40 +0100 Subject: [PATCH 08/19] [#31] grouping - ConversationHandler, typo fixed --- bot/greenhouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 6d66af1..103e71a 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -513,7 +513,7 @@ def main(): }, fallbacks=[CommandHandler('stop', __stop)], allow_reentry=True, - per_message=True, + per_message=False, per_chat=True, per_user=True ) From 803157e8402b318f581e1d59a7c5185fb8e95ef7 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 20:07:54 +0100 Subject: [PATCH 09/19] [#31] grouping - canceling fixed --- bot/greenhouse.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 103e71a..37ec31f 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -432,13 +432,14 @@ def __push_button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - if selection.__len__() < 1: - __cancel_grouping(bot, query) + logger.warning(selection.__len__) + if selection.__len__ < 1: + return __cancel_grouping(bot, query) else: return DURATION elif added_selection == lib.cancel: - __cancel_grouping(bot, query) + return __cancel_grouping(bot, query) def __cancel_grouping(bot, query): From 4aa1425cd8e76086999252756a9ffde278aa9e9d Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 20:14:58 +0100 Subject: [PATCH 10/19] [#31] grouping - tuple length fixed (if selection empty) --- bot/greenhouse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 37ec31f..a31c7df 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -432,8 +432,8 @@ def __push_button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - logger.warning(selection.__len__) - if selection.__len__ < 1: + logger.warning(len(selection)) + if len(selection) < 1: return __cancel_grouping(bot, query) else: return DURATION From 059a4bbed5e9f46773eaafa5f1aa1a5a40500478 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 20:45:02 +0100 Subject: [PATCH 11/19] [#31] grouping - canceling fixed --- bot/greenhouse.py | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index a31c7df..19966fb 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -406,11 +406,12 @@ def __cam_off(): return -# grouping +# [#31] grouping def __push_button(bot, update, chat_data): global selection query = update.callback_query added_selection = str(query.data) + if not (added_selection == str(lib.btn_finished) or added_selection == str(lib.cancel)): if not selection.__contains__(int(added_selection)): selection += (int(added_selection),) @@ -420,9 +421,7 @@ def __push_button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup) - logger.info(selection) - - elif added_selection == str(lib.btn_finished): + elif added_selection == str(lib.btn_finished) and len(selection) > 0: global target target = lib.grouping bot.delete_message(chat_id=query.message.chat_id, @@ -432,26 +431,17 @@ def __push_button(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Grouped selection: {0} {1}'.format(str(target), str(selection))) - logger.warning(len(selection)) - if len(selection) < 1: - return __cancel_grouping(bot, query) - else: - return DURATION + return DURATION elif added_selection == lib.cancel: - return __cancel_grouping(bot, query) - - -def __cancel_grouping(bot, query): - global selection - selection = () - bot.delete_message(chat_id=query.message.chat_id, - message_id=query.message.message_id) - bot.send_message(text=lib.msg_new_choice, - chat_id=query.message.chat_id, - parse_mode=ParseMode.MARKDOWN, - reply_markup=markup1) - return SELECTION + selection = () + bot.delete_message(chat_id=query.message.chat_id, + message_id=query.message.message_id) + bot.send_message(text=lib.msg_new_choice, + chat_id=query.message.chat_id, + parse_mode=ParseMode.MARKDOWN, + reply_markup=markup1) + return SELECTION def __group_menu(bot, update): @@ -474,7 +464,7 @@ def __group_menu(bot, update): def __get_inline_btn(text, callback): return InlineKeyboardButton(text, callback_data=callback) - +# end grouping def main(): __init_bot_set_pins() @@ -514,7 +504,6 @@ def main(): }, fallbacks=[CommandHandler('stop', __stop)], allow_reentry=True, - per_message=False, per_chat=True, per_user=True ) From b584f85b78c727eee3927123054cd4634f245263 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 21:04:54 +0100 Subject: [PATCH 12/19] [#31] grouping - unnecessary functions removed - libraries updated - logging improved --- bot/conf/lib_english.py | 4 ---- bot/conf/lib_german.py | 4 ---- bot/greenhouse.py | 45 +++++++++++++---------------------------- bot/logger/logger.ini | 4 ++-- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/bot/conf/lib_english.py b/bot/conf/lib_english.py index fa6ca0e..1c863e1 100644 --- a/bot/conf/lib_english.py +++ b/bot/conf/lib_english.py @@ -48,11 +48,7 @@ msg_stop = '` S T A N D B Y \n Restart ->` /start' msg_duration = '`Specify switching time for \'{}\' in ' + time_units_name[time_units_index] + ':`' water_on = '`\'{}\' is switched on for {}' + time_units_sign[time_units_index] + '.`' -water_on_group = '`{} are switched on for {}' + time_units_sign[time_units_index] + '.`' -water_on_all = '`\'{}\' is switched on for {}' + time_units_sign[time_units_index] + '.`' water_off = '`\'{}\' was switched off after {}' + time_units_sign[time_units_index] + '.\n\n`' -water_off_group = '`\'{}\' were switched off after {}' + time_units_sign[time_units_index] + '.\n\n`' -water_off_all = '`All was switched off after {}' + time_units_sign[time_units_index] + '.`\n\n' msg_choice = '`Please select:`' msg_new_choice = '`New choice or end?`' msg_panic = '`PANIC MODE!`' diff --git a/bot/conf/lib_german.py b/bot/conf/lib_german.py index 303801e..9e2a876 100644 --- a/bot/conf/lib_german.py +++ b/bot/conf/lib_german.py @@ -50,11 +50,7 @@ msg_stop = '` S T A N D B Y \n Neustart ->` /start' msg_duration = '`Schaltzeit für \'{}\' in ' + time_units_name[time_units_index] + ' angeben:`' water_on = '`\'{}\' wird jetzt für {}' + time_units_sign[time_units_index] + ' eingeschaltet.`' -water_on_group = '`{} werden jetzt für {}' + time_units_sign[time_units_index] + ' eingeschalten.`' -water_on_all = '`\'{}\' wird jetzt für {}' + time_units_sign[time_units_index] + ' eingeschalten.`' water_off = '`\'{}\' nach {}' + time_units_sign[time_units_index] + ' abgeschalten.\n\n`' -water_off_group = '`\'{}\' wurden nach {}' + time_units_sign[time_units_index] + ' abgeschalten.\n\n`' -water_off_all = '`Alles wurde nach {}' + time_units_sign[time_units_index] + ' wieder abgeschalten.`\n\n' msg_choice = '`Bitte auswählen:`' msg_new_choice = '`Neue Auswahl oder Beenden?`' msg_panic = '*PANIK-MODUS*' diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 19966fb..7645e08 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -148,6 +148,7 @@ def __selected_target(bot, update, selected_target): logger.info('Selection: {0}'.format(str(selected_target))) __start_standby_timer(bot, update) return DURATION +# end: set targets # set water duration @@ -237,30 +238,6 @@ def __all_off(): return -# TODO: check if still needed! -@run_async -def __water_all(bot, update): - logger.info('Duration: {0}'.format(water_time)) - __stop_standby_timer(bot, update) - update.message.reply_text(lib.water_on_all.format(target, water_time), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup3) - - """ starts separate thread """ - display.show_switch_group_duration(0, int(water_time)) - - for channel in all_groups: - utils.switch_on(channel) - time.sleep(int(water_time) * int(lib.time_conversion)) - __all_off() - - update.message.reply_text('{0}{1}{2}'.format( - __timestamp(), lib.water_off_all.format(water_time), lib.msg_new_choice), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) - display.show_off() - __start_standby_timer(bot, update) - return - - @run_async def __water(bot, update, channel): logger.info('Duration: {0}'.format(water_time)) @@ -286,7 +263,7 @@ def __water_group(bot, update, group): logger.info('Duration: {0}'.format(water_time)) logger.info('Toggle {0}'.format(str(group))) __stop_standby_timer(bot, update) - update.message.reply_text(lib.water_on_group.format(target, water_time), + update.message.reply_text(lib.water_on.format(target, water_time), parse_mode=ParseMode.MARKDOWN, reply_markup=markup3) for channel in group: @@ -295,11 +272,12 @@ def __water_group(bot, update, group): for channel in group: utils.switch_off(channel) update.message.reply_text('{0}{1}{2}'.format( - __timestamp(), lib.water_off_group.format(target, water_time), lib.msg_new_choice), + __timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) display.show_off() __start_standby_timer(bot, update) return +# end watering targets # get humidity and temperature values @@ -350,27 +328,29 @@ def __emergency_stop_handler(bot, update, chat_data): def __start_emergency_stop(bot, update): global emergency_job emergency_job = jq.run_once(__job_stop_and_restart, 0, context=update) - logger.warning("Initialize emergency stop immediately.") + logger.info("Initialize emergency stop immediately.") return +# end: emergency stop # [#30] implement standby init after given time without user activity def __start_standby_timer(bot, update): global timer_job timer_job = jq.run_once(__job_stop_and_restart, conf.standby_timeout, context=update) - logger.warning("Init standby timer of {0} seconds, added to queue.".format(conf.standby_timeout)) + logger.info("Init standby timer of {0} seconds, added to queue.".format(conf.standby_timeout)) return def __stop_standby_timer(bot, update): timer_job.schedule_removal() - logger.warning("Timer job removed from the queue.") + logger.info("Timer job removed from the queue.") return +# end: standby # job to stop and restart application def __job_stop_and_restart(bot, job): - logger.warning("Job: Stop and restart called!") + logger.info("Job: Stop and restart called!") stop_and_restart.stop_and_restart(job.context) return @@ -391,6 +371,7 @@ def __timestamp(): def __start_time(): return utils.get_timestamp() +# end: time stamps # camera @@ -404,6 +385,7 @@ def __cam_off(): logger.info('Disable camera module.') os.system(conf.disable_camera) return +# end: camera # [#31] grouping @@ -464,7 +446,8 @@ def __group_menu(bot, update): def __get_inline_btn(text, callback): return InlineKeyboardButton(text, callback_data=callback) -# end grouping +# end: grouping + def main(): __init_bot_set_pins() diff --git a/bot/logger/logger.ini b/bot/logger/logger.ini index c40bdcc..55ef727 100644 --- a/bot/logger/logger.ini +++ b/bot/logger/logger.ini @@ -24,7 +24,7 @@ formatter=file args=('/greenhouse.log',) [formatter_console] -format=%(asctime)s %(levelname)-8s %(name)-15s %(module)-16s > %(message)s +format=%(asctime)s %(levelname)-8s %(name)s %(module)s > %(message)s [formatter_file] -format=%(asctime)s %(levelname)-8s %(module)-16s %(threadName)-38s > %(message)s +format=%(asctime)s %(levelname)-8s %(module)-20s %(threadName)-40s > %(message)s From f93ad80d1991317d4f85dd94d7c11b21a5d60342 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 21:26:55 +0100 Subject: [PATCH 13/19] [#31] grouping, 4 digit display updated - unnecessary vars removed - functions updated - changed logging --- bot/greenhouse.py | 4 +++- bot/peripherals/four_digit/display.py | 34 +++++---------------------- bot/utils/stop_and_restart.py | 6 ++--- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 7645e08..5ff020f 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -220,7 +220,9 @@ def __duration(bot, update): __water(bot, update, group_three[1]) elif target == str(lib.grouping): - # TODO: display group! + """ starts separate thread """ + show_switch_group_duration(int(water_time)) + __water_group(bot, update, selection) else: diff --git a/bot/peripherals/four_digit/display.py b/bot/peripherals/four_digit/display.py index 9dc3a7a..841ef1b 100644 --- a/bot/peripherals/four_digit/display.py +++ b/bot/peripherals/four_digit/display.py @@ -14,10 +14,6 @@ display = tm1637.TM1637(clk=clk_pin, dio=dio_pin, brightness=brightness) -group1 = [12, 1, 34, 3] -group2 = [12, 6, 34, 8] -group3 = [12, 4, 34, 5] -all_channels = [38, 10, 22, 22] on = [38, 0, 24, 38] off = [38, 0, 15, 15] boot = [11, 26, 26, 39] @@ -28,6 +24,7 @@ update = [30, 27, 13, 39] extended = [27, 24, 1, 49] ready = [38, 28, 13, 32] +group = [38, 16, 28, 27] def show_duration(duration): @@ -111,22 +108,13 @@ def show_switch_channel_duration(channel, duration): thread.start() -def show_group(group): +def show_group(): __disable_colon(True) - if group == 1: - display.show(group1) - elif group == 2: - display.show(group2) - elif group == 3: - display.show(group3) - elif group == 0: - display.show(all_channels) - else: - display.clear() + display.show(group) return -def show_switch_group_duration(group, duration): +def show_switch_group_duration(duration): duration = duration * lib.time_conversion global thread global g_group @@ -174,22 +162,12 @@ def __switch_channel_duration(channel, duration): return -# TODO: update function accordingly new grouping! -def __switch_group_duration(group, duration): +def __switch_group_duration(duration): global g_display g_display = tm1637.TM1637(clk=clk_pin, dio=dio_pin, brightness=brightness) g_display.show_doublepoint(False) while duration > 0: - if group == 1: - display.show(group1) - elif group == 2: - display.show(group2) - elif group == 3: - display.show(group3) - elif group == 0: - display.show(all_channels) - else: - display.clear() + display.show(group) sleep(1) duration -= 1 g_display.show_remain_int(duration) diff --git a/bot/utils/stop_and_restart.py b/bot/utils/stop_and_restart.py index 7f6c5b5..60bde0c 100644 --- a/bot/utils/stop_and_restart.py +++ b/bot/utils/stop_and_restart.py @@ -23,15 +23,15 @@ def stop_and_restart(update): - logging.warning('Stop and restart, set bot in standby.') + logging.info('Stop and restart - set to standby.') utils.read_cmd(conf.disable_camera, lib.tmp_file) display.show_stop() time.sleep(2) - # start new new instance of greenhouse + """ start new new instance of greenhouse """ utils.read_cmd(lib.restart_bot, lib.tmp_file) update.message.reply_text(conf.lib.msg_stop, parse_mode=ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) display.show_standby() - # kill the current instance of greenhouse bot + """ kill the current instance of greenhouse bot """ pid1 = utils.read_cmd(lib.get_pid1, lib.tmp_file) utils.read_cmd('kill -9 {0}'.format(str(pid1)), lib.tmp_file) return From 553c8fd930cfd9688522fb9d0a347739efa08b86 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 21:32:18 +0100 Subject: [PATCH 14/19] [#31] grouping, 4 digit display fixed --- bot/greenhouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 5ff020f..7f6c64e 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -221,7 +221,7 @@ def __duration(bot, update): elif target == str(lib.grouping): """ starts separate thread """ - show_switch_group_duration(int(water_time)) + display.show_switch_group_duration(int(water_time)) __water_group(bot, update, selection) From 59f7c8c5738abeb2247383a4755d0e221d59adf4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 22:22:10 +0100 Subject: [PATCH 15/19] [#31] grouping, 4 digit display fixed --- bot/peripherals/four_digit/display.py | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/bot/peripherals/four_digit/display.py b/bot/peripherals/four_digit/display.py index 841ef1b..7e93f9a 100644 --- a/bot/peripherals/four_digit/display.py +++ b/bot/peripherals/four_digit/display.py @@ -17,14 +17,14 @@ on = [38, 0, 24, 38] off = [38, 0, 15, 15] boot = [11, 26, 26, 39] -error = [38, 14, 28, 28] +err = [38, 14, 28, 28] stop = [29, 39, 0, 27] run = [38, 28, 40, 24] -standby = [29, 39, 11, 32] -update = [30, 27, 13, 39] -extended = [27, 24, 1, 49] -ready = [38, 28, 13, 32] -group = [38, 16, 28, 27] +stby = [29, 39, 11, 32] +updt = [30, 27, 13, 39] +pnic = [27, 24, 1, 49] +rdy = [38, 28, 13, 32] +grp = [38, 16, 28, 27] def show_duration(duration): @@ -36,25 +36,25 @@ def show_duration(duration): def show_ready(): __disable_colon(True) - display.show(ready) + display.show(rdy) return def show_extended(): __disable_colon(True) - display.show(extended) + display.show(pnic) return def show_update(): __disable_colon(True) - display.show(update) + display.show(updt) return def show_standby(): __disable_colon(True) - display.show(standby) + display.show(stby) return @@ -72,7 +72,7 @@ def show_stop(): def show_error(): __disable_colon(True) - display.show(error) + display.show(err) return @@ -117,11 +117,9 @@ def show_group(): def show_switch_group_duration(duration): duration = duration * lib.time_conversion global thread - global g_group global g_duration g_duration = duration - g_group = group - thread = threading.Thread(target=__switch_group_duration, args=(g_group, g_duration), name='switch display') + thread = threading.Thread(target=__switch_group_duration, args=g_duration, name='switch display') thread.start() @@ -167,7 +165,7 @@ def __switch_group_duration(duration): g_display = tm1637.TM1637(clk=clk_pin, dio=dio_pin, brightness=brightness) g_display.show_doublepoint(False) while duration > 0: - display.show(group) + g_display.show(grp) sleep(1) duration -= 1 g_display.show_remain_int(duration) From 8a6c24ae2e384949b5f47cd17dd227dfeace112c Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 22:33:32 +0100 Subject: [PATCH 16/19] [#31] grouping, 4 digit display fixed --- bot/peripherals/four_digit/display.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/peripherals/four_digit/display.py b/bot/peripherals/four_digit/display.py index 7e93f9a..e894f0b 100644 --- a/bot/peripherals/four_digit/display.py +++ b/bot/peripherals/four_digit/display.py @@ -110,7 +110,7 @@ def show_switch_channel_duration(channel, duration): def show_group(): __disable_colon(True) - display.show(group) + display.show(grp) return From 8ddd85a56d3988a53abb3f238068fd745b2324c3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 22:58:57 +0100 Subject: [PATCH 17/19] [#31] grouping, 4 digit display fixed --- bot/peripherals/four_digit/display.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/peripherals/four_digit/display.py b/bot/peripherals/four_digit/display.py index e894f0b..51665c2 100644 --- a/bot/peripherals/four_digit/display.py +++ b/bot/peripherals/four_digit/display.py @@ -119,7 +119,7 @@ def show_switch_group_duration(duration): global thread global g_duration g_duration = duration - thread = threading.Thread(target=__switch_group_duration, args=g_duration, name='switch display') + thread = threading.Thread(target=__switch_group_duration, args=(g_duration,), name='switch display') thread.start() From 4fb47b904834e182c26784c2396d196e2940805c Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 23:24:42 +0100 Subject: [PATCH 18/19] Grouping - InlineKeyboard changed , timeout updated --- bot/conf/greenhouse_config.py | 1 - bot/conf/lib_global.py | 2 +- bot/greenhouse.py | 14 +++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bot/conf/greenhouse_config.py b/bot/conf/greenhouse_config.py index fce1b4f..b874c11 100644 --- a/bot/conf/greenhouse_config.py +++ b/bot/conf/greenhouse_config.py @@ -32,7 +32,6 @@ # keyboard configs kb1 = [[lib.group1[1], lib.group1[2], lib.group1[3], lib.group3[1]], [lib.group3[2], lib.group2[1], lib.group2[2], lib.group2[3]], - # [lib.group1[0], lib.group3[0], lib.group2[0]], [lib.grouping], [lib.stop_bot, lib.live_stream, lib.reload] ] diff --git a/bot/conf/lib_global.py b/bot/conf/lib_global.py index b4956c5..4713dc1 100644 --- a/bot/conf/lib_global.py +++ b/bot/conf/lib_global.py @@ -14,7 +14,7 @@ """ timeout if no user activity """ -timeout = 600 +timeout = 60 """ language settings diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 7f6c64e..93886cf 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -433,11 +433,11 @@ def __group_menu(bot, update): selection = () logger.info('Grouping mode called.') inline_keyboard = [ - [__get_inline_btn(lib.group1[1], conf.RELAIS_01), __get_inline_btn(lib.group1[2], conf.RELAIS_02), - __get_inline_btn(lib.group1[3], conf.RELAIS_03), __get_inline_btn(lib.group3[1], conf.RELAIS_04)], - [__get_inline_btn(lib.group3[2], conf.RELAIS_05), __get_inline_btn(lib.group2[1], conf.RELAIS_06), - __get_inline_btn(lib.group2[2], conf.RELAIS_07), __get_inline_btn(lib.group2[3], conf.RELAIS_08)], - [__get_inline_btn(lib.btn_finished, lib.btn_finished), __get_inline_btn(lib.btn_cancel, lib.btn_cancel)] + [__get_btn(lib.group1[1], conf.RELAIS_01), __get_btn(lib.group1[2], conf.RELAIS_02), + __get_btn(lib.group1[3], conf.RELAIS_03), __get_btn(lib.group3[1], conf.RELAIS_04)], + [__get_btn(lib.group3[2], conf.RELAIS_05), __get_btn(lib.group2[1], conf.RELAIS_06), + __get_btn(lib.group2[2], conf.RELAIS_07), __get_btn(lib.group2[3], conf.RELAIS_08)], + [__get_btn(lib.btn_finished, lib.btn_finished), __get_btn(lib.btn_cancel, lib.btn_cancel)] ] global reply_markup @@ -446,8 +446,8 @@ def __group_menu(bot, update): return GROUPING -def __get_inline_btn(text, callback): - return InlineKeyboardButton(text, callback_data=callback) +def __get_btn(text, callback): + return InlineKeyboardButton('{0}({1})'.format(text, callback), callback_data=callback) # end: grouping From e64355fea0d02e5e976671cb246f3f0eea602682 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Mar 2019 23:34:00 +0100 Subject: [PATCH 19/19] grouping: InlineKeyboard changed , timeout updated II --- bot/conf/lib_global.py | 2 +- bot/greenhouse.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bot/conf/lib_global.py b/bot/conf/lib_global.py index 4713dc1..22a651c 100644 --- a/bot/conf/lib_global.py +++ b/bot/conf/lib_global.py @@ -14,7 +14,7 @@ """ timeout if no user activity """ -timeout = 60 +timeout = 120 """ language settings diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 93886cf..e821521 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -437,7 +437,8 @@ def __group_menu(bot, update): __get_btn(lib.group1[3], conf.RELAIS_03), __get_btn(lib.group3[1], conf.RELAIS_04)], [__get_btn(lib.group3[2], conf.RELAIS_05), __get_btn(lib.group2[1], conf.RELAIS_06), __get_btn(lib.group2[2], conf.RELAIS_07), __get_btn(lib.group2[3], conf.RELAIS_08)], - [__get_btn(lib.btn_finished, lib.btn_finished), __get_btn(lib.btn_cancel, lib.btn_cancel)] + [InlineKeyboardButton(lib.btn_finished, callback_data=lib.btn_finished), + InlineKeyboardButton(lib.btn_cancel, callback_data=lib.btn_cancel)] ] global reply_markup @@ -447,7 +448,7 @@ def __group_menu(bot, update): def __get_btn(text, callback): - return InlineKeyboardButton('{0}({1})'.format(text, callback), callback_data=callback) + return InlineKeyboardButton('{0} ({1})'.format(text, callback), callback_data=callback) # end: grouping