Skip to content

Commit

Permalink
add unittest for EcoWatt
Browse files Browse the repository at this point in the history
  • Loading branch information
saniho committed Jan 3, 2023
1 parent bb86a21 commit 36a3105
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions custom_components/apiEnedis/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self):
PLATFORMS = ["sensor"]

_formatDateYmd = "%Y-%m-%d"
_formatDateYmdHMS = "%Y-%m-%d %H:%M:%S"

ENTITY_NAME = "name"
ENTITY_DELAI = "delai"
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 @@ -5,7 +5,7 @@
"issue_tracker": "https://github.com/saniho/apiEnedis/issues",
"iot_class": "cloud_polling",
"config_flow": true,
"version": "2.3.0",
"version": "2.3.1",
"requirements": [
"packaging>=20.8"
],
Expand Down
18 changes: 14 additions & 4 deletions custom_components/apiEnedis/myDataEnedisByDayDetail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from .const import ( # isort:skip
__nameMyEnedis__,
_formatDateYmd,
_formatDateYmdHMS,
)

except ImportError:
from const import ( # type: ignore[no-redef]
__nameMyEnedis__,
_formatDateYmd,
__formatDateYmdHMS,
)

import datetime
Expand Down Expand Up @@ -179,11 +181,19 @@ def createMultiDaysHCHP(self, data):
# dateDuJour = (datetime.date.today()).strftime(_formatDateYmd)
for x in data["meter_reading"]["interval_reading"]:
self._interval_length = x["interval_length"]
date = x["date"][:10]
heure = x["date"][11:16]
# date est la date de fin de la plage
# on recule d'une minute .. car la date et l'heure est la fin de la plage
if ( x["date"][:13] == "2022-12-27 21") or ( x["date"][:16] == "2022-12-27 22:00"):
pass
newDate = x["date"]
newDate = (
datetime.datetime.strptime(x["date"], "%Y-%m-%d %H:%M:%S") - datetime.timedelta(minutes=1)
).strftime(_formatDateYmdHMS)
date = newDate[:10]
heure = newDate[11:16]
if (
heure == "00:00"
): # alors sur la veille, var c'est la fin de la tranche du jour precedent
): # alors sur la veille, car c'est la fin de la tranche du jour precedent
date = (
datetime.datetime.strptime(date, "%Y-%m-%d") - datetime.timedelta(1)
).strftime(_formatDateYmd)
Expand All @@ -198,7 +208,7 @@ def createMultiDaysHCHP(self, data):
if date not in joursHP:
joursHP[date] = 0
heurePleine = self._contrat._getHCHPfromHour(heure)
clef = x["date"][:13]
clef = x["date"][:13] # clef contient la date et l'heure .. pas les minutes
if clef not in self._dateHeureDetail.keys():
self._dateHeureDetail[clef] = 0
self._dateHeureDetail[clef] += (
Expand Down
3 changes: 2 additions & 1 deletion custom_components/apiEnedis/sensorEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def getStatusEnergyDetailHours(self, typeSensor=_consommation):

total = valeurHP + valeurHC
state = f"{0.001 * total:.3f}"
lastResetIso = lastReset.isoformat()
# on recule d'une heure, car il faut indiquer le dernier "changement"
lastResetIso = (lastReset - datetime.timedelta(hours=1)).isoformat()
return lastResetIso, status_counts, state

def getStatusEnergyDetailHoursCost(self, typeSensor=_consommation):
Expand Down
6 changes: 3 additions & 3 deletions testEnedis.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def testMulti():
status_counts, state = myDataSensorEnedis.getStatus(typeSensor)
typeSensor = _production
status_counts, state = myDataSensorEnedis.getStatus(typeSensor)
# lastReset, status_counts, state = (
# myDataSensorEnedis.getStatusEnergyDetailHours( typeSensor )
# )
lastReset, status_counts, state = (
myDataSensorEnedis.getStatusEnergyDetailHours(typeSensor)
)
# lastReset, status_counts, state = (
# myDataSensorEnedis.getStatusEnergyDetailHoursCost( typeSensor )
# )
Expand Down

0 comments on commit 36a3105

Please sign in to comment.