Skip to content

Commit

Permalink
gestion retry sur un timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
saniho committed Jul 14, 2021
1 parent e2a137e commit 49fd199
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 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 """

__VERSION__ = "1.3.1.1" # attention updater aussi manifest.json
__VERSION__ = "1.3.1.2" # attention updater aussi manifest.json
__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.1",
"version": "1.3.1.2",
"requirements": [
],
"dependencies": [],
Expand Down
2 changes: 0 additions & 2 deletions custom_components/apiEnedis/myCall.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ def post_and_get_json(self, url, params=None, data=None, headers=None):
log.info("====== Appel http !!! reponse : %s =====" %(dataAnswer))
#raise(requests.exceptions.Timeout) # pour raiser un timeout de test ;)
try_again = False
#return dataAnswer
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"}}
self.setLastAnswer(dataAnswer)
#return dataAnswer
except requests.exceptions.HTTPError as error:
log.info("====== Appel http !!! requests.exceptions.HTTPError" )
if ( "ADAM-ERR0069" not in response.text ) and \
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 @@ -109,7 +109,7 @@ def readDataJson(self):
clef = os.path.basename(nomFichier).split(".")[0]
data[clef] = json.load(json_file)
except:
log.error(" >>>> erreur lecture : %s" %(nomfichier))
log.error(" >>>> erreur lecture : %s" %(nomFichier))
pass # si erreur lecture ... on continue ;)
return data

Expand Down
11 changes: 6 additions & 5 deletions custom_components/apiEnedis/sensorEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ def getStatus(self, typeSensor = _consommation):
status_counts["versionUpdateAvailable"] = \
self.getExistsRecentVersion( self.version, self._myDataEnedis.getGitVersion() )

#if self._myDataEnedis.getContract() != None:
if self._myDataEnedis.getTimeLastCall() != None:
# pas necessaire en visu
#status_counts["typeCompteurPDL"] = ','.join(self._myDataEnedis.getTypePDL())
self._LOGGER.info("-- ** on va mettre à jour : %s" %self._myDataEnedis.getContract().get_PDL_ID())
status_counts["nbCall"] = self._myDataEnedis.getNbCall()
status_counts["typeCompteur"] = typeSensor
status_counts["numPDL"] = self._myDataEnedis.getContract().get_PDL_ID()
status_counts["activationDate"] = self._myDataEnedis.getContract().getLastActivationDate()
if self._myDataEnedis.isConsommation():
status_counts["lastUpdate"] = self._myDataEnedis.getLastUpdate()
Expand Down Expand Up @@ -251,8 +250,10 @@ def getStatus(self, typeSensor = _consommation):
"{:.3f}".format(self._myDataEnedis.getYesterdayHCHP().getHP() * 0.001)
status_counts['current_week'] = \
"{:.3f}".format(self._myDataEnedis.getCurrentWeek().getValue() * 0.001)
status_counts['current_week_number'] = \
datetime.datetime.fromisoformat(self._myDataEnedis.getCurrentWeek().getDateDeb()).isocalendar()[1]

if self._myDataEnedis.getCurrentWeek().getDateDeb() != None:
status_counts['current_week_number'] = \
datetime.datetime.fromisoformat(self._myDataEnedis.getCurrentWeek().getDateDeb()).isocalendar()[1]
status_counts['current_week_last_year'] = \
"{:.3f}".format(self._myDataEnedis.getCurrentWeekLastYear().getValue() * 0.001)
status_counts['last_month'] = "{:.3f}".format(self._myDataEnedis.getLastMonth().getValue() * 0.001)
Expand Down
4 changes: 2 additions & 2 deletions testEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def testMulti():
import configparser
mon_conteneur = configparser.ConfigParser()
mon_conteneur.read("../myCredential/security.txt")
for qui in ["ENEDIS"]:
for qui in ["ENEDIS28"]:
log.info("*** traitement de %s " %(qui))
token = mon_conteneur[qui]['TOKEN']
PDL_ID = mon_conteneur[qui]['CODE']
Expand All @@ -39,7 +39,7 @@ def testMulti():
path = getLocalDirectory( PDL_ID, "20210713" )
myDataEnedis.setPathArchive(path)
dataJson = {}
dataJson = myDataEnedis.readDataJson()
#dataJson = myDataEnedis.readDataJson()
myDataEnedis.setDataJsonDefault( dataJsonDefault = dataJson)
myDataEnedis.setDataJsonCopy()
myDataEnedis.manageLastCallJson()
Expand Down

0 comments on commit 49fd199

Please sign in to comment.