Refresh du token
This commit is contained in:
@@ -121,7 +121,7 @@ Vous pourrez alors :
|
|||||||
- [x] Documentation
|
- [x] Documentation
|
||||||
- [x] Utilisation d'un login/mot de passe pour le broker MQTT
|
- [x] Utilisation d'un login/mot de passe pour le broker MQTT
|
||||||
- [x] Publier image Docker en multiple arch
|
- [x] Publier image Docker en multiple arch
|
||||||
- [ ] Renouvellement du token
|
- [x] Renouvellement du token
|
||||||
- [ ] Attente du serveur MQTT si non disponible
|
- [ ] Attente du serveur MQTT si non disponible
|
||||||
- [ ] Tester les paramètres et gestion d'erreur
|
- [ ] Tester les paramètres et gestion d'erreur
|
||||||
- [ ] Utilisation de certificat pour le broker MQTT
|
- [ ] Utilisation de certificat pour le broker MQTT
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class iDiamant():
|
|||||||
|
|
||||||
access_token = ""
|
access_token = ""
|
||||||
refresh_token = ""
|
refresh_token = ""
|
||||||
|
expire_token = 0
|
||||||
volets = {}
|
volets = {}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -35,6 +36,7 @@ class iDiamant():
|
|||||||
jsonStatus = json.loads(response.text)
|
jsonStatus = json.loads(response.text)
|
||||||
iDiamant.access_token = jsonStatus['access_token']
|
iDiamant.access_token = jsonStatus['access_token']
|
||||||
iDiamant.refresh_token = jsonStatus['refresh_token']
|
iDiamant.refresh_token = jsonStatus['refresh_token']
|
||||||
|
iDiamant.expire_token = int(jsonStatus['expires_in'])
|
||||||
|
|
||||||
url = "https://api.netatmo.com/api/homesdata"
|
url = "https://api.netatmo.com/api/homesdata"
|
||||||
headers = {"Authorization": "Bearer " + iDiamant.access_token}
|
headers = {"Authorization": "Bearer " + iDiamant.access_token}
|
||||||
@@ -56,6 +58,18 @@ class iDiamant():
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def updateToken():
|
def updateToken():
|
||||||
""" Update d'un token en fin de vie """
|
""" Update d'un token en fin de vie """
|
||||||
|
url = "https://api.netatmo.com/oauth2/token"
|
||||||
|
data = {'grant_type': 'refresh_token',
|
||||||
|
'refresh_token': iDiamant.refresh_token,
|
||||||
|
'client_id': Constantes.idiamantClientId,
|
||||||
|
'client_secret': Constantes.idiamantClientSecret
|
||||||
|
}
|
||||||
|
response = requests.post(url, data)
|
||||||
|
while 200 != response.status_code:
|
||||||
|
attente = 20
|
||||||
|
print("Problème d'accès au renouvellement de token : attente de " + attente + " secondes")
|
||||||
|
sleep(attente)
|
||||||
|
response = requests.post(url, data)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def publish(topic, playload, retain=True):
|
def publish(topic, playload, retain=True):
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ from time import sleep
|
|||||||
iDiamant.getToken()
|
iDiamant.getToken()
|
||||||
iDiamant.initDiscovery()
|
iDiamant.initDiscovery()
|
||||||
|
|
||||||
# Temps entre chaque pull >= 2
|
|
||||||
# pullTime = Constantes.idiamantPullStatus
|
|
||||||
# if pullTime < 2:
|
|
||||||
# pullTime = 2
|
|
||||||
|
|
||||||
# Envoie des ordres à iDiamant
|
# Envoie des ordres à iDiamant
|
||||||
mqtt2idiamant = Mqtt2iDiamant()
|
mqtt2idiamant = Mqtt2iDiamant()
|
||||||
mqtt2idiamant.start()
|
mqtt2idiamant.start()
|
||||||
|
|
||||||
|
# Refresh du token
|
||||||
|
while True:
|
||||||
|
sleep(iDiamant.expire_token / 2)
|
||||||
|
iDiamant.updateToken()
|
||||||
|
|||||||
Reference in New Issue
Block a user