Skip to content

Commit

Permalink
probleme enedis ne donne pas le detail de la veille( HC/HP )
Browse files Browse the repository at this point in the history
  • Loading branch information
saniho committed Dec 8, 2020
1 parent f16e711 commit dd58f28
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
31 changes: 25 additions & 6 deletions custom_components/apiEnedis/apiEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ def __init__(self, token, PDL_ID, delai = 3600, heuresCreuses = None, \
pass

def myLog(self, message):
pass
#self._log.info(message)
#self._log.warning(message)
pass

def myLogWarning(self, message):
self._log.warning(message)

Expand Down Expand Up @@ -392,6 +393,7 @@ def createMultiDaysHCHP(self, data):
self._joursHP={}
dateDuJour = (datetime.date.today()).strftime("%Y-%m-%d")
for x in data["meter_reading"]["interval_reading"]:
self._interval_length = x["interval_length"]
date = x["date"][:10]
heure = x["date"][11:16]
if ( heure == "00:00" ): # alors sur la veille, var c'est la fin de la tranche du jour precedent
Expand All @@ -410,6 +412,10 @@ def createMultiDaysHCHP(self, data):
else:
self._joursHC[date] +=int(x["value"]) * self.getCoeffIntervalLength() # car c'est pas en heure

# if ( date == "2020-12-06" ):
# print("ici", x["date"], heure, " ", heurePleine, ", ", x[ "value" ], \
# self._joursHP[date], self._joursHC[date], self._joursHP[date] + self._joursHC[date])

#print(self._joursHC)
#print(self._joursHP)

Expand Down Expand Up @@ -440,10 +446,10 @@ def createHCHP(self, data):
#print(self._HP)

def updateDataYesterdayHCHP(self, data=None):
self.updateLastMethodCall("updateDataHCHP")
self.myLog("--updateDataHCHP --")
self.updateLastMethodCall("updateDataYesterdayHCHP")
self.myLog("--updateDataYesterdayHCHP --")
if (data == None): data = self.CallgetDataYesterdayHCHP()
self.myLog("updateDataHCHP : data %s" % (data))
self.myLog("updateDataYesterdayHCHP : data %s" % (data))
self.checkData(data)
self.createHCHP(data)

Expand Down Expand Up @@ -612,6 +618,7 @@ def updateErrorLastCall(self, errorMessage):
def getDelai(self):
return self._delai
def getDelaiIsGood(self):
self.myLogWarning("TimeLastCall : %s" %(self.getTimeLastCall()))
ecartOk = ( datetime.datetime.now() - self.getTimeLastCall()).seconds > self.getDelai()
return ecartOk

Expand All @@ -623,7 +630,8 @@ def update(self):
self.updateLastMethodCall("")
try:
self.setUpdateRealise( True )
self.myLogWarning( "myEnedis ...%s update lancé, status precedent : %s" % (self.get_PDL_ID(), self.getStatusLastCall()))
self.myLogWarning( "myEnedis ...%s update lancé, status precedent : %s, lastCall :%s" \
% (self.get_PDL_ID(), self.getStatusLastCall(), self.getLastMethodCallError()))
if ( self.isConsommation()):
self._niemeAppel += 1
if (self.getStatusLastCall() or self.getLastMethodCallError() == "updateYesterday"):
Expand All @@ -647,7 +655,18 @@ def update(self):
if (self.getStatusLastCall() or self.getLastMethodCallError() == "updateCurrentYear"):
self.updateCurrentYear()
if (self.getStatusLastCall() or self.getLastMethodCallError() == "updateDataYesterdayHCHP"):
self.updateDataYesterdayHCHP()
try:
self.updateDataYesterdayHCHP()
except Exception as inst:
if ( inst.args[:3] == ('call', 'error', 'no_data_found')): # gestion que c'est pas une erreur de contrat trop recent ?
# si le service ne repond pas, l'erreur pas grave
self.updateErrorLastCall( "%s"%(self.getLastAnswer()))
pass
else:
raise Exception(inst)

# if (self.getStatusLastCall() or self.getLastMethodCallError() == "updateDataYesterdayHCHP"):
# self.updateDataYesterdayHCHP()
if (self.getStatusLastCall() or self.getLastMethodCallError() == "updateLastYear"):
self.updateLastYear()
if (self.getStatusLastCall() or self.getLastMethodCallError() == "updateLastMonthLastYear"):
Expand Down
6 changes: 4 additions & 2 deletions custom_components/apiEnedis/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

ICON = "mdi:package-variant-closed"

__VERSION__ = "1.0.5.0"
__VERSION__ = "1.0.5.1"

SCAN_INTERVAL = timedelta(seconds=1800)# interrogation enedis ?
DEFAUT_DELAI_INTERVAL = 7200 # interrogation faite toutes 2 les heures
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(self, session, name, interval, myDataEnedis):
self._session = session
self._name = name
self._myDataEnedis = myDataEnedis
self._attributes = None
self._attributes = {}
self._state = None
self._unit = "kWh"
self.update = Throttle(interval)(self._update)
Expand All @@ -113,6 +113,8 @@ def setAttributesFromLastAttributes(self):
if ( self._lastAttributes != None ) :
self._attributes = self._lastAttributes.copy()
return self._attributes
else:
return {}

@property
def name(self):
Expand Down
22 changes: 16 additions & 6 deletions custom_components/apiEnedis/sensorEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def manageSensorState( _myDataEnedis,_LOGGER = None, version = None ):
# si pas de mises à jour alors juste return !!
return
if (_myDataEnedis.getStatusLastCall()): # update avec statut ok
#if( 1 ): #
try:
status_counts["typeCompteur"] = _myDataEnedis.getTypePDL()
if ( _myDataEnedis.isConsommation()):
Expand All @@ -19,10 +20,10 @@ def manageSensorState( _myDataEnedis,_LOGGER = None, version = None ):
status_counts['yesterday'] = _myDataEnedis.getYesterday()
status_counts['last_week'] = _myDataEnedis.getLastWeek()

last7days = _myDataEnedis.getLast7Days()
for day in last7days:
status_counts['day_%s' % (day["niemejour"])] = day["value"]
status_counts['daily'] = [("{:.2f}".format(day["value"] * 0.001)) for day in last7days]
#last7days = _myDataEnedis.getLast7Days()
#for day in last7days:
# status_counts['day_%s' % (day["niemejour"])] = day["value"]
#status_counts['daily'] = [("{:.2f}".format(day["value"] * 0.001)) for day in last7days]

last7daysHP = _myDataEnedis.get7DaysHP()
listeClef = list(last7daysHP.keys())
Expand Down Expand Up @@ -80,6 +81,15 @@ def manageSensorState( _myDataEnedis,_LOGGER = None, version = None ):
dailyHP.append(last7daysHP[clef])
status_counts['dailyweek_HP'] = [("{:.3f}".format(0.001 * day_HP)) for day_HP in dailyHP]

niemejour = 0
daily = []
for clef in listeClef:
niemejour += 1
somme = last7daysHP[clef] + last7daysHC[clef]
status_counts['day_%s' %(niemejour)] = somme
daily.append(somme)
status_counts['daily'] = [("{:.2f}".format(0.001 * day)) for day in daily]

status_counts["halfhourly"] = []
status_counts["offpeak_hours"] = _myDataEnedis.getYesterdayHC() * 0.001
status_counts["peak_hours"] = _myDataEnedis.getYesterdayHP() * 0.001
Expand All @@ -104,9 +114,9 @@ def manageSensorState( _myDataEnedis,_LOGGER = None, version = None ):
status_counts['last_year'] = _myDataEnedis.getLastYear() * 0.001
status_counts['current_year'] = _myDataEnedis.getCurrentYear() * 0.001
status_counts['errorLastCall'] = _myDataEnedis.getErrorLastCall()
if ((_myDataEnedis.getLastMonthLastYear() != None) and
if ((_myDataEnedis.getLastMonthLastYear() is not None) and
(_myDataEnedis.getLastMonthLastYear() != 0) and
(_myDataEnedis.getLastMonth() != None)):
(_myDataEnedis.getLastMonth() is not None)):
status_counts["monthly_evolution"] = \
((_myDataEnedis.getLastMonth() - _myDataEnedis.getLastMonthLastYear())
/ _myDataEnedis.getLastMonthLastYear()) * 100
Expand Down
4 changes: 2 additions & 2 deletions custom_components/apiEnedis/testEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def testMulti():
mon_conteneur.read("../../../myCredential/security.txt")
#for qui in ["ENEDIS","ENEDIS2","ENEDIS3","ENEDIS4"]:
#for qui in ["ENEDIS","ENEDIS7"]:
for qui in ["ENEDIS8"]:
for qui in ["ENEDIS"]:
token = mon_conteneur[qui]['TOKEN']
PDL_ID = mon_conteneur[qui]['CODE']
print(token, PDL_ID)
Expand All @@ -107,7 +107,7 @@ def testMono():
import configparser
mon_conteneur = configparser.ConfigParser()
mon_conteneur.read("../../../myCredential/security.txt")
qui = "ENEDIS8"
qui = "ENEDIS"
token = mon_conteneur[qui]['TOKEN']
PDL_ID = mon_conteneur[qui]['CODE']
print(token, PDL_ID)
Expand Down

0 comments on commit dd58f28

Please sign in to comment.