Ejemplo n.º 1
0
def help(update, context):
    name = update.message.chat.first_name
    if sql.check_username(update.message.chat.username):

        update.message.reply_text(
            'Hi' + name + ',\n\n'
            'This is SafeHouse Bot.\n\n'
            'I will send you notifications in case something happen in your House.'
        )
    else:
        update.message.reply_text('Hi ' + name + NOT_AUTHORISED)
        return VALVE
Ejemplo n.º 2
0
def cancel(update, context):
    if sql.check_username(update.message.chat.username):
        if valve_state:
            reply_keyboard = [['Close Valve', 'Sensors State']]
            update.message.reply_text(
                'Cancelled', reply_markup=ReplyKeyboardMarkup(reply_keyboard))
        else:
            reply_keyboard = [['Open Valve', 'Sensors State']]
            update.message.reply_text(
                'Cancelled', reply_markup=ReplyKeyboardMarkup(reply_keyboard))
        return VALVE
    else:
        update.message.reply_text('Hi ' + update.message.chat.first_name +
                                  NOT_AUTHORISED)
        return VALVE
Ejemplo n.º 3
0
def start(update, context):
    username = update.message.chat.username
    user_name = update.message.chat.first_name
    chat_id = update.message.chat.id
    if sql.check_username(username):
        sql.insert_chat_id(chat_id, username)
        reply_keyboard = [['Close Valve', 'Sensors State']]
        update.message.reply_text(
            'Hi ' + user_name + ',\n\n'
            'This is SafeHouse Bot.\n\n'
            'I will send you notifications in case something happens in your House.',
            reply_markup=ReplyKeyboardMarkup(reply_keyboard))

        return VALVE
    else:
        update.message.reply_text('Hi ' + user_name + NOT_AUTHORISED)
        return VALVE
Ejemplo n.º 4
0
def valve_ver(update, context):
    if sql.check_username(update.message.chat.username):
        if valve_state:
            reply_keyboard = [['Yes', 'Cancel']]
            update.message.reply_text(
                'Do you really want to close valve?',
                reply_markup=ReplyKeyboardMarkup(reply_keyboard))
        else:
            reply_keyboard = [['Yes', 'Cancel']]
            update.message.reply_text(
                'Do you really want to open valve?',
                reply_markup=ReplyKeyboardMarkup(reply_keyboard))

        return VALVE
    else:
        update.message.reply_text('Hi ' + update.message.chat.first_name +
                                  NOT_AUTHORISED)
        return VALVE
Ejemplo n.º 5
0
def sensors_state(update, context):
    username = update.message.chat.username
    if sql.check_username(username):
        sensors = sql.sensors_state(username)
        text = ""
        for sensor in sensors:
            print(1222)
            text += str(sensor[1]) + ". \n\n Last update: " + str(
                sensor[3]) + "\n\n Value: " + str(sensor[4]) + "\n\n \n\n"
        update.message.reply_text(
            text

            # 'Kitchen: Good, Last seen: 2 min ago \n\n Bathroom: Good, Last seen: 3 min ago'
        )
        return VALVE
    else:
        update.message.reply_text('Hi ' + update.message.chat.first_name +
                                  NOT_AUTHORISED)
        return VALVE
Ejemplo n.º 6
0
def rotate_valve(update, context):
    if sql.check_username(update.message.chat.username):
        global valve_state
        if valve_state:
            valve_state = False
            reply_keyboard = [['Open Valve', 'Sensors State']]
            update.message.reply_text(
                'Valve was closed',
                reply_markup=ReplyKeyboardMarkup(reply_keyboard))
        else:
            valve_state = True
            reply_keyboard = [['Close Valve', 'Sensors State']]
            update.message.reply_text(
                'Valve was opened',
                reply_markup=ReplyKeyboardMarkup(reply_keyboard))

        return VALVE
    else:
        update.message.reply_text('Hi ' + update.message.chat.first_name +
                                  NOT_AUTHORISED)
        return VALVE