Skip to content

Commit

Permalink
meilleure gestion de nodataavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
saniho committed Apr 16, 2021
1 parent c13d511 commit 2f74326
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
DEFAULT_SCAN_INTERVAL_HISTORIQUE = 60*10 # 1 fois toutes les 10 minutes

HEURESCREUSES_ON = "heuresCreusesON"
__VERSION__ = "1.1.4.3RC" # attention updater aussi manifest.json
__VERSION__ = "1.1.4.3RC2b" # attention updater aussi manifest.json
__name__ = "myEnedis"

_consommation = "consommation"
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.1.4.3RC",
"version": "1.1.4.3RC2b",
"requirements": [
],
"dependencies": [],
Expand Down
20 changes: 9 additions & 11 deletions custom_components/apiEnedis/myEnedis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import requests
import datetime, time, sys
import json
import datetime, sys
import logging

try:
Expand Down Expand Up @@ -109,24 +107,24 @@ def post_and_get_json(self, url, params=None, data=None, headers=None):
try:
import time
time.sleep( self._waitCall )
import json
import json, requests
session = requests.Session()
#self.myLogWarning("params : %s " % (params))
#self.myLogWarning("data : %s " % (json.dumps(data)))
session.verify = True
response = session.post(url, params=params, data=json.dumps(data), headers=headers, timeout=30)
response.raise_for_status()
#print(response.json())
return response.json()
except requests.exceptions.Timeout as error:
response = {"enedis_return": {"error": "UNKERROR_002"}}
return response
except requests.exceptions.HTTPError as error:
if ( "ADAM-ERR0069" not in response.text ) and \
( "__token_refresh_401" not in response.text ):
( "__token_refresh_401" not in response.text ):
self.myLogError("*" * 60)
self.myLogError("header : %s " % (headers))
self.myLogError("params : %s " % (params))
self.myLogError("data : %s " % (json.dumps(data)))
self.myLogError("Error JSON : %s " % (response.text))
self.myLogError("*" * 60)
#with open('error.json', 'w') as outfile:
# json.dump(response.json(), outfile)

Expand Down Expand Up @@ -524,9 +522,9 @@ def updateContract(self, data=None):
self.myLog("--updateContract --")
if (data == None): data = self.CallgetDataContract()
self.myLog("updateContract : data %s" % (data))
self.checkDataContract(data)
self.myLog("updateContract(2) : data %s" % (data))
self._contract = self.analyseValueContract(data)
if ( self.checkDataContract(data) ):
self.myLog("updateContract(2) : data %s" % (data))
self._contract = self.analyseValueContract(data)
except Exception as inst:
if (inst.args[:2] == ("call", "error")):
self.myLogWarning("*" * 60)
Expand Down
1 change: 1 addition & 0 deletions custom_components/apiEnedis/sensorEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def getStatus(self, typeSensor = _consommation):
status_counts['current_week'] = "{:.3f}".format(self._myDataEnedis.getCurrentWeek() * 0.001)
status_counts['current_week_last_year'] = "{:.3f}".format(self._myDataEnedis.getCurrentWeekLastYear() * 0.001)
status_counts['last_month'] = "{:.3f}".format(self._myDataEnedis.getLastMonth() * 0.001)
status_counts['last_month_last_year'] = "{:.3f}".format(self._myDataEnedis.getLastMonthLastYear() * 0.001)
status_counts['current_month'] = "{:.3f}".format(self._myDataEnedis.getCurrentMonth() * 0.001)
status_counts['last_year'] = "{:.3f}".format(self._myDataEnedis.getLastYear() * 0.001)
status_counts['current_year'] = "{:.3f}".format(self._myDataEnedis.getCurrentYear() * 0.001)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/apiEnedis/testEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def testMulti():
#for qui in ["ENEDIS19"]:
#for qui in ["ENEDIS"]:
#for qui in ["ENEDIS21"]:
for qui in ["ENEDIS28"]:
for qui in ["ENEDIS24"]:
print("*** traitement de %s " %(qui))
token = mon_conteneur[qui]['TOKEN']
PDL_ID = mon_conteneur[qui]['CODE']
Expand Down

0 comments on commit 2f74326

Please sign in to comment.