Verified Commit f889c5fc authored by Mroik's avatar Mroik
Browse files

Temporary changes

parent 0bfe9f0f
......@@ -13,7 +13,7 @@ LOGGER = logging.getLogger(__name__)
def main():
# logging.basicConfig(level=logging.DEBUG) # Uncomment for DUBUG
logging.basicConfig(level=logging.DEBUG) # Uncomment for DUBUG
mt.bot = Bot(SERVER, PORT)
mt.bot.start(USERNAME, PASSWORD)
......
......@@ -25,6 +25,7 @@ def on_message(client, userdata, msg):
payload = json.loads(msg.payload.decode("utf-8"))
if msg.topic != "sede/status":
return
return
if payload["status"] == OPEN:
for id_ in where_am_i:
updater.bot.send_message(id_, "🟢🟢 Il POuL è aperto! 🟢🟢")
......
......@@ -42,28 +42,26 @@ def check_debounce():
last_change = datetime.now()
return True
else:
if datetime.now() - timedelta(seconds=20) < last_change:
if datetime.now() - timedelta(seconds=2) < last_change:
return True
return False
def set_open(update: Update, context: CallbackContext):
LOGGER.debug("Trying to open")
if check_debounce():
return
if not check_admin(update, context):
raise DispatcherHandlerStop
resp = mt.bot.mqtt.publish("sede/status", payload=json.dumps({"id": "Set from telegram", "status": OPEN}))
LOGGER.info(resp.mid)
set_status(True, update, context)
def set_closed(update: Update, context: CallbackContext):
LOGGER.debug("Trying to close")
set_status(False, update, context)
def set_status(status: bool, update: Update, context: CallbackContext):
LOGGER.debug(f"Trying to set status to {status}")
if check_debounce():
LOGGER.debug("Debounce triggered")
return
if not check_admin(update, context):
LOGGER.debug("Not an admin")
raise DispatcherHandlerStop
resp = mt.bot.mqtt.publish("sede/status", payload=json.dumps({"id": "Set from telegram", "status": CLOSED}))
resp = mt.bot.mqtt.publish("sede/status", payload=json.dumps({"id": "Set from telegram", "status": OPEN if status else CLOSED}))
LOGGER.info(resp.mid)
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