def tasmota_control(phrase,devname,devip): try: if 'on' in phrase: rq=requests.head("http://"+devip+"/cm?cmnd=Power%20on") say("Tunring on "+devname) elif 'off' in phrase: rq=requests.head("http://"+devip+"/cm?cmnd=Power%20off") say("Tunring off "+devname) except requests.exceptions.ConnectionError: say("Device not online")
def before_filter(): # Skip auth filter for instance management and in development environment. if (request.path.startswith('/_ah/') # Start/stop instance. or ':808' in request.host): # Ports 8080/8081 are used in dev env. return # Authenticate PubSub push messages. if request.path.startswith('/push/'): # Check if request came from a CRMint's push subscription. if request.args.get('token', '') != _PUBSUB_VERIFICATION_TOKEN: return 'Invalid request', 400 # Check if request is signed by PubSub. try: bearer_token = request.headers.get('Authorization') token = bearer_token.split(' ')[1] claim = id_token.verify_oauth2_token(token, _REQUEST) except Exception as e: # pylint: disable=broad-except return f'Invalid token: {e}', 400 # Check if request is signed with the App Engine's service account key. if claim['email'] != f'{_PROJECT_ID}@appspot.gserviceaccount.com': return 'Invalid request', 400 else: # Check if the user is authenticated. response = requests.head(f'{request.url_root}assets/favicon.ico', cookies=request.cookies) if response.status_code != 200: return redirect(request.url_root)