Skip to content

Instantly share code, notes, and snippets.

@kgantsov
Last active February 12, 2019 07:25
Show Gist options
  • Save kgantsov/ccebba670321d0e4272c49cfa9f0b38c to your computer and use it in GitHub Desktop.
Save kgantsov/ccebba670321d0e4272c49cfa9f0b38c to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import usb
import telebot
from temperusb import TemperDevice
TEMP_VENDOR_ID = 0x0c45
TEMP_PRODUCT_ID = 0x7401
TELEGRAM_API_TOKEN = os.environ.get('TELEGRAM_API_TOKEN')
dev = usb.core.find(idVendor=TEMP_VENDOR_ID, idProduct=TEMP_PRODUCT_ID)
temp_dev = TemperDevice(dev)
bot = telebot.TeleBot(TELEGRAM_API_TOKEN)
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(
message,
"Hi there, I am simple bot that shows you a temperature in the bot's apartment"
)
@bot.message_handler(commands=['temp'])
def get_temp(message):
bot.reply_to(message, 'Current temperature is {} C'.format(round(temp_dev.get_temperature(), 1)))
bot.polling()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment