27
27
28
28
from .commons import find_reading_by_date
29
29
from .const import DOMAIN , CONF_USER_ID , STATICS_DICT_NAME , STATIC_KWH_TARIFF , INVOICE_DICT_NAME , \
30
- FUTURE_CONSUMPTIONS_DICT_NAME , DAILY_READINGS_DICT_NAME , STATIC_CONTRACT , STATIC_BP_NUMBER , TODAY_READING_DICT_NAME
30
+ FUTURE_CONSUMPTIONS_DICT_NAME , DAILY_READINGS_DICT_NAME , STATIC_CONTRACT , STATIC_BP_NUMBER
31
31
32
32
_LOGGER = logging .getLogger (__name__ )
33
33
TIMEZONE = pytz .timezone ("Asia/Jerusalem" )
@@ -184,8 +184,7 @@ async def _async_update_data(
184
184
185
185
data = {STATICS_DICT_NAME : static_data , INVOICE_DICT_NAME : last_invoice ,
186
186
FUTURE_CONSUMPTIONS_DICT_NAME : future_consumption ,
187
- DAILY_READINGS_DICT_NAME : daily_readings ,
188
- TODAY_READING_DICT_NAME : today_reading }
187
+ DAILY_READINGS_DICT_NAME : daily_readings }
189
188
190
189
# Clean today reading for next reading cycle
191
190
self ._today_reading = None
@@ -197,7 +196,7 @@ async def _insert_statistics(self) -> None:
197
196
# Support only smart meters at the moment
198
197
return
199
198
200
- _LOGGER .info (f"Updating statistics for IEC Contract { self ._contract_id } " )
199
+ _LOGGER .debug (f"Updating statistics for IEC Contract { self ._contract_id } " )
201
200
devices = await self .api .get_devices (self ._contract_id )
202
201
month_ago_time = (datetime .now () - timedelta (weeks = 4 ))
203
202
@@ -219,10 +218,17 @@ async def _insert_statistics(self) -> None:
219
218
self ._contract_id )
220
219
else :
221
220
last_stat_time = last_stat [consumption_statistic_id ][0 ]["start" ]
222
- # API returns daily data, so need to increase the start date by 1 day to get the next day
223
- from_date = datetime .fromtimestamp (last_stat_time ) + timedelta (days = 1 )
221
+ # API returns daily data, so need to increase the start date by 4 hrs to get the next day
222
+ from_date = datetime .fromtimestamp (last_stat_time )
223
+ _LOGGER .debug (f"Last statistics are from { from_date .strftime ('%Y-%m-%d %H:%M:%S' )} " )
224
+
225
+ if from_date .hour == 23 :
226
+ from_date = from_date + timedelta (hours = 2 )
227
+
228
+ _LOGGER .debug (f"Calculated from_date = { from_date .strftime ('%Y-%m-%d %H:%M:%S' )} " )
224
229
if (datetime .today () - from_date ).days <= 0 :
225
- from_date = TIMEZONE .localize (datetime .today ())
230
+ _LOGGER .debug ("The date to fetch is today or later, replacing it with Today at 01:00:00" )
231
+ from_date = TIMEZONE .localize (datetime .today ().replace (hour = 1 , minute = 0 , second = 0 , microsecond = 0 ))
226
232
227
233
_LOGGER .debug (f"Fetching consumption from { from_date .strftime ('%Y-%m-%d %H:%M:%S' )} " )
228
234
readings = await self .api .get_remote_reading (device .device_number , int (device .device_code ),
0 commit comments