From 3e46b981516c02bad7a5ce532a703f60f1e16dc4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 19 Mar 2019 21:37:52 +0100 Subject: [PATCH 01/17] [fix][logging] typo removed --- bot/greenhouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index eb7ba7a..aa3e573 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -430,7 +430,7 @@ def __error(bot, update, e): __cam_off() utils.GPIO.cleanup() except Exception: - logging.warning('Any error occurs!') + logger.warning('Any error occurs!') return ConversationHandler.END From b72d7a25d60dfc437e055f52bed85f65b3e22db6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 21:09:56 +0100 Subject: [PATCH 02/17] code refactoring, global strings updated --- bot/conf/lib_english.py | 12 +++-- bot/conf/lib_german.py | 11 +++-- bot/greenhouse.py | 97 ++++++++++++++++++----------------------- 3 files changed, 59 insertions(+), 61 deletions(-) diff --git a/bot/conf/lib_english.py b/bot/conf/lib_english.py index 5d045e4..81d6c00 100644 --- a/bot/conf/lib_english.py +++ b/bot/conf/lib_english.py @@ -31,9 +31,15 @@ btn_finished = 'Finished' btn_cancel = cancel reload = 'Reload' -group1 = ('Channel 1 to 3', 'Channel 1', 'Channel 2', 'Channel 3') -group2 = ('Channel 6 to 8', 'Channel 6', 'Channel 7', 'Channel 8') -group3 = ('Channel 4 and 5', 'Channel 4', 'Channel 5') + +channel_1 = 'Channel 1' +channel_2 = 'Channel 2' +channel_3 = 'Channel 3' +channel_4 = 'Channel 4' +channel_5 = 'Channel 5' +channel_6 = 'Channel 6' +channel_7 = 'Channel 7' +channel_8 = 'Channel 8' temp = 'Temperature' hum = 'Humidity' diff --git a/bot/conf/lib_german.py b/bot/conf/lib_german.py index ef5df0d..8f5704b 100644 --- a/bot/conf/lib_german.py +++ b/bot/conf/lib_german.py @@ -33,9 +33,14 @@ btn_finished = 'Fertig' btn_cancel = cancel -group1 = ('Kanal 1 bis 3', 'Kanal 1', 'Kanal 2', 'Kanal 3') -group2 = ('Kanal 6 bis 8', 'Kanal 6', 'Kanal 7', 'Kanal 8') -group3 = ('Kanal 4 und 5', 'Kanal 4', 'Kanal 5') +channel_1 = 'Kanal 1' +channel_2 = 'Kanal 2' +channel_3 = 'Kanal 3' +channel_4 = 'Kanal 4' +channel_5 = 'Kanal 5' +channel_6 = 'Kanal 6' +channel_7 = 'Kanal 7' +channel_8 = 'Kanal 8' temp = 'Temperatur' hum = 'Luftfeuchtigkeit' diff --git a/bot/greenhouse.py b/bot/greenhouse.py index aa3e573..ebe62f6 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -34,10 +34,7 @@ lib = conf.lib # define pins -all_groups = conf.GROUP_ALL -group_one = conf.GROUP_01 -group_two = conf.GROUP_02 -group_three = conf.GROUP_03 + # api and bot settings SELECTION, DURATION, GROUPING = range(3) @@ -116,13 +113,12 @@ def __start(bot, update): def __selection(bot, update): global target target = update.message.text - __stop_standby_timer(bot, update) if target == str(lib.panic): + logger.info('Panic mode called.') update.message.reply_text(lib.msg_panic, parse_mode=ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) - logger.info(lib.msg_panic) os.system(conf.run_extended_greenhouse + str(user_id)) elif target == str(lib.live_stream): @@ -192,14 +188,15 @@ def __grouping(bot, update, chat_data): def __group_menu(bot, update): + __stop_standby_timer(bot, update) global selection selection = () logger.info('Grouping mode called.') inline_keyboard = [ - [__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.channel_1, conf.RELAIS_01), __get_btn(lib.channel_2, conf.RELAIS_02), + __get_btn(lib.channel_3, conf.RELAIS_03), __get_btn(lib.channel_4, conf.RELAIS_04)], + [__get_btn(lib.channel_5, conf.RELAIS_05), __get_btn(lib.channel_6, conf.RELAIS_06), + __get_btn(lib.channel_7, conf.RELAIS_07), __get_btn(lib.channel_8, conf.RELAIS_08)], [InlineKeyboardButton(lib.btn_finished, callback_data=lib.btn_finished), InlineKeyboardButton(lib.btn_cancel, callback_data=lib.btn_cancel)] ] @@ -207,6 +204,7 @@ 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 @@ -221,7 +219,6 @@ def __duration(bot, update): global g_duration_update g_duration_update = update water_time = update.message.text - __stop_standby_timer(bot, update) if water_time == str(lib.cancel): @@ -235,58 +232,40 @@ def __duration(bot, update): logger.info(lib.msg_panic) os.system(conf.run_extended_greenhouse + str(user_id)) - elif target == str(lib.group1[1]): - """ starts separate thread """ + elif target == str(lib.channel_1): display.show_switch_channel_duration(1, int(water_time)) + __water(bot, update, conf.RELAIS_01) - __water(bot, update, group_one[0]) - - elif target == str(lib.group1[2]): - """ starts separate thread """ + elif target == str(lib.channel_2): display.show_switch_channel_duration(2, int(water_time)) + __water(bot, update, conf.RELAIS_02) - __water(bot, update, group_one[1]) - - elif target == str(lib.group1[3]): - """ starts separate thread """ + elif target == str(lib.channel_3): display.show_switch_channel_duration(3, int(water_time)) + __water(bot, update, conf.RELAIS_03) - __water(bot, update, group_one[2]) + elif target == str(lib.channel_4): + display.show_switch_channel_duration(4, int(water_time)) + __water(bot, update, conf.RELAIS_04) - elif target == str(lib.group2[1]): - """ starts separate thread """ - display.show_switch_channel_duration(6, int(water_time)) + elif target == str(lib.channel_5): + display.show_switch_channel_duration(5, int(water_time)) + __water(bot, update, conf.RELAIS_05) - __water(bot, update, group_two[0]) + elif target == str(lib.channel_6): + display.show_switch_channel_duration(6, int(water_time)) + __water(bot, update, conf.RELAIS_06) - elif target == str(lib.group2[2]): - """ starts separate thread """ + elif target == str(lib.channel_7): display.show_switch_channel_duration(7, int(water_time)) + __water(bot, update, conf.RELAIS_07) - __water(bot, update, group_two[1]) - - elif target == str(lib.group2[3]): - """ starts separate thread """ + elif target == str(lib.channel_8): display.show_switch_channel_duration(8, int(water_time)) - - __water(bot, update, group_two[2]) - - elif target == str(lib.group3[1]): - """ starts separate thread """ - display.show_switch_channel_duration(4, int(water_time)) - - __water(bot, update, group_three[0]) - - elif target == str(lib.group3[2]): - """ starts separate thread """ - display.show_switch_channel_duration(5, int(water_time)) - - __water(bot, update, group_three[1]) + __water(bot, update, conf.RELAIS_08) elif target == str(lib.grouping): - """ starts separate thread """ display.show_switch_group_duration(int(water_time)) - __water_group(bot, update, selection) else: @@ -349,8 +328,8 @@ def __water_group(bot, update, group): # get humidity and temperature values def __message_values(update): - """ to avoid refresh intervals shorter than 3 seconds """ time.sleep(3) + """ avoid refresh intervals shorter than 3 seconds! """ dht.get_values() if dht.temperature == 0: temp = (lib.temp + lib.colon_space + '------') @@ -363,8 +342,7 @@ def __message_values(update): hum = (lib.hum + lib.colon_space + conf.hum_format).format(dht.humidity) core_temp = (lib.core + lib.colon_space + core.get_temperature()) - update.message.reply_text(lib.msg_temperature.format( - __start_time(), temp, hum, core_temp), parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __reply(update, lib.msg_temperature.format(__start_time(), temp, hum, core_temp), markup1) return @@ -375,7 +353,7 @@ def __stop(bot, update): logger.info('Bot stopped.') __cam_off() display.show_stop() - update.message.reply_text(lib.msg_stop, parse_mode=ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) + __reply(update, lib.msg_stop, ReplyKeyboardRemove()) time.sleep(2) display.show_standby() return ConversationHandler.END @@ -460,7 +438,16 @@ def __cam_off(): # release info def __message_release_info(bot, update): - update.message.reply_text('`' + utils.get_release_info() + '`', parse_mode=ParseMode.MARKDOWN) + __reply(update, '`' + utils.get_release_info() + '`') + return + + +# reply message +def __reply(update, text, markup=None): + if markup is None: + update.message.reply_text(text, parse_mode=ParseMode.MARKDOWN) + else: + update.message.reply_text(text, parse_mode=ParseMode.MARKDOWN, reply_markup=markup) return @@ -476,7 +463,7 @@ def main(): dp = updater.dispatcher - help_commandhandler = CommandHandler('help', __message_release_info) + help_handler = CommandHandler('help', __message_release_info) emergency_stop_handler = RegexHandler('^{0}$'.format(str(lib.emergency_stop)), __emergency_stop_handler, @@ -510,7 +497,7 @@ def main(): dp.add_handler(emergency_stop_handler) - dp.add_handler(help_commandhandler) + dp.add_handler(help_handler) dp.add_handler(ch) From 9aa9ab29b0b12d98a1020da1197f668668823f1a Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 21:50:43 +0100 Subject: [PATCH 03/17] code refactoring, unnecessary variables removed, typos fixed --- bot/conf/greenhouse_config.py | 27 +++++------- bot/ext_greenhouse.py | 19 +++----- bot/greenhouse.py | 81 +++++++++++++---------------------- 3 files changed, 45 insertions(+), 82 deletions(-) diff --git a/bot/conf/greenhouse_config.py b/bot/conf/greenhouse_config.py index 5fa7364..39906c0 100644 --- a/bot/conf/greenhouse_config.py +++ b/bot/conf/greenhouse_config.py @@ -31,8 +31,8 @@ # 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]], +kb1 = [[lib.channel_1, lib.channel_2, lib.channel_3, lib.channel_4], + [lib.channel_5, lib.channel_6, lib.channel_7, lib.channel_8], [lib.grouping], [lib.stop_bot, lib.live_stream, lib.reload] ] @@ -53,20 +53,15 @@ # Raspi core temperature core_temp_format = '{0}{1}{4}{2}{3}°C' -# def board pins/channels, refer hardware/raspi_gpio.info -RELAIS_01 = 29 -RELAIS_02 = 31 -RELAIS_03 = 33 -RELAIS_04 = 35 -RELAIS_05 = 37 -RELAIS_06 = 36 -RELAIS_07 = 38 -RELAIS_08 = 40 - -GROUP_ALL = (RELAIS_01, RELAIS_02, RELAIS_03, RELAIS_04, RELAIS_05, RELAIS_06, RELAIS_07, RELAIS_08) -GROUP_01 = (RELAIS_01, RELAIS_02, RELAIS_03) -GROUP_02 = (RELAIS_06, RELAIS_07, RELAIS_08) -GROUP_03 = (RELAIS_04, RELAIS_05) +# board pins of relays, refer hardware/raspi_gpio.info +RELAY_01 = 29 +RELAY_02 = 31 +RELAY_03 = 33 +RELAY_04 = 35 +RELAY_05 = 37 +RELAY_06 = 36 +RELAY_07 = 38 +RELAY_08 = 40 # live stream address live = access.live diff --git a/bot/ext_greenhouse.py b/bot/ext_greenhouse.py index 6b6da05..9694148 100644 --- a/bot/ext_greenhouse.py +++ b/bot/ext_greenhouse.py @@ -30,20 +30,11 @@ markdown = "-d parse_mode='Markdown'" no_parse_mode = conf.lib.empty -relais01 = conf.RELAIS_01 -relais02 = conf.RELAIS_02 -relais03 = conf.RELAIS_03 -relais04 = conf.RELAIS_04 -relais05 = conf.RELAIS_05 -relais06 = conf.RELAIS_06 -relais07 = conf.RELAIS_07 -relais08 = conf.RELAIS_08 - -group_all = (relais01, relais02, relais03, relais04, - relais05, relais06, relais07, relais08) -group_one = (relais01, relais02, relais03) -group_two = (relais06, relais07, relais08) -group_three = (relais04, relais05) +group_all = (conf.RELAY_01, conf.RELAY_02, conf.RELAY_03, conf.RELAY_04, + conf.RELAY_05, conf.RELAY_06, conf.RELAY_07, conf.RELAY_08) +group_one = (conf.RELAY_01, conf.RELAY_02, conf.RELAY_03) +group_two = (conf.RELAY_06, conf.RELAY_07, conf.RELAY_08) +group_three = (conf.RELAY_04, conf.RELAY_05) # water a group of targets diff --git a/bot/greenhouse.py b/bot/greenhouse.py index ebe62f6..91e8a11 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -30,15 +30,8 @@ thread = threading.Thread(target=monitor.main, name='main bot temperature monitoring') thread.start() -# used library lib = conf.lib - -# define pins - - -# api and bot settings SELECTION, DURATION, GROUPING = range(3) -# LIST_OF_ADMINS = ['mock to test'] list_of_admins = conf.admins token = conf.token target = lib.empty @@ -46,15 +39,11 @@ user_id = lib.empty jq = None timer_job = None - -# keyboard config +selection = () markup1 = ReplyKeyboardMarkup(conf.kb1, resize_keyboard=True, one_time_keyboard=True) markup2 = ReplyKeyboardMarkup(conf.kb2, resize_keyboard=True, one_time_keyboard=True) markup3 = ReplyKeyboardMarkup(conf.kb3, resize_keyboard=True, one_time_keyboard=True) -# for grouping -selection = () - # Start info def __init_bot_set_pins(): @@ -86,10 +75,9 @@ def __start(bot, update): if user_id not in list_of_admins: display.show_stop() - logger.info('Not allowed access by: {0} - {1},{2}'.format( + logger.warning('Not allowed access by: {0} - {1},{2}'.format( str(user_id), update.message.from_user.last_name, update.message.from_user.first_name)) - update.message.reply_text(lib.private_warning.format( - update.message.from_user.first_name, update.message.chat_id), parse_mode=ParseMode.MARKDOWN) + __reply(update, lib.private_warning.format(update.message.from_user.first_name, update.message.chat_id)) return ConversationHandler.END else: display.show_run() @@ -97,9 +85,10 @@ def __start(bot, update): __message_values(update) __cam_on() display.show_ready() - update.message.reply_text('{0}{1}{2}'.format( - lib.msg_welcome.format(update.message.from_user.first_name), lib.space, lib.msg_choice), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __reply( + update, + '{0}{1}{2}'.format(lib.msg_welcome.format(update.message.from_user.first_name), lib.space, lib.msg_choice), + markup1) logger.info('Bot is using by: {0} - {1},{2}'.format( str(user_id), update.message.from_user.last_name, update.message.from_user.first_name)) logger.info('Time unit is \'{0}\''.format(str(lib.time_units_name[lib.time_units_index]))) @@ -117,14 +106,12 @@ def __selection(bot, update): if target == str(lib.panic): logger.info('Panic mode called.') - update.message.reply_text(lib.msg_panic, - parse_mode=ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) + __reply(update, lib.msg_panic, ReplyKeyboardRemove()) os.system(conf.run_extended_greenhouse + str(user_id)) elif target == str(lib.live_stream): logger.info('Live URL requested.') - update.message.reply_text(lib.msg_live.format(str(conf.live)), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __reply(update, lib.msg_live.format(str(conf.live)), markup1) __start_standby_timer(bot, update) return SELECTION @@ -139,8 +126,7 @@ def __selection(bot, update): def __selected_target(bot, update, selected_target): - update.message.reply_text(lib.msg_duration.format(selected_target), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) + __reply(update, lib.msg_duration.format(selected_target), markup2) logger.info('Selection: {0}'.format(str(selected_target))) __start_standby_timer(bot, update) return DURATION @@ -203,7 +189,7 @@ 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) + __reply(update, lib.msg_grouping, reply_markup) __start_standby_timer(bot, update) return GROUPING @@ -222,54 +208,52 @@ def __duration(bot, update): __stop_standby_timer(bot, update) if water_time == str(lib.cancel): - update.message.reply_text(lib.msg_new_choice, - parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __reply(update, lib.msg_new_choice, markup1) logger.info(lib.msg_new_choice) elif water_time == str(lib.panic): - update.message.reply_text(lib.msg_panic, - parse_mode=ParseMode.MARKDOWN, reply_markup=ReplyKeyboardRemove()) + __reply(update, lib.msg_panic, ReplyKeyboardRemove()) logger.info(lib.msg_panic) os.system(conf.run_extended_greenhouse + str(user_id)) elif target == str(lib.channel_1): display.show_switch_channel_duration(1, int(water_time)) - __water(bot, update, conf.RELAIS_01) + __water(bot, update, conf.RELAY_01) elif target == str(lib.channel_2): display.show_switch_channel_duration(2, int(water_time)) - __water(bot, update, conf.RELAIS_02) + __water(bot, update, conf.RELAY_02) elif target == str(lib.channel_3): display.show_switch_channel_duration(3, int(water_time)) - __water(bot, update, conf.RELAIS_03) + __water(bot, update, conf.RELAY_03) elif target == str(lib.channel_4): display.show_switch_channel_duration(4, int(water_time)) - __water(bot, update, conf.RELAIS_04) + __water(bot, update, conf.RELAY_04) elif target == str(lib.channel_5): display.show_switch_channel_duration(5, int(water_time)) - __water(bot, update, conf.RELAIS_05) + __water(bot, update, conf.RELAY_05) elif target == str(lib.channel_6): display.show_switch_channel_duration(6, int(water_time)) - __water(bot, update, conf.RELAIS_06) + __water(bot, update, conf.RELAY_06) elif target == str(lib.channel_7): display.show_switch_channel_duration(7, int(water_time)) - __water(bot, update, conf.RELAIS_07) + __water(bot, update, conf.RELAY_07) elif target == str(lib.channel_8): display.show_switch_channel_duration(8, int(water_time)) - __water(bot, update, conf.RELAIS_08) + __water(bot, update, conf.RELAY_08) elif target == str(lib.grouping): display.show_switch_group_duration(int(water_time)) __water_group(bot, update, selection) else: - update.message.reply_text(lib.msg_choice, reply_markup=markup1) + __reply(update, lib.msg_choice, markup1) __start_standby_timer(bot, update) return SELECTION @@ -289,16 +273,12 @@ def __water(bot, update, channel): logger.info('Duration: {0}'.format(water_time)) logger.info('Toggle {0}'.format(str(channel))) __stop_standby_timer(bot, update) - update.message.reply_text(lib.water_on.format(target, water_time), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup3) - + __reply(update, lib.water_on.format(target, water_time), markup3) utils.switch_on(channel) time.sleep(int(water_time) * int(lib.time_conversion)) utils.switch_off(channel) - - update.message.reply_text('{0}{1}{2}'.format( - __timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __reply(update, + '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() __start_standby_timer(bot, update) return @@ -309,17 +289,14 @@ 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.format(target, water_time), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup3) - + __reply(update, lib.water_on.format(target, water_time), markup3) for channel in group: utils.switch_on(channel) time.sleep((int(water_time) * int(lib.time_conversion))) for channel in group: utils.switch_off(channel) - update.message.reply_text('{0}{1}{2}'.format( - __timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), - parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __reply(update, + '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() __start_standby_timer(bot, update) return @@ -373,7 +350,7 @@ 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.info("Initialize emergency stop immediately.") + logger.warning("Initialize emergency stop immediately.") return # end: emergency stop From 9846895257d7344998ecaa976e36d577c08c9af6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 22:06:40 +0100 Subject: [PATCH 04/17] [fix] all_off fixed --- bot/conf/greenhouse_config.py | 2 ++ bot/greenhouse.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/conf/greenhouse_config.py b/bot/conf/greenhouse_config.py index 39906c0..11c9186 100644 --- a/bot/conf/greenhouse_config.py +++ b/bot/conf/greenhouse_config.py @@ -63,6 +63,8 @@ RELAY_07 = 38 RELAY_08 = 40 +ALL = (RELAY_01, RELAY_02, RELAY_03, RELAY_04, RELAY_05, RELAY_06, RELAY_07, RELAY_08) + # live stream address live = access.live diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 91e8a11..16a1370 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -263,8 +263,8 @@ def __duration(bot, update): # watering targets def __all_off(): logger.info('Switch all off.') - for channel in all_groups: - utils.switch_off(channel) + for relay in conf.ALL: + utils.switch_off(relay) return From 2084c04815880c8e21dc056a73b985b5acd8e96c Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 22:18:44 +0100 Subject: [PATCH 05/17] [fix] ConversationHandler states fixed --- bot/greenhouse.py | 5 ++--- bot/utils/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 16a1370..14314e9 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -449,9 +449,8 @@ def main(): 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.channel_1), str(lib.channel_2), str(lib.channel_3), str(lib.channel_4), + str(lib.channel_5), str(lib.channel_6), str(lib.channel_7), str(lib.channel_8), str(lib.panic), str(lib.live_stream), str(lib.reload)), __selection), diff --git a/bot/utils/utils.py b/bot/utils/utils.py index 3ee034d..bee3542 100644 --- a/bot/utils/utils.py +++ b/bot/utils/utils.py @@ -19,7 +19,7 @@ # switch functions def switch_on(pin): - logger.info('switch relais on: ' + str(pin)) + logger.info('switch relay on: ' + str(pin)) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.LOW) # os.system(run_gpio_check + str(pin)) @@ -27,7 +27,7 @@ def switch_on(pin): def switch_off(pin): - logger.info('switch relais off: ' + str(pin)) + logger.info('switch relay off: ' + str(pin)) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH) # os.system(run_gpio_check + str(pin)) From 8da64ba21ee909ed345256102dd757ba324e2f2a Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 22:27:12 +0100 Subject: [PATCH 06/17] [fix] grouping typos fixed --- bot/greenhouse.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 14314e9..e2868b3 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -179,10 +179,10 @@ def __group_menu(bot, update): selection = () logger.info('Grouping mode called.') inline_keyboard = [ - [__get_btn(lib.channel_1, conf.RELAIS_01), __get_btn(lib.channel_2, conf.RELAIS_02), - __get_btn(lib.channel_3, conf.RELAIS_03), __get_btn(lib.channel_4, conf.RELAIS_04)], - [__get_btn(lib.channel_5, conf.RELAIS_05), __get_btn(lib.channel_6, conf.RELAIS_06), - __get_btn(lib.channel_7, conf.RELAIS_07), __get_btn(lib.channel_8, conf.RELAIS_08)], + [__get_btn(lib.channel_1, conf.RELAY_01), __get_btn(lib.channel_2, conf.RELAY_02), + __get_btn(lib.channel_3, conf.RELAY_03), __get_btn(lib.channel_4, conf.RELAY_04)], + [__get_btn(lib.channel_5, conf.RELAY_05), __get_btn(lib.channel_6, conf.RELAY_06), + __get_btn(lib.channel_7, conf.RELAY_07), __get_btn(lib.channel_8, conf.RELAY_08)], [InlineKeyboardButton(lib.btn_finished, callback_data=lib.btn_finished), InlineKeyboardButton(lib.btn_cancel, callback_data=lib.btn_cancel)] ] From 13abd6413b9ca862e3bd491cbcbde4b76a6a3bcd Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 22:39:03 +0100 Subject: [PATCH 07/17] [standby] try to avoid doubled calls --- bot/greenhouse.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index e2868b3..dc19e26 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -270,9 +270,9 @@ def __all_off(): @run_async def __water(bot, update, channel): + #__stop_standby_timer(bot, update) logger.info('Duration: {0}'.format(water_time)) logger.info('Toggle {0}'.format(str(channel))) - __stop_standby_timer(bot, update) __reply(update, lib.water_on.format(target, water_time), markup3) utils.switch_on(channel) time.sleep(int(water_time) * int(lib.time_conversion)) @@ -280,15 +280,15 @@ def __water(bot, update, channel): __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() - __start_standby_timer(bot, update) + #__start_standby_timer(bot, update) return @run_async def __water_group(bot, update, group): + #__stop_standby_timer(bot, update) logger.info('Duration: {0}'.format(water_time)) logger.info('Toggle {0}'.format(str(group))) - __stop_standby_timer(bot, update) __reply(update, lib.water_on.format(target, water_time), markup3) for channel in group: utils.switch_on(channel) @@ -298,7 +298,7 @@ def __water_group(bot, update, group): __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() - __start_standby_timer(bot, update) + #__start_standby_timer(bot, update) return # end watering targets From eea7921180b9db225f7221326a1ff47808b62f46 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 23:30:44 +0100 Subject: [PATCH 08/17] [logging] minor changes/improvements --- bot/ext_greenhouse.py | 2 +- bot/greenhouse.py | 45 ++++++++++++++++++-------------------- bot/peripherals/dht/dht.py | 6 ++--- bot/peripherals/monitor.py | 9 +++----- bot/utils/utils.py | 6 ++--- 5 files changed, 30 insertions(+), 38 deletions(-) diff --git a/bot/ext_greenhouse.py b/bot/ext_greenhouse.py index 9694148..173cbd4 100644 --- a/bot/ext_greenhouse.py +++ b/bot/ext_greenhouse.py @@ -22,7 +22,7 @@ import peripherals.monitor as monitor logging = log.get_logger() -thread = threading.Thread(target=monitor.main, name='ext bot temperature monitoring') +thread = threading.Thread(target=monitor.main, name='ExtendedBot temperature monitoring') thread.start() pins_state = False diff --git a/bot/greenhouse.py b/bot/greenhouse.py index dc19e26..c7461cc 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -27,7 +27,7 @@ from telegram.ext.dispatcher import run_async logger = logger.get_logger() -thread = threading.Thread(target=monitor.main, name='main bot temperature monitoring') +thread = threading.Thread(target=monitor.main, name='MainBot temperature monitoring') thread.start() lib = conf.lib @@ -47,9 +47,8 @@ # Start info def __init_bot_set_pins(): - logger.info('Initialize bot, setup GPIO pins.') + logger.info('Initializing...') utils.set_pins() - logger.info('Switch all off at start.') __all_off() display.show_standby() return @@ -81,7 +80,7 @@ def __start(bot, update): return ConversationHandler.END else: display.show_run() - logger.info('Bot started...') + logger.info('Started...') __message_values(update) __cam_on() display.show_ready() @@ -89,9 +88,8 @@ def __start(bot, update): update, '{0}{1}{2}'.format(lib.msg_welcome.format(update.message.from_user.first_name), lib.space, lib.msg_choice), markup1) - logger.info('Bot is using by: {0} - {1},{2}'.format( + logger.info('Bot usage: {0} - {1},{2}'.format( str(user_id), update.message.from_user.last_name, update.message.from_user.first_name)) - logger.info('Time unit is \'{0}\''.format(str(lib.time_units_name[lib.time_units_index]))) display.show_off() __start_standby_timer(bot, update) @@ -177,7 +175,7 @@ def __group_menu(bot, update): __stop_standby_timer(bot, update) global selection selection = () - logger.info('Grouping mode called.') + logger.info('Grouping called.') inline_keyboard = [ [__get_btn(lib.channel_1, conf.RELAY_01), __get_btn(lib.channel_2, conf.RELAY_02), __get_btn(lib.channel_3, conf.RELAY_03), __get_btn(lib.channel_4, conf.RELAY_04)], @@ -262,43 +260,41 @@ def __duration(bot, update): # watering targets def __all_off(): - logger.info('Switch all off.') + logger.info('All off.') for relay in conf.ALL: - utils.switch_off(relay) + utils.switch_out_high(relay) return @run_async def __water(bot, update, channel): - #__stop_standby_timer(bot, update) - logger.info('Duration: {0}'.format(water_time)) - logger.info('Toggle {0}'.format(str(channel))) + __stop_standby_timer(bot, update) + logger.info('Toggle {0} , Duration {1}'.format(str(channel), str(water_time))) __reply(update, lib.water_on.format(target, water_time), markup3) - utils.switch_on(channel) + utils.switch_out_low(channel) time.sleep(int(water_time) * int(lib.time_conversion)) - utils.switch_off(channel) + utils.switch_out_high(channel) __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() - #__start_standby_timer(bot, update) + __start_standby_timer(bot, update) return @run_async def __water_group(bot, update, group): - #__stop_standby_timer(bot, update) - logger.info('Duration: {0}'.format(water_time)) - logger.info('Toggle {0}'.format(str(group))) + __stop_standby_timer(bot, update) + logger.info('Toggle {0} , Duration {1}'.format(str(group), str(water_time))) __reply(update, lib.water_on.format(target, water_time), markup3) for channel in group: - utils.switch_on(channel) + utils.switch_out_low(channel) time.sleep((int(water_time) * int(lib.time_conversion))) for channel in group: - utils.switch_off(channel) + utils.switch_out_high(channel) __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() - #__start_standby_timer(bot, update) + __start_standby_timer(bot, update) return # end watering targets @@ -327,7 +323,7 @@ def __message_values(update): def __stop(bot, update): __all_off() __stop_standby_timer(bot, update) - logger.info('Bot stopped.') + logger.info('Stopped.') __cam_off() display.show_stop() __reply(update, lib.msg_stop, ReplyKeyboardRemove()) @@ -348,18 +344,18 @@ def __emergency_stop_handler(bot, update, chat_data): def __start_emergency_stop(bot, update): + logger.warning("Initialize emergency stop immediately.") global emergency_job emergency_job = jq.run_once(__job_stop_and_restart, 0, context=update) - logger.warning("Initialize emergency stop immediately.") return # end: emergency stop # [#30] implement standby init after given time without user activity def __start_standby_timer(bot, update): + logger.info("Init standby timer of {0} seconds, added to queue.".format(conf.standby_timeout)) global timer_job timer_job = jq.run_once(__job_stop_and_restart, conf.standby_timeout, context=update) - logger.info("Init standby timer of {0} seconds, added to queue.".format(conf.standby_timeout)) return @@ -383,6 +379,7 @@ def __error(bot, update, e): try: display.show_error() __cam_off() + __all_off() utils.GPIO.cleanup() except Exception: logger.warning('Any error occurs!') diff --git a/bot/peripherals/dht/dht.py b/bot/peripherals/dht/dht.py index 3be886c..06eccbd 100644 --- a/bot/peripherals/dht/dht.py +++ b/bot/peripherals/dht/dht.py @@ -20,13 +20,11 @@ def get_values(): global temperature global humidity - logging.info('Try to get temperature and humidity values.') + logging.info('Get temperature and humidity values.') humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) if humidity is not None and temperature is not None: - logging.info(('{0}{1}{2}{3}{4}{1}{5}'.format( - lib.temp, lib.colon_space, conf.temp_format, lib.space, lib.hum, conf.hum_format)) - .format(temperature, humidity)) + logging.info(('{0}{1}{2}'.format(conf.temp_format, lib.space, conf.hum_format)).format(temperature, humidity)) else: logging.warning('Failed to get temperature and humidity values. Set to \'0\'!') humidity = 0 diff --git a/bot/peripherals/monitor.py b/bot/peripherals/monitor.py index 215ad77..29c8389 100644 --- a/bot/peripherals/monitor.py +++ b/bot/peripherals/monitor.py @@ -14,7 +14,7 @@ logger = logger.get_logger() -message = 'Warning, you Greenhouse Raspi reaches a temperature over {}°C! Current temperature is about {}°C!' +message = 'Warning, your RaspberryPi reaches a temperature over {}°C! Current temperature is about {}°C!' def __calc_core_temp(): @@ -35,13 +35,10 @@ def __send_msg(msg, bot, chat): def __fan_control(temp): if temp >= temperature_max and int(utils.get_pin_state(fan_pin)) == 0: - logger.warning('Current core temperature: {}°C'.format(str(temp))) + logger.warning('Current core temperature: {0}°C {1}'.format(str(temp), "Heat dissipation: Fan on")) utils.switch_out_high(fan_pin) - logger.warning("Heat dissipation: Fan switched on") if temp <= temperature_min and int(utils.get_pin_state(fan_pin)) == 1: - logger.info('Core temperature: {}°C'.format(str(temp))) - utils.switch_out_low(fan_pin) - logger.info("Heat dissipation: Fan switched off") + logger.info('Core temperature: {0}°C {1}'.format(str(temp), "Heat dissipation: Fan off")) return diff --git a/bot/utils/utils.py b/bot/utils/utils.py index bee3542..d8eba99 100644 --- a/bot/utils/utils.py +++ b/bot/utils/utils.py @@ -19,7 +19,7 @@ # switch functions def switch_on(pin): - logger.info('switch relay on: ' + str(pin)) + logger.info('switch on: ' + str(pin)) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.LOW) # os.system(run_gpio_check + str(pin)) @@ -27,7 +27,7 @@ def switch_on(pin): def switch_off(pin): - logger.info('switch relay off: ' + str(pin)) + logger.info('switch off: ' + str(pin)) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH) # os.system(run_gpio_check + str(pin)) @@ -68,7 +68,7 @@ def get_pin_state(pin): def set_pins(): GPIO.setmode(GPIO.BOARD) logger.info('Set GPIO mode: GPIO.BOARD') - # to use GPIO instead board pin numbers, then please adapt pin definition + """ to use GPIO instead board pin numbers, then please adapt pin definition """ # GPIO.setmode(GPIO.BCM) # comment if warnings required GPIO.setwarnings(False) From da2aa7970e86eb01492e27dca0ebcd5b68e3fff7 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 20 Mar 2019 23:49:57 +0100 Subject: [PATCH 09/17] [standby] minor changes/improvements --- bot/greenhouse.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index c7461cc..f7b7308 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -133,6 +133,7 @@ def __selected_target(bot, update, selected_target): # [#31] grouping def __grouping(bot, update, chat_data): + __stop_standby_timer(bot, update) global selection query = update.callback_query btn_click = str(query.data) @@ -158,6 +159,7 @@ def __grouping(bot, update, chat_data): parse_mode=ParseMode.MARKDOWN, reply_markup=markup2) logger.info('Selected: {0} {1}'.format(str(target), str(selection))) + __start_standby_timer(bot, update) return DURATION elif btn_click == lib.cancel: @@ -168,14 +170,13 @@ def __grouping(bot, update, chat_data): chat_id=query.message.chat_id, parse_mode=ParseMode.MARKDOWN, reply_markup=markup1) + __start_standby_timer(bot, update) return SELECTION def __group_menu(bot, update): - __stop_standby_timer(bot, update) global selection selection = () - logger.info('Grouping called.') inline_keyboard = [ [__get_btn(lib.channel_1, conf.RELAY_01), __get_btn(lib.channel_2, conf.RELAY_02), __get_btn(lib.channel_3, conf.RELAY_03), __get_btn(lib.channel_4, conf.RELAY_04)], @@ -188,7 +189,7 @@ def __group_menu(bot, update): global reply_markup reply_markup = InlineKeyboardMarkup(inline_keyboard) __reply(update, lib.msg_grouping, reply_markup) - __start_standby_timer(bot, update) + logger.info('Grouping called.') return GROUPING @@ -252,8 +253,8 @@ def __duration(bot, update): else: __reply(update, lib.msg_choice, markup1) + __start_standby_timer(bot, update) - __start_standby_timer(bot, update) return SELECTION # end: duration From 229bacf900aebd83977e6e80d1762c54763ba5f9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 21 Mar 2019 00:00:19 +0100 Subject: [PATCH 10/17] [standby] minor changes/improvements II --- bot/greenhouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index f7b7308..55e2fc8 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -133,7 +133,6 @@ def __selected_target(bot, update, selected_target): # [#31] grouping def __grouping(bot, update, chat_data): - __stop_standby_timer(bot, update) global selection query = update.callback_query btn_click = str(query.data) @@ -190,6 +189,7 @@ def __group_menu(bot, update): reply_markup = InlineKeyboardMarkup(inline_keyboard) __reply(update, lib.msg_grouping, reply_markup) logger.info('Grouping called.') + __stop_standby_timer(bot, update) return GROUPING From 87ddf9070c1154bafaa921c381f6f043367eec86 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 21 Mar 2019 00:12:20 +0100 Subject: [PATCH 11/17] [standby] improvements III --- bot/greenhouse.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 55e2fc8..a034de6 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -189,7 +189,6 @@ def __group_menu(bot, update): reply_markup = InlineKeyboardMarkup(inline_keyboard) __reply(update, lib.msg_grouping, reply_markup) logger.info('Grouping called.') - __stop_standby_timer(bot, update) return GROUPING @@ -253,8 +252,8 @@ def __duration(bot, update): else: __reply(update, lib.msg_choice, markup1) - __start_standby_timer(bot, update) + __start_standby_timer(bot, update) return SELECTION # end: duration @@ -269,7 +268,6 @@ def __all_off(): @run_async def __water(bot, update, channel): - __stop_standby_timer(bot, update) logger.info('Toggle {0} , Duration {1}'.format(str(channel), str(water_time))) __reply(update, lib.water_on.format(target, water_time), markup3) utils.switch_out_low(channel) @@ -278,13 +276,11 @@ def __water(bot, update, channel): __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() - __start_standby_timer(bot, update) return @run_async def __water_group(bot, update, group): - __stop_standby_timer(bot, update) logger.info('Toggle {0} , Duration {1}'.format(str(group), str(water_time))) __reply(update, lib.water_on.format(target, water_time), markup3) for channel in group: @@ -295,7 +291,6 @@ def __water_group(bot, update, group): __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() - __start_standby_timer(bot, update) return # end watering targets From 607cb39011789f432334baffe0d67e4e96ec5e6f Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 21 Mar 2019 13:46:57 +0100 Subject: [PATCH 12/17] [standby] job calls changed --- bot/greenhouse.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index a034de6..a1f9386 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -189,6 +189,7 @@ def __group_menu(bot, update): reply_markup = InlineKeyboardMarkup(inline_keyboard) __reply(update, lib.msg_grouping, reply_markup) logger.info('Grouping called.') + __stop_standby_timer(bot, update) return GROUPING @@ -464,16 +465,12 @@ def main(): per_user=True ) + dp.add_error_handler(__error) dp.add_handler(emergency_stop_handler) - dp.add_handler(help_handler) - dp.add_handler(ch) - dp.add_error_handler(__error) - updater.start_polling() - updater.idle() From 309beeb77c87d36497e6f21500b91d341d2ae981 Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 21 Mar 2019 14:09:12 +0100 Subject: [PATCH 13/17] [standby] job calls changed II --- bot/greenhouse.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index a1f9386..4d860d0 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -189,7 +189,7 @@ def __group_menu(bot, update): reply_markup = InlineKeyboardMarkup(inline_keyboard) __reply(update, lib.msg_grouping, reply_markup) logger.info('Grouping called.') - __stop_standby_timer(bot, update) + __start_standby_timer(bot, update) return GROUPING @@ -269,6 +269,7 @@ def __all_off(): @run_async def __water(bot, update, channel): + __stop_standby_timer(bot, update) logger.info('Toggle {0} , Duration {1}'.format(str(channel), str(water_time))) __reply(update, lib.water_on.format(target, water_time), markup3) utils.switch_out_low(channel) @@ -282,6 +283,7 @@ def __water(bot, update, channel): @run_async def __water_group(bot, update, group): + __stop_standby_timer(bot, update) logger.info('Toggle {0} , Duration {1}'.format(str(group), str(water_time))) __reply(update, lib.water_on.format(target, water_time), markup3) for channel in group: From 6f1630e00abe674c8e3066b9063f4287a30a5b01 Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 21 Mar 2019 14:19:34 +0100 Subject: [PATCH 14/17] [standby] job calls changed III --- bot/greenhouse.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 4d860d0..05b6bcb 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -278,6 +278,7 @@ def __water(bot, update, channel): __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() + __start_standby_timer(bot, update) return @@ -294,6 +295,7 @@ def __water_group(bot, update, group): __reply(update, '{0}{1}{2}'.format(__timestamp(), lib.water_off.format(target, water_time), lib.msg_new_choice), markup1) display.show_off() + __start_standby_timer(bot, update) return # end watering targets From 9184fa4bd777c5fe69c259c16585086876035ed4 Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 21 Mar 2019 14:32:11 +0100 Subject: [PATCH 15/17] [standby] job calls changed IV --- bot/greenhouse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 05b6bcb..61ef06f 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -147,6 +147,7 @@ def __grouping(bot, update, chat_data): reply_markup=reply_markup) elif btn_click == str(lib.btn_finished) and len(selection) > 0: + __stop_standby_timer(bot, update) global target target = lib.grouping bot.edit_message_text(text=lib.msg_grouping_selection.format(selection), @@ -162,6 +163,7 @@ def __grouping(bot, update, chat_data): return DURATION elif btn_click == lib.cancel: + __stop_standby_timer(bot, update) selection = () bot.delete_message(chat_id=query.message.chat_id, message_id=query.message.message_id) @@ -204,7 +206,6 @@ def __duration(bot, update): global g_duration_update g_duration_update = update water_time = update.message.text - __stop_standby_timer(bot, update) if water_time == str(lib.cancel): __reply(update, lib.msg_new_choice, markup1) @@ -254,7 +255,6 @@ def __duration(bot, update): else: __reply(update, lib.msg_choice, markup1) - __start_standby_timer(bot, update) return SELECTION # end: duration From 2b2ec2137f3083e09c9df4bd1b224e5e392e6f57 Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 21 Mar 2019 14:47:36 +0100 Subject: [PATCH 16/17] [standby] job calls changed V --- bot/greenhouse.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 61ef06f..3b41bac 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -138,6 +138,7 @@ def __grouping(bot, update, chat_data): btn_click = str(query.data) if not (btn_click == str(lib.btn_finished) or btn_click == str(lib.cancel)): + __stop_standby_timer(bot, update) if not selection.__contains__(int(btn_click)): selection += (int(btn_click),) bot.edit_message_text(text=lib.msg_grouping_selection.format(selection), @@ -145,6 +146,7 @@ def __grouping(bot, update, chat_data): message_id=query.message.message_id, parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup) + __start_standby_timer(bot, update) elif btn_click == str(lib.btn_finished) and len(selection) > 0: __stop_standby_timer(bot, update) @@ -191,7 +193,6 @@ def __group_menu(bot, update): reply_markup = InlineKeyboardMarkup(inline_keyboard) __reply(update, lib.msg_grouping, reply_markup) logger.info('Grouping called.') - __start_standby_timer(bot, update) return GROUPING From 96b396312bfdfa7a5f55c190667bbfbb5ea26cc2 Mon Sep 17 00:00:00 2001 From: Thomas Kaulke Date: Thu, 21 Mar 2019 15:03:16 +0100 Subject: [PATCH 17/17] [standby] job calls improved --- bot/greenhouse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/greenhouse.py b/bot/greenhouse.py index 3b41bac..4df225d 100644 --- a/bot/greenhouse.py +++ b/bot/greenhouse.py @@ -138,8 +138,8 @@ def __grouping(bot, update, chat_data): btn_click = str(query.data) if not (btn_click == str(lib.btn_finished) or btn_click == str(lib.cancel)): - __stop_standby_timer(bot, update) if not selection.__contains__(int(btn_click)): + __stop_standby_timer(bot, update) selection += (int(btn_click),) bot.edit_message_text(text=lib.msg_grouping_selection.format(selection), chat_id=query.message.chat_id,