Welcome to Mombasa :-)

Commit 58e5b9f3 by Oliver Hertel

Merge branch 'master' of echelon.bastelhalde.de:oliver/MiFloraTelegramBot

parents 9d07f4bb 29fb04c1
[submodule "deps/miflora"]
path = deps/miflora
url = https://github.com/open-homeautomation/miflora.git
[submodule "deps/python-telegram-bot"]
path = deps/python-telegram-bot
url = https://github.com/python-telegram-bot/python-telegram-bot.git
......@@ -20,8 +20,8 @@ plants = []
# GLOBALS
intervalJob = 300 # in Minuten
intervalJob = 300 # in minutes
batteryThreshold = 20 # in percent
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
......@@ -44,7 +44,7 @@ def update(bot, update):
# process general information
def arbeite(bot, update):
def work(bot, update):
update_data = False
chat_id = update.message.chat_id
incoming = update.message.text.lower()
......@@ -68,6 +68,8 @@ def arbeite(bot, update):
def alarm(bot, job):
global plants
global batteryThreshold
for i in range(len(plants)):
plant = plants[i]
bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING)
......@@ -76,6 +78,10 @@ def alarm(bot, job):
alarm_text = 'GIEßEN!\n\n' + str(plant)
bot.send_message(job.context, text=alarm_text, parse_mode=ParseMode.MARKDOWN)
if (plant.poller.parameter_value(MI_BATTERY) < batteryThreshold):
alarm_text = '*BATTERIE!*\n\n' + str(plant)
bot.send_message(job.context, text=alarm_text, parse_mode=ParseMode.MARKDOWN)
def set(bot, update, args, job_queue, chat_data):
global intervalJob
......@@ -128,12 +134,15 @@ def _get_backend(arg):
def main():
global plants
global interval
global batteryThreshold
# load settings
with open('config.json', 'r') as fp:
data = json.load(fp)
token = data['token']
_backend = _get_backend(data['backend'])
batteryThreshold = data['batteryThreshold']
# load plants from config
for i, p in enumerate(data['plants']):
......@@ -162,7 +171,7 @@ def main():
dp.add_handler(CommandHandler("unset", unset, pass_chat_data=True))
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.text, arbeite))
dp.add_handler(MessageHandler(Filters.text, work))
# log all errors
dp.add_error_handler(error)
......
{
"token": "asdf1234",
"backend": "bluepy",
"batteryThreshold": 10,
"plants": [
{
"name": "Kitchen Plant",
......@@ -14,4 +15,3 @@
}
]
}
Subproject commit 0af1185abfbfe35ed2202b0ebab9e94a646efe4a
Subproject commit 820f4e1d59ac2e05c237015843c855e2a2527c6b
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment