From dd74d9bc7c3be59222df8041b9cca2fc4e9928cb Mon Sep 17 00:00:00 2001 From: saniho <52693545+saniho@users.noreply.github.com> Date: Fri, 23 Jul 2021 21:32:09 +0200 Subject: [PATCH] gestion random sur heure d'appel .. entre 9h30 et 11:00 pour limiter la saturation du serveur --- custom_components/apiEnedis/const.py | 2 +- custom_components/apiEnedis/manifest.json | 2 +- custom_components/apiEnedis/myCall.py | 6 +++--- custom_components/apiEnedis/myClientEnedis.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/custom_components/apiEnedis/const.py b/custom_components/apiEnedis/const.py index 429c73f..0e0eec3 100644 --- a/custom_components/apiEnedis/const.py +++ b/custom_components/apiEnedis/const.py @@ -1,6 +1,6 @@ """ Constants """ # attention updater aussi manifest.json -__VERSION__ = "1.3.1.8" +__VERSION__ = "1.3.1.9" __name__ = "myEnedis" try: diff --git a/custom_components/apiEnedis/manifest.json b/custom_components/apiEnedis/manifest.json index 49166e1..b3da476 100644 --- a/custom_components/apiEnedis/manifest.json +++ b/custom_components/apiEnedis/manifest.json @@ -3,7 +3,7 @@ "name": "myEnedis sensor", "documentation": "https://github.com/saniho/apiEnedis/", "config_flow": true, - "version": "1.3.1.8", + "version": "1.3.1.9", "requirements": [ ], "dependencies": [], diff --git a/custom_components/apiEnedis/myCall.py b/custom_components/apiEnedis/myCall.py index 14b27b3..2f2589b 100644 --- a/custom_components/apiEnedis/myCall.py +++ b/custom_components/apiEnedis/myCall.py @@ -62,8 +62,8 @@ def post_and_get_json(self, url, params=None, data=None, headers=None): try_again = False except requests.exceptions.Timeout as error: # a ajouter raison de l'erreur !!! - log.info("====== Appel http !!! requests.exceptions.Timeout" ) - dataAnswer = {"enedis_return": {"error": "UNKERROR_002"}} + log.error("====== Appel http !!! requests.exceptions.Timeout" ) + dataAnswer = {"enedis_return": {"error": "UNKERROR_002","message": "Timeout"}} self.setLastAnswer(dataAnswer) except requests.exceptions.HTTPError as error: log.info("====== Appel http !!! requests.exceptions.HTTPError" ) @@ -84,7 +84,7 @@ def post_and_get_json(self, url, params=None, data=None, headers=None): try_again = True # si le nombre de digit n'est pas de 14 ...lié à une erreur coté enedis if ( try_again ) and ( nbEssai > 2): import time - time.sleep(2) # on attend quelques secondes + time.sleep(30) # on attend quelques secondes try_again = False return dataAnswer diff --git a/custom_components/apiEnedis/myClientEnedis.py b/custom_components/apiEnedis/myClientEnedis.py index 931e042..c5fc06a 100644 --- a/custom_components/apiEnedis/myClientEnedis.py +++ b/custom_components/apiEnedis/myClientEnedis.py @@ -60,7 +60,7 @@ def __init__(self, token, PDL_ID, delai=3600, heuresCreuses=None, \ self._forceCallJson = False import random - self._horaireMin = datetime.datetime(2021,7,21,9,30) + datetime.timedelta(minutes=random.randrange(60)) + self._horaireMin = datetime.datetime(2021,7,21,9,30) + datetime.timedelta(minutes=random.randrange(90)) self._myCalli.setParam( PDL_ID, token, version) self._contract = myContrat( self._myCalli, self._token, self._PDL_ID, self._version, heuresCreusesON, heuresCreuses)