Skip to content

Commit db68a39

Browse files
committed
fix compatibility with python < 3.9
1 parent c6f9c94 commit db68a39

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This Python script retrieves statistics from [MyElectricalData](https://github.c
55
Long Term Statistics will be created in Home Assistant and usable in the Energy Dashboard.
66

77
## Pre-requisites
8-
- Python 3.4 or higher
8+
- Python 3.5 or higher
99
- A running instance of Home Assistant 2022.10.0 or higher
1010
- A running instance of MyElectricalData 0.8.13-11 or higher
1111
- MyElectricalData must be configured with the cache and hourly details enabled, cf. [wiki](https://github.com/m4dm4rtig4n/myelectricaldata/wiki/03.-Configuration)

statistics_importer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '2.0.0'
1+
__version__ = '2.0.1'
22

33
import aiohttp
44
import argparse
@@ -13,7 +13,7 @@
1313
import sys
1414
import time
1515
import traceback
16-
from typing import Any, Dict, Optional
16+
from typing import Any, Dict, List, Optional
1717
import yaml
1818

1919
MED_CONFIG_DATE_FORMAT: str = "%Y-%m-%d"
@@ -132,7 +132,7 @@ def to_float(s: str) -> float:
132132
return math.nan
133133

134134

135-
def get_max_date_from_med_config(usage_point_config: dict[str, str], statistics_key: str) -> datetime:
135+
def get_max_date_from_med_config(usage_point_config: Dict[str, str], statistics_key: str) -> datetime:
136136
try:
137137
max_date_str = usage_point_config[f"{statistics_key}_max_date"]
138138
max_date = datetime.strptime(max_date_str, MED_CONFIG_DATE_FORMAT)
@@ -143,7 +143,7 @@ def get_max_date_from_med_config(usage_point_config: dict[str, str], statistics_
143143
return max_date
144144

145145

146-
def create_plan_from_med_config(usage_point_config: dict[str, str]):
146+
def create_plan_from_med_config(usage_point_config: Dict[str, str]):
147147
plan_type = PlanType(usage_point_config["plan"])
148148
if plan_type == PlanType.BASE:
149149
plan = PlanBase(to_float(usage_point_config["consumption_price_base"]),
@@ -157,7 +157,7 @@ def create_plan_from_med_config(usage_point_config: dict[str, str]):
157157
return plan
158158

159159

160-
def export_statistics_from_db(db_cursor: sqlite3.Cursor, stat_metadata: StatisticMetadata, start_date: datetime, sum_offset: float, plan: Plan) -> list[StatisticData]:
160+
def export_statistics_from_db(db_cursor: sqlite3.Cursor, stat_metadata: StatisticMetadata, start_date: datetime, sum_offset: float, plan: Plan) -> List[StatisticData]:
161161
is_cost = (stat_metadata.unit_of_measurement == Unit.EURO)
162162
is_base_tariff = (stat_metadata.tariff_type == TariffType.BASE)
163163
# Select the sum of the value column aggregated by hour
@@ -222,7 +222,7 @@ async def authenticate(self, access_token: str) -> None:
222222
raise Exception(
223223
f"authenticate: auth NOT ok, check Home Assistant Long-Lived Access Token")
224224

225-
async def recorder_import_statistics(self, stat_metadata: StatisticMetadata, stats: list[StatisticData]) -> None:
225+
async def recorder_import_statistics(self, stat_metadata: StatisticMetadata, stats: List[StatisticData]) -> None:
226226
self._command_id += 1
227227
await self._websocket.send_json({
228228
"id": self._command_id,
@@ -243,7 +243,7 @@ async def recorder_import_statistics(self, stat_metadata: StatisticMetadata, sta
243243
if not response["success"]:
244244
raise Exception(f"recorder_import_statistics: failed")
245245

246-
async def recorder_list_statistic_ids(self) -> list[dict]:
246+
async def recorder_list_statistic_ids(self) -> List[dict]:
247247
self._command_id += 1
248248
response = await self._websocket.send_json({
249249
"id": self._command_id,
@@ -259,7 +259,7 @@ async def recorder_list_statistic_ids(self) -> list[dict]:
259259

260260
return response["result"]
261261

262-
async def recorder_clear_statistics(self, statistic_ids: list[str]) -> None:
262+
async def recorder_clear_statistics(self, statistic_ids: List[str]) -> None:
263263
self._command_id += 1
264264
response = await self._websocket.send_json({
265265
"id": self._command_id,
@@ -272,7 +272,7 @@ async def recorder_clear_statistics(self, statistic_ids: list[str]) -> None:
272272
if not response["success"]:
273273
raise Exception(f"recorder_clear_statistics: failed")
274274

275-
async def recorder_statistics_during_period(self, stat_metadata: StatisticMetadata, start_time: datetime, end_time: datetime) -> dict[str, list[StatisticData]]:
275+
async def recorder_statistics_during_period(self, stat_metadata: StatisticMetadata, start_time: datetime, end_time: datetime) -> Dict[str, List[StatisticData]]:
276276
self._command_id += 1
277277
await self._websocket.send_json({
278278
"id": self._command_id,

0 commit comments

Comments
 (0)