Example #1
0
def display_choose_keyboard(bot, chat_id):
    keyboard = [[
        InlineKeyboardButton(plant.name, callback_data=plant.id)
        for plant in Plants.all()
    ]]
    bot.send_message(text=_('Please choose:'),
                     reply_markup=(InlineKeyboardMarkup(keyboard)),
                     chat_id=chat_id)
Example #2
0
def plants_response(bot, update):
    plants = Plants.all()
    text = "```\n" + \
           "| {0:^15} | {1:^5} |\n".format(_("Plant"), "%") + \
           "|{0:-<17}|{0:-<7}|\n".format('') + \
           '\n'.join(['| {0:15.15} | {1:4.0f}% |'.format(plant.name, plant.get_humidity()) for plant in plants]) + \
           '```'
    update.message.reply_markdown(text)
Example #3
0
def selected_plant(bot, update):
    query = update.callback_query
    plant = Plants.get_plant_by_id(query.data)
    bot.edit_message_text(text=plant.get_humidity_display_text(),
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id)

    display_choose_keyboard(bot, query.message.chat_id)
Example #4
0
def test_get_plant_by_id(monkeypatch):
    expected_plant = Plant(name='Minze', port=10)
    monkeypatch.setattr(
        Plants, "plants",
        [expected_plant, Plant(name='Chili', port=9)])

    plant = Plants.get_plant_by_id(10)

    assert plant == expected_plant
Example #5
0
def test_get_plants(monkeypatch, query, expected):
    monkeypatch.setattr(
        Plants, "plants",
        [Plant(name='Minze', port=10),
         Plant(name='Chili', port=9)])

    plants = Plants.get_plants(query)

    assert [plant.name for plant in plants] == expected
Example #6
0
def plant_response(bot, update):
    plant_number = re.sub('^/plant *', '', update.message.text)
    if plant_number:
        plants = Plants.get_plants(plant_number)
        if plants:
            plant = plants[0]
            update.message.reply_text(plant.get_humidity_display_text())
            return

    display_choose_keyboard(bot, update.message.chat_id)
Example #7
0
def inline_query(bot, update):
    query = update.inline_query.query
    results = [
        InlineQueryResultArticle(id=uuid4(),
                                 title=plant.name,
                                 input_message_content=InputTextMessageContent(
                                     plant.get_humidity_display_text()))
        for plant in Plants.get_plants(query)
    ]

    update.inline_query.answer(results)
Example #8
0
def test_get_all_plants(monkeypatch):
    plants = [Plant(name='test', port=42)]
    monkeypatch.setattr(Plants, "plants", plants)

    assert plants == Plants.all()