#!/usr/bin/env python import sys import requests token_url = 'https://accounts.somfy.com/oauth/oauth/v2/token' api_url = 'https://www.tahomalink.com/enduser-mobile-web/enduserAPI' auth_payload = { 'client_id': '1e2d830f-4c65-11e7-bd0c-02dd59bd3041_5n78r5nnwaw4wc0kskkg0csogkk8cwocswg84c0gowcgossogw', # TahomaLink prod secrets 'client_secret': '4txucwsv29a8o0co8s8kw8ggswkks8ossccockgcckokw8ck00', 'grant_type': 'password', 'username': '', 'password': '', } r = requests.post(token_url, data=auth_payload) if r.status_code != 200: print('Authentification invalide') sys.exit(-1) token = r.json() r = requests.get(api_url + '/setup', headers={'Authorization': 'Bearer {}'.format(token['access_token'])}) garage = None for device in r.json().get('devices'): if device.get('label') == 'Porte du garage': garage = device break if not garage: print('Impossible de trouver la porte du garage') sys.exit(-1) state = [s['value'] for s in garage.get('states') if s['name'] == 'core:OpenClosedUnknownState'][0] # open, closed, unknown if state != 'closed': print('La porte du garage est ouverte !') # TODO envoyer notification print('terminé')