-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
71 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.3.0 | ||
hooks: | ||
- id: end-of-file-fixer | ||
# exclude: '\.json$' | ||
- id: trailing-whitespace | ||
args: ['--markdown-linebreak-ext=md'] | ||
- id: check-json | ||
- id: pretty-format-json | ||
args: ['--autofix', '--no-sort-keys'] | ||
- id: check-toml | ||
# - id: check-yaml | ||
- id: debug-statements | ||
|
||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v3.9.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: ['--py39'] | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
args: ['--profile', 'black'] | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 23.7.0 | ||
hooks: | ||
- id: black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
|
@@ -25,10 +23,10 @@ | |
Client, | ||
ClientError, | ||
CommandError, | ||
get_session, | ||
InvalidContractError, | ||
InvalidData, | ||
RequestFailedError, | ||
get_session, | ||
) | ||
|
||
|
||
|
@@ -38,7 +36,7 @@ def get_credentials(parsedargs=None, credentials=None, environ_prefix="IDEENERGY | |
|
||
credentials = credentials or getattr(parsedargs, "credentials", None) | ||
if credentials: | ||
with open(credentials, mode="r", encoding="utf-8") as fh: | ||
with open(credentials, encoding="utf-8") as fh: | ||
d = json.loads(fh.read()) | ||
return d["username"], d["password"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
|
@@ -18,6 +16,7 @@ | |
# USA. | ||
|
||
import asyncio | ||
|
||
from .cli import main | ||
|
||
if __name__ == "__main__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
|
@@ -26,6 +24,7 @@ | |
from typing import Any, Dict, List, Optional, Union | ||
|
||
import aiohttp | ||
|
||
from . import parsers | ||
|
||
_BASE_URL = "https://www.i-de.es/consumidores/rest" | ||
|
@@ -74,7 +73,7 @@ class Measure: | |
accumulate: int | ||
instant: float | ||
|
||
def asdict(self) -> Dict[str, Union[int, float]]: | ||
def asdict(self) -> dict[str, Union[int, float]]: | ||
return dataclasses.asdict(self) | ||
|
||
|
||
|
@@ -140,7 +139,7 @@ def auto_renew_user_session(self) -> bool: | |
|
||
async def request_json( | ||
self, method: str, url: str, encoding: str = "utf-8", **kwargs | ||
) -> Dict[Any, Any]: | ||
) -> dict[Any, Any]: | ||
buff = await self.request_bytes(method, url, **kwargs) | ||
data = json.loads(buff.decode(encoding)) | ||
return data | ||
|
@@ -211,7 +210,7 @@ async def is_icp_ready(self) -> bool: | |
return ret | ||
|
||
@auth_required | ||
async def get_contract_details(self) -> Dict[str, Any]: | ||
async def get_contract_details(self) -> dict[str, Any]: | ||
""" | ||
{ | ||
"ape1Titular": "xxxxxx ", | ||
|
@@ -279,7 +278,7 @@ async def get_contract_details(self) -> Dict[str, Any]: | |
return data | ||
|
||
@auth_required | ||
async def get_contracts(self) -> List[Dict[str, Any]]: | ||
async def get_contracts(self) -> list[dict[str, Any]]: | ||
""" | ||
{ | ||
'success': true, | ||
|
@@ -351,22 +350,22 @@ async def get_measure(self) -> Measure: | |
|
||
async def get_historical_consumption( | ||
self, start: datetime, end: datetime | ||
) -> Dict[str, Any]: | ||
) -> dict[str, Any]: | ||
return await self._get_historical_generic_data( | ||
_CONSUMPTION_PERIOD_ENDPOINT, start, end | ||
) | ||
|
||
async def get_historical_generation( | ||
self, start: datetime, end: datetime | ||
) -> Dict[str, Any]: | ||
) -> dict[str, Any]: | ||
return await self._get_historical_generic_data( | ||
_GENERATION_PERIOD_ENDPOINT, start, end | ||
) | ||
|
||
@auth_required | ||
async def _get_historical_generic_data( | ||
self, url_template: str, start: datetime, end: datetime | ||
) -> Dict[Any, Any]: | ||
) -> dict[Any, Any]: | ||
start = min([start, end]) | ||
end = max([start, end]) | ||
url = url_template.format(start=start, end=end) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
|
@@ -18,13 +16,13 @@ | |
# USA. | ||
|
||
|
||
import itertools | ||
import datetime | ||
import itertools | ||
from typing import Dict | ||
|
||
|
||
def parser_generic_historical_data(data, base_dt: datetime.datetime) -> Dict: | ||
def _normalize_historical_item(idx: int, item: Dict | None) -> Dict | None: | ||
def parser_generic_historical_data(data, base_dt: datetime.datetime) -> dict: | ||
def _normalize_historical_item(idx: int, item: dict | None) -> dict | None: | ||
if item is None: | ||
return None | ||
|
||
|
@@ -53,8 +51,8 @@ def _normalize_historical_item(idx: int, item: Dict | None) -> Dict | None: | |
} | ||
|
||
|
||
def parse_historical_power_demand_data(data) -> Dict: | ||
def _normalize_power_spike_item(item: Dict): | ||
def parse_historical_power_demand_data(data) -> dict: | ||
def _normalize_power_spike_item(item: dict): | ||
return { | ||
"dt": datetime.datetime.strptime(item["name"], "%d/%m/%Y %H:%M"), | ||
"value": item["y"], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
[metadata] | ||
name = ideenergy | ||
version = 1.0.0 | ||
version = 1.0.2 | ||
author = Luis López | ||
author_email = [email protected] | ||
description = Interface to i-de.es energy data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
|
@@ -20,11 +19,10 @@ | |
|
||
|
||
import asyncio | ||
from ideenergy import client | ||
from ideenergy import get_credentials, get_session | ||
|
||
from datetime import datetime, timedelta | ||
|
||
from ideenergy import client, get_credentials, get_session | ||
|
||
|
||
async def main(): | ||
u, p = get_credentials(credentials="credentials.json") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2021-2022 Luis López <[email protected]> | ||
# | ||
|