Skip to content

Commit

Permalink
gestion random sur heure d'appel .. entre 9h30 et 11:00
Browse files Browse the repository at this point in the history
pour limiter la saturation du serveur
  • Loading branch information
saniho committed Jul 23, 2021
1 parent 2ba2054 commit dd74d9b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Constants """
# attention updater aussi manifest.json
__VERSION__ = "1.3.1.8"
__VERSION__ = "1.3.1.9"
__name__ = "myEnedis"

try:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
6 changes: 3 additions & 3 deletions custom_components/apiEnedis/myCall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/myClientEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dd74d9b

Please sign in to comment.