1
+ import csv
1
2
import datetime as datetime
2
3
import os
4
+ from asyncio import get_running_loop
3
5
from zoneinfo import ZoneInfo
4
6
5
- from aiocsv import AsyncDictReader
6
- from aiofiles import open
7
7
from aiozoneinfo import async_get_time_zone
8
8
9
9
from custom_components .som_energia .price .holidays import holidays
10
10
11
- async def _read_price_csv () -> dict :
11
+ def _read_price_csv () -> dict :
12
12
file_path = os .path .join (os .path .dirname (__file__ ), "prices.csv" )
13
13
prices_data = {}
14
- async with open (file_path , mode = 'r' ) as file :
15
- async for row in AsyncDictReader (file ):
14
+ with open (file_path ) as file :
15
+ reader = csv .DictReader (file )
16
+ for row in reader :
16
17
period = (row ["Inicio Periodo" ], row ["Final Periodo" ])
17
18
prices_data [period ] = {
18
19
"punta" : float (row ["Punta" ] if row ["Punta" ] != "" else 0.0 ),
@@ -28,7 +29,6 @@ async def _read_price_csv() -> dict:
28
29
}
29
30
return prices_data
30
31
31
-
32
32
async def _prices_for_current_period (timezone_datetime : datetime , tz : ZoneInfo ) -> dict :
33
33
prices_of_the_period = {
34
34
"punta" : 0.0 ,
@@ -39,7 +39,7 @@ async def _prices_for_current_period(timezone_datetime: datetime, tz: ZoneInfo)
39
39
"llano_generation_kwh" : 0.0 ,
40
40
"valle_generation_kwh" : 0.0 ,
41
41
}
42
- for period , prices_of_the_period in (await _read_price_csv ( )).items ():
42
+ for period , prices_of_the_period in (await get_running_loop (). run_in_executor ( None , _read_price_csv )).items ():
43
43
prices_period_start = datetime .datetime .strptime (period [0 ], "%Y-%m-%d" ).replace (tzinfo = tz )
44
44
prices_period_end = datetime .datetime .strptime (period [1 ], "%Y-%m-%d" ).replace (
45
45
hour = 23 , minute = 59 , second = 59 , microsecond = 999999 , tzinfo = tz
0 commit comments