ideenergy 2.0.0rc2__tar.gz → 2.0.1.dev2__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.
Files changed (23) hide show
  1. ideenergy-2.0.1.dev2/PKG-INFO +36 -0
  2. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/README.md +6 -5
  3. ideenergy-2.0.1.dev2/ideenergy/__init__.py +59 -0
  4. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy/cli.py +75 -19
  5. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy/client.py +166 -176
  6. ideenergy-2.0.1.dev2/ideenergy/endpoints.py +170 -0
  7. ideenergy-2.0.1.dev2/ideenergy/mock.py +217 -0
  8. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy/parsers.py +3 -0
  9. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy/types.py +0 -1
  10. ideenergy-2.0.1.dev2/ideenergy.egg-info/PKG-INFO +36 -0
  11. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy.egg-info/SOURCES.txt +2 -0
  12. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy.egg-info/requires.txt +1 -0
  13. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/pyproject.toml +10 -3
  14. ideenergy-2.0.0rc2/PKG-INFO +0 -709
  15. ideenergy-2.0.0rc2/ideenergy/__init__.py +0 -172
  16. ideenergy-2.0.0rc2/ideenergy.egg-info/PKG-INFO +0 -709
  17. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/LICENSE +0 -0
  18. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy/__main__.py +0 -0
  19. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy.egg-info/dependency_links.txt +0 -0
  20. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy.egg-info/entry_points.txt +0 -0
  21. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/ideenergy.egg-info/top_level.txt +0 -0
  22. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/setup.cfg +0 -0
  23. {ideenergy-2.0.0rc2 → ideenergy-2.0.1.dev2}/tests/test_client.py +0 -0
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.4
2
+ Name: ideenergy
3
+ Version: 2.0.1.dev2
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
+ ![GitHub Release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/ldotlopez/ideenergy)
27
+ [![Create release](https://github.com/ldotlopez/ideenergy/actions/workflows/release.yml/badge.svg)](https://github.com/ldotlopez/ideenergy/actions/workflows/release.yml)
28
+ [![Upload Python package](https://github.com/ldotlopez/ideenergy/actions/workflows/publish.yml/badge.svg)](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
- ![GitHub Release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/ldotlopez/ideenergy?include_prereleases)
6
- [![CodeQL](https://github.com/ldotlopez/ideenergy/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ldotlopez/ideenergy/actions/workflows/codeql-analysis.yml)
7
- [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
7
+
8
+ ![GitHub Release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/ldotlopez/ideenergy)
9
+ [![Create release](https://github.com/ldotlopez/ideenergy/actions/workflows/release.yml/badge.svg)](https://github.com/ldotlopez/ideenergy/actions/workflows/release.yml)
10
+ [![Upload Python package](https://github.com/ldotlopez/ideenergy/actions/workflows/publish.yml/badge.svg)](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)
@@ -0,0 +1,59 @@
1
+ # Copyright (C) 2021-2022 Luis López <luis@cuarentaydos.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
16
+ # USA.
17
+
18
+
19
+ from .client import (
20
+ Client,
21
+ ClientError,
22
+ CommandError,
23
+ InvalidContractError,
24
+ InvalidData,
25
+ RequestFailedError,
26
+ UserExpiredError,
27
+ )
28
+ from .mock import MockClient
29
+ from .types import (
30
+ ConsumptionForPeriod,
31
+ DemandAtInstant,
32
+ HistoricalConsumption,
33
+ HistoricalGeneration,
34
+ HistoricalPowerDemand,
35
+ Measure,
36
+ PeriodValue,
37
+ )
38
+
39
+ # def sanitize_address(address):
40
+ # return " ".join([x.strip().capitalize() for x in address.split(" ") if x])
41
+
42
+
43
+ __all__ = [
44
+ "Client",
45
+ "ClientError",
46
+ "CommandError",
47
+ "ConsumptionForPeriod",
48
+ "DemandAtInstant",
49
+ "HistoricalConsumption",
50
+ "HistoricalGeneration",
51
+ "HistoricalPowerDemand",
52
+ "InvalidContractError",
53
+ "InvalidData",
54
+ "Measure",
55
+ "MockClient",
56
+ "PeriodValue",
57
+ "RequestFailedError",
58
+ "UserExpiredError",
59
+ ]
@@ -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 Client, RequestFailedError, get_credentials, get_session
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 _main():
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, password = get_credentials(args)
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
- session = await get_session()
89
- client = Client(
90
- username=username, password=password, session=session, logger=logger
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
- try:
94
- if data := await get_requested_data():
95
- print(pprint.pformat(data))
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
- await session.close()
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
- return asyncio.run(_main())
161
+ dotenv.load_dotenv()
162
+ return asyncio.run(amain())
107
163
 
108
164
 
109
165
  if __name__ == "__main__":