ideenergy 2.0.0rc2__tar.gz → 2.0.1.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ideenergy-2.0.1.dev1/PKG-INFO +36 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/README.md +6 -5
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy/__init__.py +23 -27
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy/cli.py +75 -19
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy/client.py +79 -145
- ideenergy-2.0.1.dev1/ideenergy/endpoints.py +170 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy/types.py +0 -1
- ideenergy-2.0.1.dev1/ideenergy.egg-info/PKG-INFO +36 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy.egg-info/SOURCES.txt +1 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy.egg-info/requires.txt +1 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/pyproject.toml +10 -3
- ideenergy-2.0.0rc2/PKG-INFO +0 -709
- ideenergy-2.0.0rc2/ideenergy.egg-info/PKG-INFO +0 -709
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/LICENSE +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy/__main__.py +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy/parsers.py +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy.egg-info/dependency_links.txt +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy.egg-info/entry_points.txt +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/ideenergy.egg-info/top_level.txt +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/setup.cfg +0 -0
- {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev1}/tests/test_client.py +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ideenergy
|
|
3
|
+
Version: 2.0.1.dev1
|
|
4
|
+
Summary: Programmatic access to consumer energy consumption from https://www.i-de.es/ (Spanish energy distributor)
|
|
5
|
+
Author-email: Luis López <luis@cuarentaydos.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/ldotlopez/ideenergy
|
|
7
|
+
Project-URL: Issues, https://github.com/ldotlopez/ideenergy/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/ldotlopez/ideenergy.git
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: aiohttp<4.0,>=3.8
|
|
15
|
+
Requires-Dist: dotenv>=0.9.9
|
|
16
|
+
Requires-Dist: importlib-metadata; python_version >= "3.11"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# ideenergy
|
|
20
|
+
|
|
21
|
+
Programmatic access to consumer energy consumption from https://www.i-de.es/ (Spanish energy distributor)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<!-- Code and releases -->
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
[](https://github.com/ldotlopez/ideenergy/actions/workflows/release.yml)
|
|
28
|
+
[](https://github.com/ldotlopez/ideenergy/actions/workflows/publish.yml)
|
|
29
|
+
|
|
30
|
+
<!-- Sponsors -->
|
|
31
|
+
<a href="https://www.buymeacoffee.com/zepolson" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 30px !important;width: 105px !important;" ></a>
|
|
32
|
+
|
|
33
|
+
**Useful links**
|
|
34
|
+
|
|
35
|
+
* [Related Home-Assistant component](https://github.com/ldotlopez/ha-ideenergy)
|
|
36
|
+
* [Documentation about other distributors](https://www.genbeta.com/web/como-saber-consumo-electrico-tiempo-real-casa)
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# ideenergy
|
|
2
2
|
|
|
3
|
+
Programmatic access to consumer energy consumption from https://www.i-de.es/ (Spanish energy distributor)
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
<!-- Code and releases -->
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[
|
|
9
|
+
[](https://github.com/ldotlopez/ideenergy/actions/workflows/release.yml)
|
|
10
|
+
[](https://github.com/ldotlopez/ideenergy/actions/workflows/publish.yml)
|
|
8
11
|
|
|
9
12
|
<!-- Sponsors -->
|
|
10
13
|
<a href="https://www.buymeacoffee.com/zepolson" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 30px !important;width: 105px !important;" ></a>
|
|
11
14
|
|
|
12
|
-
Programmatic access to consumer energy consumption from https://www.i-de.es/ (Spanish energy distributor)
|
|
13
|
-
|
|
14
15
|
**Useful links**
|
|
15
16
|
|
|
16
17
|
* [Related Home-Assistant component](https://github.com/ldotlopez/ha-ideenergy)
|
|
@@ -18,9 +18,6 @@
|
|
|
18
18
|
|
|
19
19
|
import json
|
|
20
20
|
import os
|
|
21
|
-
from dataclasses import dataclass, field
|
|
22
|
-
from datetime import datetime
|
|
23
|
-
from typing import Dict, List
|
|
24
21
|
|
|
25
22
|
from .client import (
|
|
26
23
|
Client,
|
|
@@ -29,7 +26,7 @@ from .client import (
|
|
|
29
26
|
InvalidContractError,
|
|
30
27
|
InvalidData,
|
|
31
28
|
RequestFailedError,
|
|
32
|
-
|
|
29
|
+
UserExpiredError,
|
|
33
30
|
)
|
|
34
31
|
from .types import (
|
|
35
32
|
ConsumptionForPeriod,
|
|
@@ -41,46 +38,45 @@ from .types import (
|
|
|
41
38
|
PeriodValue,
|
|
42
39
|
)
|
|
43
40
|
|
|
41
|
+
# def get_credentials(parsedargs=None, credentials=None, environ_prefix="I_DE_ENERGY"):
|
|
42
|
+
# if parsedargs and parsedargs.username:
|
|
43
|
+
# return parsedargs.username, parsedargs.password
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
# credentials = credentials or getattr(parsedargs, "credentials", None)
|
|
46
|
+
# if credentials:
|
|
47
|
+
# with open(credentials, encoding="utf-8") as fh:
|
|
48
|
+
# d = json.loads(fh.read())
|
|
49
|
+
# return d["username"], d["password"]
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
# if environ_prefix:
|
|
52
|
+
# environ_prefix = environ_prefix.upper()
|
|
53
|
+
# return (
|
|
54
|
+
# os.environ.get(f"{environ_prefix}_USERNAME"),
|
|
55
|
+
# os.environ.get(f"{environ_prefix}_PASSWORD"),
|
|
56
|
+
# )
|
|
54
57
|
|
|
55
|
-
if environ_prefix:
|
|
56
|
-
environ_prefix = environ_prefix.upper()
|
|
57
|
-
return (
|
|
58
|
-
os.environ.get(f"{environ_prefix}_USERNAME"),
|
|
59
|
-
os.environ.get(f"{environ_prefix}_PASSWORD"),
|
|
60
|
-
)
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return " ".join([x.strip().capitalize() for x in address.split(" ") if x])
|
|
59
|
+
# def sanitize_address(address):
|
|
60
|
+
# return " ".join([x.strip().capitalize() for x in address.split(" ") if x])
|
|
65
61
|
|
|
66
62
|
|
|
67
63
|
__all__ = [
|
|
68
64
|
"Client",
|
|
69
65
|
"ClientError",
|
|
70
66
|
"CommandError",
|
|
71
|
-
"get_credentials",
|
|
72
|
-
"get_session",
|
|
73
|
-
"InvalidContractError",
|
|
74
|
-
"InvalidData",
|
|
75
|
-
"RequestFailedError",
|
|
76
|
-
"sanitize_address",
|
|
77
67
|
"ConsumptionForPeriod",
|
|
78
68
|
"DemandAtInstant",
|
|
79
69
|
"HistoricalConsumption",
|
|
80
70
|
"HistoricalGeneration",
|
|
81
71
|
"HistoricalPowerDemand",
|
|
72
|
+
"InvalidContractError",
|
|
73
|
+
"InvalidData",
|
|
82
74
|
"Measure",
|
|
83
75
|
"PeriodValue",
|
|
76
|
+
"RequestFailedError",
|
|
77
|
+
"UserExpiredError",
|
|
78
|
+
# "get_credentials",
|
|
79
|
+
# "sanitize_address",
|
|
84
80
|
]
|
|
85
81
|
|
|
86
82
|
__doc__ = """
|
|
@@ -17,25 +17,34 @@
|
|
|
17
17
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
18
18
|
# USA.
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
import argparse
|
|
22
21
|
import asyncio
|
|
23
22
|
import logging
|
|
23
|
+
import os
|
|
24
24
|
import pprint
|
|
25
25
|
import sys
|
|
26
26
|
from datetime import datetime, timedelta
|
|
27
|
+
from types import SimpleNamespace
|
|
28
|
+
|
|
29
|
+
import aiohttp
|
|
30
|
+
import dotenv
|
|
27
31
|
|
|
28
|
-
from . import
|
|
32
|
+
from . import ( # get_credentials,
|
|
33
|
+
Client,
|
|
34
|
+
RequestFailedError,
|
|
35
|
+
UserExpiredError,
|
|
36
|
+
)
|
|
29
37
|
|
|
30
38
|
|
|
31
39
|
def build_arg_parser():
|
|
32
40
|
parser = argparse.ArgumentParser()
|
|
33
41
|
parser.add_argument("-u", "--username", required=False)
|
|
34
42
|
parser.add_argument("-p", "--password", required=False)
|
|
35
|
-
parser.add_argument("--credentials", required=False)
|
|
43
|
+
# parser.add_argument("--credentials", required=False)
|
|
44
|
+
parser.add_argument("--trace-http-requests", required=False, action="store_true")
|
|
36
45
|
parser.add_argument("--retries", type=int, default=1)
|
|
37
|
-
parser.add_argument("--contract")
|
|
38
46
|
|
|
47
|
+
parser.add_argument("--contract")
|
|
39
48
|
parser.add_argument("--list-contracts", action="store_true")
|
|
40
49
|
parser.add_argument("--get-measure", action="store_true")
|
|
41
50
|
parser.add_argument("--get-historical-consumption", action="store_true")
|
|
@@ -45,7 +54,7 @@ def build_arg_parser():
|
|
|
45
54
|
return parser
|
|
46
55
|
|
|
47
56
|
|
|
48
|
-
async def
|
|
57
|
+
async def amain():
|
|
49
58
|
async def get_requested_data():
|
|
50
59
|
if args.list_contracts:
|
|
51
60
|
contracts = await client.get_contracts()
|
|
@@ -79,31 +88,78 @@ async def _main():
|
|
|
79
88
|
|
|
80
89
|
parser = build_arg_parser()
|
|
81
90
|
args = parser.parse_args()
|
|
82
|
-
username
|
|
91
|
+
username = args.username or os.environ.get("I_DE_ENERGY_USERNAME", "")
|
|
92
|
+
password = args.password or os.environ.get("I_DE_ENERGY_PASSWORD", "")
|
|
83
93
|
|
|
84
94
|
if not username or not password:
|
|
85
95
|
print("Missing username or password", file=sys.stderr)
|
|
86
96
|
sys.exit(1)
|
|
87
97
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
trace_config = aiohttp.TraceConfig()
|
|
99
|
+
if args.trace_http_requests:
|
|
100
|
+
trace_config.on_request_start.append(on_request_start)
|
|
101
|
+
trace_config.on_request_end.append(on_request_end)
|
|
102
|
+
trace_config.on_request_chunk_sent.append(on_request_chunk_sent)
|
|
103
|
+
|
|
104
|
+
if not (
|
|
105
|
+
args.list_contracts
|
|
106
|
+
or args.get_measure
|
|
107
|
+
or args.get_historical_consumption
|
|
108
|
+
or args.get_historical_generation
|
|
109
|
+
or args.get_historical_power_demand
|
|
110
|
+
):
|
|
111
|
+
parser.print_help()
|
|
112
|
+
sys.exit(1)
|
|
92
113
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
114
|
+
async with aiohttp.ClientSession(trace_configs=[trace_config]) as session:
|
|
115
|
+
client = Client(
|
|
116
|
+
username=username, password=password, session=session, logger=logger
|
|
117
|
+
)
|
|
118
|
+
try:
|
|
119
|
+
if data := await get_requested_data():
|
|
120
|
+
print(pprint.pformat(data))
|
|
121
|
+
|
|
122
|
+
except RequestFailedError as e:
|
|
123
|
+
print(f"Request failed: {e}", file=sys.stderr)
|
|
124
|
+
await session.close()
|
|
125
|
+
sys.exit(1)
|
|
126
|
+
|
|
127
|
+
except UserExpiredError as e:
|
|
128
|
+
print(f"User expired, renew auth code via web: {e}", file=sys.stderr)
|
|
129
|
+
await session.close()
|
|
130
|
+
sys.exit(1)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
async def on_request_start(
|
|
134
|
+
session: aiohttp.ClientSession,
|
|
135
|
+
trace_config_ctx: SimpleNamespace,
|
|
136
|
+
params: aiohttp.TraceRequestStartParams,
|
|
137
|
+
):
|
|
138
|
+
print(f"--> Sending request: {params.method} {params.url}")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
async def on_request_end(
|
|
142
|
+
session: aiohttp.ClientSession,
|
|
143
|
+
trace_config_ctx: SimpleNamespace,
|
|
144
|
+
params: aiohttp.TraceRequestStartParams,
|
|
145
|
+
):
|
|
146
|
+
print(
|
|
147
|
+
f"<-- Received response: {params.response}" # ty:ignore[unresolved-attribute]
|
|
148
|
+
)
|
|
96
149
|
|
|
97
|
-
except RequestFailedError as e:
|
|
98
|
-
print(f"Request failed: {e}", file=sys.stderr)
|
|
99
|
-
await session.close()
|
|
100
|
-
sys.exit(1)
|
|
101
150
|
|
|
102
|
-
|
|
151
|
+
async def on_request_chunk_sent(
|
|
152
|
+
session: aiohttp.ClientSession,
|
|
153
|
+
context: SimpleNamespace,
|
|
154
|
+
params: aiohttp.TraceRequestStartParams,
|
|
155
|
+
):
|
|
156
|
+
raw_data = params.chunk.decode("utf-8") # ty:ignore[unresolved-attribute]
|
|
157
|
+
print(f"--> Sending chunk: {raw_data}")
|
|
103
158
|
|
|
104
159
|
|
|
105
160
|
def main():
|
|
106
|
-
|
|
161
|
+
dotenv.load_dotenv()
|
|
162
|
+
return asyncio.run(amain())
|
|
107
163
|
|
|
108
164
|
|
|
109
165
|
if __name__ == "__main__":
|
|
@@ -25,6 +25,20 @@ from typing import Any
|
|
|
25
25
|
import aiohttp
|
|
26
26
|
|
|
27
27
|
from . import parsers
|
|
28
|
+
from .endpoints import (
|
|
29
|
+
_BASE_URL,
|
|
30
|
+
_CONSUMPTION_PERIOD_ENDPOINT,
|
|
31
|
+
_CONTRACT_DETAILS_ENDPOINT,
|
|
32
|
+
_CONTRACT_SELECTION_ENDPOINT,
|
|
33
|
+
_CONTRACTS_ENDPOINT,
|
|
34
|
+
_GENERATION_PERIOD_ENDPOINT,
|
|
35
|
+
_ICP_STATUS_ENDPOINT,
|
|
36
|
+
_KEEP_SESSION,
|
|
37
|
+
_LOGIN_ENDPOINT,
|
|
38
|
+
_MEASURE_ENDPOINT,
|
|
39
|
+
_POWER_DEMAND_LIMITS_ENDPOINT,
|
|
40
|
+
_POWER_DEMAND_PERIOD_ENDPOINT,
|
|
41
|
+
)
|
|
28
42
|
from .types import (
|
|
29
43
|
HistoricalConsumption,
|
|
30
44
|
HistoricalGeneration,
|
|
@@ -32,44 +46,6 @@ from .types import (
|
|
|
32
46
|
Measure,
|
|
33
47
|
)
|
|
34
48
|
|
|
35
|
-
_BASE_URL = "https://www.i-de.es/consumidores/rest"
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
# URLs not confirmed since begining of the times
|
|
39
|
-
#
|
|
40
|
-
_CONTRACTS_ENDPOINT = f"{_BASE_URL}/cto/listaCtos/"
|
|
41
|
-
_CONTRACT_DETAILS_ENDPOINT = f"{_BASE_URL}/detalleCto/detalle/"
|
|
42
|
-
_CONTRACT_SELECTION_ENDPOINT = f"{_BASE_URL}/cto/seleccion/"
|
|
43
|
-
_GENERATION_PERIOD_ENDPOINT = (
|
|
44
|
-
f"{_BASE_URL}/consumoNew/obtenerDatosGeneracionPeriodo/"
|
|
45
|
-
"fechaInicio/{start:%d-%m-%Y}00:00:00/"
|
|
46
|
-
"fechaFinal/{end:%d-%m-%Y}00:00:00/"
|
|
47
|
-
)
|
|
48
|
-
_ICP_STATUS_ENDPOINT = f"{_BASE_URL}/rearmeICP/consultarEstado"
|
|
49
|
-
_LOGIN_ENDPOINT = f"{_BASE_URL}/loginNew/login"
|
|
50
|
-
_MEASURE_ENDPOINT = f"{_BASE_URL}/escenarioNew/obtenerMedicionOnline/24"
|
|
51
|
-
|
|
52
|
-
#
|
|
53
|
-
# URLs reviewed on 2023-06-22
|
|
54
|
-
#
|
|
55
|
-
_CONSUMPTION_PERIOD_ENDPOINT = (
|
|
56
|
-
f"{_BASE_URL}/consumoNew/obtenerDatosConsumoDH/"
|
|
57
|
-
"{start:%d-%m-%Y}/"
|
|
58
|
-
"{end:%d-%m-%Y}/"
|
|
59
|
-
"horas/USU/"
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
_POWER_DEMAND_LIMITS_ENDPOINT = f"{_BASE_URL}/consumoNew/obtenerLimitesFechasPotencia/"
|
|
63
|
-
_POWER_DEMAND_PERIOD_ENDPOINT = (
|
|
64
|
-
f"{_BASE_URL}/consumoNew/obtenerPotenciasMaximasRangoV2/"
|
|
65
|
-
# fecMin and fecMax are provided by _POWER_DEMAND_LIMITS_ENDPOINT
|
|
66
|
-
"{fecMin}/{fecMax}"
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
async def get_session() -> aiohttp.ClientSession:
|
|
71
|
-
return aiohttp.ClientSession()
|
|
72
|
-
|
|
73
49
|
|
|
74
50
|
def auth_required(fn):
|
|
75
51
|
@functools.wraps(fn)
|
|
@@ -95,6 +71,33 @@ class Client:
|
|
|
95
71
|
),
|
|
96
72
|
}
|
|
97
73
|
|
|
74
|
+
# POST /consumidores/rest/loginNew/login HTTP/2
|
|
75
|
+
# Host: www.i-de.es
|
|
76
|
+
# User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0
|
|
77
|
+
# Accept: application/json, text/plain, */*
|
|
78
|
+
# Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
|
|
79
|
+
# Accept-Encoding: gzip, deflate, br, zstd
|
|
80
|
+
# dispositivo: desktop
|
|
81
|
+
# AppVersion: v2
|
|
82
|
+
# Content-Type: application/json; charset=UTF-8
|
|
83
|
+
# Content-Length: 104
|
|
84
|
+
# Origin: https://www.i-de.es
|
|
85
|
+
# Connection: keep-alive
|
|
86
|
+
# Cookie: [redacted]
|
|
87
|
+
# Sec-Fetch-Dest: empty
|
|
88
|
+
# Sec-Fetch-Mode: cors
|
|
89
|
+
# Sec-Fetch-Site: same-origin
|
|
90
|
+
# Priority: u=0
|
|
91
|
+
# Pragma: no-cache
|
|
92
|
+
# Cache-Control: no-cache
|
|
93
|
+
# TE: trailers
|
|
94
|
+
#
|
|
95
|
+
# _HEADERS = {
|
|
96
|
+
# "dispositivo": "desktop",
|
|
97
|
+
# "AppVersion": "v2",
|
|
98
|
+
# "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0",
|
|
99
|
+
# }
|
|
100
|
+
|
|
98
101
|
def __init__(
|
|
99
102
|
self,
|
|
100
103
|
session: aiohttp.ClientSession,
|
|
@@ -178,15 +181,6 @@ class Client:
|
|
|
178
181
|
#
|
|
179
182
|
|
|
180
183
|
async def login(self) -> None:
|
|
181
|
-
"""
|
|
182
|
-
{
|
|
183
|
-
'redirect': 'informacion-del-contrato',
|
|
184
|
-
'zona': 'B',
|
|
185
|
-
'success': 'true',
|
|
186
|
-
'idioma': 'ES',
|
|
187
|
-
'uCcr': ''
|
|
188
|
-
}
|
|
189
|
-
"""
|
|
190
184
|
payload = [
|
|
191
185
|
self.username,
|
|
192
186
|
self.password,
|
|
@@ -199,11 +193,30 @@ class Client:
|
|
|
199
193
|
"s",
|
|
200
194
|
"",
|
|
201
195
|
]
|
|
202
|
-
|
|
196
|
+
# payload = [
|
|
197
|
+
# self.username,
|
|
198
|
+
# self.password,
|
|
199
|
+
# None,
|
|
200
|
+
# "Linux -",
|
|
201
|
+
# "PC",
|
|
202
|
+
# "Firefox 145.0",
|
|
203
|
+
# "0",
|
|
204
|
+
# "",
|
|
205
|
+
# "s",
|
|
206
|
+
# None,
|
|
207
|
+
# None,
|
|
208
|
+
# None,
|
|
209
|
+
# ]
|
|
210
|
+
|
|
211
|
+
await self.request_bytes("GET", _BASE_URL)
|
|
203
212
|
data = await self.request_json("POST", _LOGIN_ENDPOINT, json=payload)
|
|
213
|
+
|
|
204
214
|
if not isinstance(data, dict):
|
|
205
215
|
raise InvalidData(data)
|
|
206
216
|
|
|
217
|
+
if data.get("success", "") == "userExpired":
|
|
218
|
+
raise UserExpiredError(data)
|
|
219
|
+
|
|
207
220
|
if data.get("success", "false") != "true":
|
|
208
221
|
raise CommandError(data)
|
|
209
222
|
|
|
@@ -214,13 +227,15 @@ class Client:
|
|
|
214
227
|
await self.select_contract(self._contract)
|
|
215
228
|
self._logger.info(f"contract '{self._contract}' selected ")
|
|
216
229
|
|
|
230
|
+
# async def verify_is_logged(self) -> bool:
|
|
231
|
+
# sess_info = await self.renew_session()
|
|
232
|
+
# return bool(sess_info.get("usSes"))
|
|
233
|
+
|
|
234
|
+
async def renew_session(self) -> dict:
|
|
235
|
+
return await self.request_json("POST", _KEEP_SESSION)
|
|
236
|
+
|
|
217
237
|
@auth_required
|
|
218
238
|
async def is_icp_ready(self) -> bool:
|
|
219
|
-
"""
|
|
220
|
-
{
|
|
221
|
-
'icp': 'trueConectado'
|
|
222
|
-
}
|
|
223
|
-
"""
|
|
224
239
|
data = await self.request_json("POST", _ICP_STATUS_ENDPOINT)
|
|
225
240
|
ret = data.get("icp", "") == "trueConectado"
|
|
226
241
|
|
|
@@ -228,66 +243,6 @@ class Client:
|
|
|
228
243
|
|
|
229
244
|
@auth_required
|
|
230
245
|
async def get_contract_details(self) -> dict[str, Any]:
|
|
231
|
-
"""
|
|
232
|
-
{
|
|
233
|
-
"ape1Titular": "xxxxxx ",
|
|
234
|
-
"ape2Titular": "xxxxxx ",
|
|
235
|
-
"codCliente": "12345678",
|
|
236
|
-
"codContrato": 123456789.0,
|
|
237
|
-
"codPoblacion": "000000",
|
|
238
|
-
"codProvincia": "00",
|
|
239
|
-
"codPostal": "00000",
|
|
240
|
-
"codSociedad": 3,
|
|
241
|
-
"codTarifaIblda": "92T0",
|
|
242
|
-
"codTension": "09",
|
|
243
|
-
"cups": "ES0000000000000000XY",
|
|
244
|
-
"direccion": "C/ XXXXXXXXXXXXXXXXXX, 12 , 34 00000-XXXXXXXXXXXXXXXXXXXX"
|
|
245
|
-
" - XXXXXXXXX ",
|
|
246
|
-
"dni": "12345678Y",
|
|
247
|
-
"emailFactElec": "xxxxxxxxx@xxxxx.com",
|
|
248
|
-
"esAutoconsumidor": False,
|
|
249
|
-
"esAutogenerador": False,
|
|
250
|
-
"esPeajeDirecto": False,
|
|
251
|
-
"fecAltaContrato": "2000-01-01",
|
|
252
|
-
"fecBajaContrato": 1600000000000,
|
|
253
|
-
"fecUltActua": "22.10.2021",
|
|
254
|
-
"indEstadioPS": 4,
|
|
255
|
-
"indFraElectrn": "N",
|
|
256
|
-
"nomGestorOficina": "XXXXXXXXXXXX ",
|
|
257
|
-
"nomPoblacion": "XXXXXXXXXXXXXXXXXXXX ",
|
|
258
|
-
"nomProvincia": "XXXXXXXXX ",
|
|
259
|
-
"nomTitular": "XXXXX ",
|
|
260
|
-
"numCtaBancaria": "0",
|
|
261
|
-
"numTelefono": " ",
|
|
262
|
-
"numTelefonoAdicional": "123456789",
|
|
263
|
-
"potDia": 0.0,
|
|
264
|
-
"potMaxima": 5750,
|
|
265
|
-
"presion": "1.00",
|
|
266
|
-
"puntoSuministro": "1234567.0",
|
|
267
|
-
"tipAparato": "CN",
|
|
268
|
-
"tipCualificacion": "PP",
|
|
269
|
-
"tipEstadoContrato": "AL",
|
|
270
|
-
"tipo": "A",
|
|
271
|
-
"tipPuntoMedida": None,
|
|
272
|
-
"tipSectorEne": "01",
|
|
273
|
-
"tipSisLectura": "TG",
|
|
274
|
-
"tipSuministro": None,
|
|
275
|
-
"tipUsoEnerg": "",
|
|
276
|
-
"listContador": [
|
|
277
|
-
{
|
|
278
|
-
"fecInstalEquipo": "28-01-2011",
|
|
279
|
-
"propiedadEquipo": "i-DE",
|
|
280
|
-
"tipAparato": "CONTADOR TELEGESTION",
|
|
281
|
-
"tipMarca": "ZIV",
|
|
282
|
-
"numSerieEquipo": 12345678.0,
|
|
283
|
-
}
|
|
284
|
-
],
|
|
285
|
-
"esTelegestionado": True,
|
|
286
|
-
"esTelegestionadoFacturado": True,
|
|
287
|
-
"esTelemedido": False,
|
|
288
|
-
"cau": None,
|
|
289
|
-
}
|
|
290
|
-
"""
|
|
291
246
|
data = await self.request_json("GET", _CONTRACT_DETAILS_ENDPOINT)
|
|
292
247
|
if not data.get("codContrato", False):
|
|
293
248
|
raise InvalidData(data)
|
|
@@ -296,28 +251,6 @@ class Client:
|
|
|
296
251
|
|
|
297
252
|
@auth_required
|
|
298
253
|
async def get_contracts(self) -> list[dict[str, Any]]:
|
|
299
|
-
"""
|
|
300
|
-
{
|
|
301
|
-
'success': true,
|
|
302
|
-
'contratos': [
|
|
303
|
-
{
|
|
304
|
-
'direccion': 'xxxxxxxxxxxxxxxxxxxxxxx',
|
|
305
|
-
'cups': 'ES0000000000000000AB',
|
|
306
|
-
'tipo': 'A',
|
|
307
|
-
'tipUsoEnergiaCorto': '-',
|
|
308
|
-
'tipUsoEnergiaLargo': '-',
|
|
309
|
-
'estContrato': 'Alta',
|
|
310
|
-
'codContrato': '123456789',
|
|
311
|
-
'esTelegestionado': True,
|
|
312
|
-
'presion': '1.00',
|
|
313
|
-
'fecUltActua': '01.01.1970',
|
|
314
|
-
'esTelemedido': False,
|
|
315
|
-
'tipSisLectura': 'TG',
|
|
316
|
-
'estadoAlta': True
|
|
317
|
-
}
|
|
318
|
-
]
|
|
319
|
-
}
|
|
320
|
-
"""
|
|
321
254
|
data = await self.request_json("GET", _CONTRACTS_ENDPOINT)
|
|
322
255
|
if not data.get("success", False):
|
|
323
256
|
raise CommandError(data)
|
|
@@ -338,16 +271,6 @@ class Client:
|
|
|
338
271
|
|
|
339
272
|
@auth_required
|
|
340
273
|
async def get_measure(self) -> Measure:
|
|
341
|
-
"""
|
|
342
|
-
{
|
|
343
|
-
"valMagnitud": "158.64",
|
|
344
|
-
"valInterruptor": "1",
|
|
345
|
-
"valEstado": "09",
|
|
346
|
-
"valLecturaContador": "43167",
|
|
347
|
-
"codSolicitudTGT": "012345678901",
|
|
348
|
-
}
|
|
349
|
-
"""
|
|
350
|
-
|
|
351
274
|
self._logger.debug("Requesting data to the ICP, may take up to a minute.")
|
|
352
275
|
data = await self.request_json("GET", _MEASURE_ENDPOINT)
|
|
353
276
|
|
|
@@ -418,6 +341,9 @@ class Client:
|
|
|
418
341
|
return data
|
|
419
342
|
|
|
420
343
|
limits = await _get_available_interval(self)
|
|
344
|
+
if limits.get("resultado") != "correcto":
|
|
345
|
+
raise CommandError(limits)
|
|
346
|
+
|
|
421
347
|
url = _POWER_DEMAND_PERIOD_ENDPOINT.format(**limits)
|
|
422
348
|
|
|
423
349
|
data = await self.request_json("GET", url)
|
|
@@ -463,3 +389,11 @@ class InvalidContractError(ClientError):
|
|
|
463
389
|
|
|
464
390
|
def __str__(self):
|
|
465
391
|
return f"Invalid contract code: {self.data!r}"
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
class UserExpiredError(ClientError):
|
|
395
|
+
def __init__(self, data):
|
|
396
|
+
self.data = data
|
|
397
|
+
|
|
398
|
+
def __str__(self):
|
|
399
|
+
return f"User expired: {self.data!r}"
|