myelectricaldatapy 2.2.2__tar.gz → 2.2.4__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 (45) hide show
  1. myelectricaldatapy-2.2.2/.github/workflows/pythonpublish.yml → myelectricaldatapy-2.2.4/.github/workflows/python-publish.yml +2 -4
  2. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.github/workflows/release.yml +8 -0
  3. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.pre-commit-config.yaml +4 -4
  4. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/PKG-INFO +2 -1
  5. myelectricaldatapy-2.2.4/_secrets.yaml +3 -0
  6. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/example.py +5 -2
  7. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/auth.py +3 -2
  8. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/myelectricaldata.py +2 -4
  9. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/mypdl.py +45 -4
  10. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy.egg-info/PKG-INFO +2 -1
  11. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy.egg-info/SOURCES.txt +3 -2
  12. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/pyproject.toml +7 -1
  13. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/requirements-dev.txt +5 -4
  14. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/__init__.py +2 -0
  15. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/conftest.py +39 -32
  16. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/test_analytics.py +18 -27
  17. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/test_load_data.py +13 -20
  18. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.flake8 +0 -0
  19. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.github/dependabot.yml +0 -0
  20. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.github/workflows/auto-approve.yml +0 -0
  21. /myelectricaldatapy-2.2.2/.github/workflows/lint.yml → /myelectricaldatapy-2.2.4/.github/workflows/python-lint.yml +0 -0
  22. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.gitignore +0 -0
  23. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/.vscode/settings.json +0 -0
  24. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/LICENSE +0 -0
  25. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/MANIFEST.in +0 -0
  26. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/README.md +0 -0
  27. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/__init__.py +0 -0
  28. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/analytics.py +0 -0
  29. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/const.py +0 -0
  30. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/exceptions.py +0 -0
  31. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy/py.typed +0 -0
  32. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy.egg-info/dependency_links.txt +0 -0
  33. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy.egg-info/requires.txt +0 -0
  34. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/myelectricaldatapy.egg-info/top_level.txt +0 -0
  35. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/requirements.txt +0 -0
  36. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/setup.cfg +0 -0
  37. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/consts.py +0 -0
  38. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/access.json +0 -0
  39. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/address.json +0 -0
  40. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/contract.json +0 -0
  41. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/daily.json +0 -0
  42. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/detail.json +0 -0
  43. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/ecowatt.json +0 -0
  44. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/invalid_access.json +0 -0
  45. {myelectricaldatapy-2.2.2 → myelectricaldatapy-2.2.4}/tests/fixtures/tempo.json +0 -0
@@ -3,10 +3,8 @@ name: Upload Python Package
3
3
  on:
4
4
  release:
5
5
  types: ["published"]
6
-
7
- push:
8
- tags:
9
- - "*.*.*"
6
+ workflow_call:
7
+ workflow_dispatch:
10
8
 
11
9
  jobs:
12
10
  deploy:
@@ -26,3 +26,11 @@ jobs:
26
26
  body: ${{ steps.changelog.outputs.changelog }}
27
27
  draft: false
28
28
  prerelease: false
29
+ publish:
30
+ needs: release
31
+ permissions:
32
+ contents: write
33
+ packages: write
34
+ id-token: write
35
+ if: ${{ ! contains(github.ref_name, '-') }}
36
+ uses: ./.github/workflows/python-publish.yml
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  repos:
3
3
  - repo: https://github.com/astral-sh/ruff-pre-commit
4
- rev: v0.4.5
4
+ rev: v0.8.2
5
5
  hooks:
6
6
  - id: ruff
7
7
  args:
@@ -17,7 +17,7 @@ repos:
17
17
  - --quiet-level=2
18
18
  exclude_types: [csv, json]
19
19
  - repo: https://github.com/pre-commit/pre-commit-hooks
20
- rev: v4.6.0
20
+ rev: v5.0.0
21
21
  hooks:
22
22
  - id: check-executables-have-shebangs
23
23
  stages: [manual]
@@ -33,7 +33,7 @@ repos:
33
33
  hooks:
34
34
  - id: prettier
35
35
  - repo: https://github.com/cdce8p/python-typing-update
36
- rev: v0.6.0
36
+ rev: v0.7.0
37
37
  hooks:
38
38
  # Run `python-typing-update` hook manually from time to time
39
39
  # to update python typing syntax.
@@ -46,7 +46,7 @@ repos:
46
46
  - --force
47
47
  - --keep-updates
48
48
  - repo: https://github.com/pre-commit/mirrors-mypy
49
- rev: v1.10.0
49
+ rev: v1.13.0
50
50
  hooks:
51
51
  - id: mypy
52
52
  args: [--strict, --ignore-missing-imports]
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: myelectricaldatapy
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
4
  Summary: Fetch Linky data from myelectricaldata.fr
5
5
  Author-email: Cyr-ius <cyr-ius@ipocus.net>
6
6
  License: GPL-3
7
+ Project-URL: Homepage, https://github.com/cyr-ius/myelectricaldatapy
7
8
  Keywords: enedis,linky,async,myelectricaldata
8
9
  Classifier: Programming Language :: Python
9
10
  Classifier: Development Status :: 5 - Production/Stable
@@ -0,0 +1,3 @@
1
+ ---
2
+ PDL: "0123456789"
3
+ TOKEN: "xxxxxxxxxxxxxxxxxxxxxxxx"
@@ -52,7 +52,10 @@ async def async_main() -> None:
52
52
  except EnedisException as error:
53
53
  logger.error(error)
54
54
 
55
+ await myPdl.async_close()
56
+
55
57
 
56
58
  if __name__ == "__main__":
57
- loop = asyncio.get_event_loop()
58
- loop.run_until_complete(async_main())
59
+ loop = asyncio.new_event_loop()
60
+ asyncio.set_event_loop(loop)
61
+ asyncio.run(async_main())
@@ -52,9 +52,10 @@ class EnedisAuth:
52
52
  except ClientResponseError:
53
53
  message = contents.decode("utf8")
54
54
  if "application/json" in response.headers.get("Content-Type", ""):
55
+ msg = json.loads(message)
55
56
  if response.status == 409:
56
- raise LimitReached(json.loads(message))
57
- raise EnedisException(json.loads(message))
57
+ raise LimitReached(msg.get("detail", msg))
58
+ raise EnedisException(msg.get("detail", msg))
58
59
  raise EnedisException({"message": message})
59
60
  except (ClientError, socket.gaierror) as error:
60
61
  raise HttpRequestError(
@@ -20,12 +20,10 @@ class Enedis:
20
20
  """Get data of pdl."""
21
21
 
22
22
  def __init__(
23
- self,
24
- token: str,
25
- session: ClientSession = ClientSession(),
26
- timeout: int = TIMEOUT,
23
+ self, token: str, session: ClientSession | None = None, timeout: int = TIMEOUT
27
24
  ) -> None:
28
25
  """Initialize."""
26
+ session = session or ClientSession()
29
27
  self.auth = EnedisAuth(session, token, timeout)
30
28
  self.async_request = self.auth.async_request
31
29
  self.offpeaks: list[str] = []
@@ -84,16 +84,24 @@ CUM_SCH = vol.Schema(
84
84
 
85
85
 
86
86
  class EnedisByPDL:
87
- """PDL class."""
87
+ """Enedis by PDL class.
88
+
89
+ This class allows you to obtain information specific to a connection point.
90
+
91
+ The "set_collect" function allows you to specify the collection parameters from Enedis
92
+ The "async_update_collects" function allows you to perform the calculations
93
+ The result is displayed in the property: stats
94
+ y"""
88
95
 
89
96
  def __init__(
90
97
  self,
91
98
  pdl: str,
92
99
  token: str,
93
- session: ClientSession = ClientSession(),
100
+ session: ClientSession | None = None,
94
101
  timeout: int = TIMEOUT,
95
102
  ) -> None:
96
103
  """Initialize."""
104
+ session = ClientSession() if session is None else session
97
105
  self._api: Enedis = Enedis(token, session, timeout)
98
106
  self.pdl = pdl
99
107
  self._connected: bool = False
@@ -290,7 +298,25 @@ class EnedisByPDL:
290
298
  cum_value: dict[str, Any] | None = None,
291
299
  cum_price: dict[str, Any] | None = None,
292
300
  ) -> None:
293
- """Set parameters for data collect."""
301
+ """Set parameters for data collect.
302
+
303
+ service: "daily_production" or "daily_consumption" or "detail_production" or "detail_consumption"
304
+ start: date of begin to collect data
305
+ end: date of end to collect data
306
+ intervals: offpeak hours range - ex: [("01:00","05:00"),("12:00","14:00")]
307
+ prices: price for standard interval and offpeak interval
308
+ ex: {
309
+ "standard": [float], "offpeak": [float]
310
+ }
311
+ ex: {
312
+ "standard":{"blue":[float],"white":[float],"red":[float]},
313
+ "offpeak":{"blue":[float],"white":[float],"red":[float]}
314
+ }
315
+ cum_sum: price of start
316
+ ex: {"standard":[float], "offpeak":[float]}
317
+ cum_price:
318
+ ex: {"standard":[float], "offpeak":[float]}
319
+ """
294
320
  funcs: dict[str, Callable[..., Any]] = {
295
321
  DAILY_PROD: self._api.async_get_daily_production,
296
322
  DETAIL_PROD: self._api.async_get_details_production,
@@ -314,7 +340,11 @@ class EnedisByPDL:
314
340
  self.has_parameters = True
315
341
 
316
342
  async def async_update_collects(self) -> None:
317
- """Update data to collect."""
343
+ """Update data to collect.
344
+
345
+ It is necessary to value the initial data via the method: set_collects.
346
+ The execution of this method updates the property: stats.
347
+ """
318
348
  checked = True
319
349
  self.has_collected = False
320
350
  for mode, attr in self._params.items():
@@ -328,6 +358,8 @@ class EnedisByPDL:
328
358
  checked = False
329
359
  _LOGGER.error(error)
330
360
  else:
361
+ if dataset is None:
362
+ raise EnedisException("Data collection is empty")
331
363
  data = dataset.get("meter_reading", {}).get("interval_reading", [])
332
364
  if len(data) == 0:
333
365
  raise EnedisException("Data collection is empty")
@@ -338,3 +370,12 @@ class EnedisByPDL:
338
370
  self.tempo = await self._api.async_get_tempo(start, end)
339
371
 
340
372
  self.has_collected = checked
373
+
374
+ async def __aexit__(self, *_exc_info: object) -> None:
375
+ """Async exit."""
376
+ await self.async_close()
377
+
378
+ async def async_close(self) -> None:
379
+ """Close the session."""
380
+ if self._api.auth.session:
381
+ await self._api.auth.session.close()
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: myelectricaldatapy
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
4
  Summary: Fetch Linky data from myelectricaldata.fr
5
5
  Author-email: Cyr-ius <cyr-ius@ipocus.net>
6
6
  License: GPL-3
7
+ Project-URL: Homepage, https://github.com/cyr-ius/myelectricaldatapy
7
8
  Keywords: enedis,linky,async,myelectricaldata
8
9
  Classifier: Programming Language :: Python
9
10
  Classifier: Development Status :: 5 - Production/Stable
@@ -4,14 +4,15 @@
4
4
  LICENSE
5
5
  MANIFEST.in
6
6
  README.md
7
+ _secrets.yaml
7
8
  example.py
8
9
  pyproject.toml
9
10
  requirements-dev.txt
10
11
  requirements.txt
11
12
  .github/dependabot.yml
12
13
  .github/workflows/auto-approve.yml
13
- .github/workflows/lint.yml
14
- .github/workflows/pythonpublish.yml
14
+ .github/workflows/python-lint.yml
15
+ .github/workflows/python-publish.yml
15
16
  .github/workflows/release.yml
16
17
  .vscode/settings.json
17
18
  myelectricaldatapy/__init__.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "myelectricaldatapy"
7
- dynamic = ["version"]
7
+ dynamic = ["version"]
8
8
  license = {text = "GPL-3"}
9
9
  description = "Fetch Linky data from myelectricaldata.fr"
10
10
  readme = "README.md"
@@ -31,8 +31,14 @@ dependencies = [
31
31
  "voluptuous>=0.13.1",
32
32
  ]
33
33
 
34
+ [project.urls]
35
+ Homepage = "https://github.com/cyr-ius/myelectricaldatapy"
36
+
34
37
  [tool.setuptools_scm]
35
38
 
39
+ [tool.pytest.ini_options]
40
+ asyncio_mode = "auto"
41
+
36
42
  [tool.ruff.lint.flake8-pytest-style]
37
43
  fixture-parentheses = false
38
44
 
@@ -4,10 +4,11 @@
4
4
  codespell
5
5
  mypy
6
6
  pre-commit
7
- python-typing-update
8
- ruff
9
- yamllint
10
- types-requests
11
7
  pytest
12
8
  pytest-asyncio
9
+ python-typing-update
10
+ ruff
13
11
  setuptools_scm
12
+ types-requests
13
+ yamllint
14
+ freezegun
@@ -1,5 +1,7 @@
1
1
  """Tests for myelectricaldata."""
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  from pathlib import Path
4
6
 
5
7
 
@@ -1,5 +1,7 @@
1
1
  """Test helpers for MyElectricalData."""
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  from collections.abc import Generator
4
6
  import json
5
7
  from typing import Any
@@ -7,9 +9,7 @@ from unittest.mock import AsyncMock, patch
7
9
 
8
10
  import pytest
9
11
 
10
- import myelectricaldatapy
11
-
12
- from . import load_fixture
12
+ from tests import load_fixture
13
13
 
14
14
 
15
15
  @pytest.fixture(name="mock_detail")
@@ -66,35 +66,37 @@ def mock_enedis(
66
66
  """Mock a successful connection."""
67
67
 
68
68
  with (
69
- patch.object(
70
- myelectricaldatapy.Enedis,
71
- "async_get_daily_consumption",
69
+ patch(
70
+ "myelectricaldatapy.Enedis.async_get_daily_consumption",
72
71
  return_value=mock_daily,
73
72
  ),
74
- patch.object(
75
- myelectricaldatapy.Enedis,
76
- "async_get_daily_production",
73
+ patch(
74
+ "myelectricaldatapy.Enedis.async_get_daily_production",
77
75
  return_value=mock_daily,
78
76
  ),
79
- patch.object(
80
- myelectricaldatapy.Enedis,
81
- "async_get_details_consumption",
77
+ patch(
78
+ "myelectricaldatapy.Enedis.async_get_details_consumption",
82
79
  return_value=mock_detail,
83
80
  ),
84
- patch.object(
85
- myelectricaldatapy.Enedis, "async_valid_access", return_value=mock_access
81
+ patch(
82
+ "myelectricaldatapy.Enedis.async_valid_access",
83
+ return_value=mock_access,
86
84
  ),
87
- patch.object(
88
- myelectricaldatapy.Enedis, "async_get_contract", return_value=mock_contract
85
+ patch(
86
+ "myelectricaldatapy.Enedis.async_get_contract",
87
+ return_value=mock_contract,
89
88
  ),
90
- patch.object(
91
- myelectricaldatapy.Enedis, "async_get_address", return_value=mock_address
89
+ patch(
90
+ "myelectricaldatapy.Enedis.async_get_address",
91
+ return_value=mock_address,
92
92
  ),
93
- patch.object(
94
- myelectricaldatapy.Enedis, "async_get_tempo", return_value=mock_tempo
93
+ patch(
94
+ "myelectricaldatapy.Enedis.async_get_tempo",
95
+ return_value=mock_tempo,
95
96
  ),
96
- patch.object(
97
- myelectricaldatapy.Enedis, "async_get_ecowatt", return_value=mock_ecowatt
97
+ patch(
98
+ "myelectricaldatapy.Enedis.async_get_ecowatt",
99
+ return_value=mock_ecowatt,
98
100
  ),
99
101
  ):
100
102
  yield AsyncMock()
@@ -106,20 +108,25 @@ def mock_base(
106
108
  ) -> Generator[AsyncMock, None, None]:
107
109
  """Mock a successful connection."""
108
110
  with (
109
- patch.object(
110
- myelectricaldatapy.Enedis, "async_valid_access", return_value=mock_access
111
+ patch(
112
+ "myelectricaldatapy.Enedis.async_valid_access",
113
+ return_value=mock_access,
111
114
  ),
112
- patch.object(
113
- myelectricaldatapy.Enedis, "async_get_contract", return_value=mock_contract
115
+ patch(
116
+ "myelectricaldatapy.Enedis.async_get_contract",
117
+ return_value=mock_contract,
114
118
  ),
115
- patch.object(
116
- myelectricaldatapy.Enedis, "async_get_address", return_value=mock_address
119
+ patch(
120
+ "myelectricaldatapy.Enedis.async_get_address",
121
+ return_value=mock_address,
117
122
  ),
118
- patch.object(
119
- myelectricaldatapy.Enedis, "async_get_tempo", return_value=mock_tempo
123
+ patch(
124
+ "myelectricaldatapy.Enedis.async_get_tempo",
125
+ return_value=mock_tempo,
120
126
  ),
121
- patch.object(
122
- myelectricaldatapy.Enedis, "async_get_ecowatt", return_value=mock_ecowatt
127
+ patch(
128
+ "myelectricaldatapy.Enedis.async_get_ecowatt",
129
+ return_value=mock_ecowatt,
123
130
  ),
124
131
  ):
125
132
  yield AsyncMock()
@@ -6,6 +6,7 @@ from datetime import datetime as dt
6
6
  from typing import Any
7
7
  from unittest.mock import Mock, patch
8
8
 
9
+ from aiohttp import ClientSession
9
10
  from freezegun import freeze_time
10
11
  import pytest
11
12
 
@@ -16,10 +17,9 @@ from .consts import PDL, TOKEN
16
17
 
17
18
 
18
19
  @freeze_time("2023-03-01")
19
- @pytest.mark.asyncio
20
20
  async def test_compute(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
21
21
  """Test standard."""
22
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
22
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
23
23
  api.set_collects("consumption_load_curve")
24
24
  await api.async_update()
25
25
  resultat = api.stats["consumption"]
@@ -27,7 +27,7 @@ async def test_compute(mock_enedis: Mock) -> None: # pylint: disable=unused-arg
27
27
  assert resultat[0]["notes"] == "standard"
28
28
  assert resultat[0]["value"] == 1.296
29
29
 
30
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
30
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
31
31
  api.set_collects("daily_consumption")
32
32
  await api.async_update()
33
33
  resultat = api.stats["consumption"]
@@ -37,7 +37,6 @@ async def test_compute(mock_enedis: Mock) -> None: # pylint: disable=unused-arg
37
37
 
38
38
 
39
39
  @freeze_time("2023-03-01")
40
- @pytest.mark.asyncio
41
40
  async def test_without_offpeak(
42
41
  mock_enedis: Mock,
43
42
  ) -> None: # pylint: disable=unused-argument
@@ -45,7 +44,7 @@ async def test_without_offpeak(
45
44
  await mock_enedis()
46
45
  prices: dict[str, Any] = {"standard": {"price": 0.17}}
47
46
  # Test standard price
48
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
47
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
49
48
  api.set_collects("consumption_load_curve", prices=prices)
50
49
  await api.async_update_collects()
51
50
  resultat = api.stats["consumption"]
@@ -62,14 +61,13 @@ async def test_without_offpeak(
62
61
 
63
62
 
64
63
  @freeze_time("2023-03-01")
65
- @pytest.mark.asyncio
66
64
  async def test_with_offpeak(
67
65
  mock_enedis: Mock, # pylint: disable=unused-argument
68
66
  ) -> None:
69
67
  """Test without offpeak , with price."""
70
68
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
71
69
  prices: dict[str, Any] = {"standard": {"price": 0.17}, "offpeak": {"price": 0.18}}
72
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
70
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
73
71
  api.set_collects("consumption_load_curve", prices=prices, intervals=intervals)
74
72
  await api.async_update_collects()
75
73
  resultat = api.stats["consumption"]
@@ -81,7 +79,7 @@ async def test_with_offpeak(
81
79
  print(resultat)
82
80
 
83
81
  # Without cums
84
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
82
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
85
83
  api.set_collects("consumption_load_curve", prices=prices, intervals=intervals)
86
84
  await api.async_update_collects()
87
85
  resultat = api.stats["consumption"]
@@ -93,7 +91,7 @@ async def test_with_offpeak(
93
91
  print(resultat)
94
92
 
95
93
  # Without price
96
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
94
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
97
95
  api.set_collects("consumption_load_curve", intervals=intervals)
98
96
  await api.async_update_collects()
99
97
  resultat = api.stats["consumption"]
@@ -102,7 +100,7 @@ async def test_with_offpeak(
102
100
  print(resultat)
103
101
 
104
102
  # Daily
105
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
103
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
106
104
  api.set_collects("daily_consumption", prices=prices, intervals=intervals)
107
105
  await api.async_update_collects()
108
106
  resultat = api.stats["consumption"]
@@ -112,14 +110,13 @@ async def test_with_offpeak(
112
110
 
113
111
 
114
112
  @freeze_time("2023-03-01")
115
- @pytest.mark.asyncio
116
113
  async def test_daily_with_offpeak(
117
114
  mock_enedis: Mock, # pylint: disable=unused-argument
118
115
  ) -> None:
119
116
  """Test daily with offpeak."""
120
117
  prices: dict[str, Any] = {"standard": {"price": 0.17}, "offpeak": {"price": 0.18}}
121
118
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
122
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
119
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
123
120
  api.set_collects("daily_consumption", prices=prices, intervals=intervals)
124
121
  await api.async_update_collects()
125
122
  resultat = api.stats["consumption"]
@@ -128,7 +125,6 @@ async def test_daily_with_offpeak(
128
125
 
129
126
 
130
127
  @freeze_time("2023-03-01")
131
- @pytest.mark.asyncio
132
128
  async def test_compare(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
133
129
  """Test details compare."""
134
130
  prices: dict[str, Any] = {"standard": {"price": 0.17}, "offpeak": {"price": 0.18}}
@@ -141,7 +137,7 @@ async def test_compare(mock_enedis: Mock) -> None: # pylint: disable=unused-arg
141
137
  "offpeak": {"sum_price": 0},
142
138
  }
143
139
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
144
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
140
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
145
141
  api.set_collects(
146
142
  "consumption_load_curve",
147
143
  prices=prices,
@@ -198,14 +194,13 @@ async def test_compare(mock_enedis: Mock) -> None: # pylint: disable=unused-arg
198
194
 
199
195
 
200
196
  @freeze_time("2023-03-01")
201
- @pytest.mark.asyncio
202
197
  async def test_cumsums(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
203
198
  """Test cumulative summary."""
204
199
  prices: dict[str, Any] = {"standard": {"price": 0.17}, "offpeak": {"price": 0.18}}
205
200
  cumsum_value: dict[str, Any] = {"standard": 100, "offpeak": 1000}
206
201
  cumsum_price: dict[str, Any] = {"standard": 50, "offpeak": 75}
207
202
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
208
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
203
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
209
204
  api.set_collects(
210
205
  "consumption_load_curve",
211
206
  start=dt.strptime("2023-03-01", "%Y-%m-%d"),
@@ -226,12 +221,11 @@ async def test_cumsums(mock_enedis: Mock) -> None: # pylint: disable=unused-arg
226
221
 
227
222
 
228
223
  @freeze_time("2023-03-01")
229
- @pytest.mark.asyncio
230
224
  async def test_extra_date(mock_base: Mock, mock_detail) -> None: # pylint: disable=unused-argument
231
225
  """Test cumulative summary."""
232
226
  prices: dict[str, Any] = {"standard": {"price": 0.17}, "offpeak": {"price": 0.18}}
233
227
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
234
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
228
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
235
229
  api.set_collects(
236
230
  "consumption_load_curve",
237
231
  start=dt.strptime("2023-03-01", "%Y-%m-%d"),
@@ -264,7 +258,6 @@ async def test_extra_date(mock_base: Mock, mock_detail) -> None: # pylint: disa
264
258
 
265
259
 
266
260
  @freeze_time("2023-3-1")
267
- @pytest.mark.asyncio
268
261
  async def test_tempo(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
269
262
  """Test tempo pricings."""
270
263
  prices: dict[str, Any] = {
@@ -282,7 +275,7 @@ async def test_tempo(mock_enedis: Mock) -> None: # pylint: disable=unused-argum
282
275
  cumsum_value: dict[str, Any] = {"standard": 100, "offpeak": 1000}
283
276
  cumsum_price: dict[str, Any] = {"standard": 50, "offpeak": 75}
284
277
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
285
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
278
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
286
279
  api.set_collects(
287
280
  "consumption_load_curve",
288
281
  prices=prices,
@@ -300,7 +293,7 @@ async def test_tempo(mock_enedis: Mock) -> None: # pylint: disable=unused-argum
300
293
  assert api.tempo_day == "blue"
301
294
 
302
295
  # Check Daily -> compute not possible.
303
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
296
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
304
297
  api.set_collects("daily_production", prices=prices, intervals=intervals)
305
298
  await api.async_update_collects()
306
299
  resultat = api.stats.get("production")
@@ -308,21 +301,20 @@ async def test_tempo(mock_enedis: Mock) -> None: # pylint: disable=unused-argum
308
301
 
309
302
 
310
303
  @freeze_time("2023-03-01")
311
- @pytest.mark.asyncio
312
304
  async def test_standard_offpeak_cumsum(
313
305
  mock_enedis: Mock, # pylint: disable=unused-argument
314
306
  ) -> None:
315
307
  """Test with offpeak and cumsum."""
316
308
  prices: dict[str, Any] = {"standard": {"price": 0.5}, "offpeak": {"price": 1}}
317
309
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
318
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
310
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
319
311
  api.set_collects("consumption_load_curve", prices=prices, intervals=intervals)
320
312
  await api.async_update_collects()
321
313
  resultat = api.stats["consumption"]
322
314
  assert resultat[0]["value"] == 1.079
323
315
 
324
316
  # Test daily data , check ignore intervals.
325
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
317
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
326
318
  api.set_collects("daily_consumption", prices=prices, intervals=intervals)
327
319
  await api.async_update_collects()
328
320
  resultat = api.stats["consumption"]
@@ -332,7 +324,7 @@ async def test_standard_offpeak_cumsum(
332
324
  @pytest.mark.asyncio
333
325
  async def test_start_date(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
334
326
  """Test with start_date."""
335
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
327
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
336
328
  api.set_collects(
337
329
  "consumption_load_curve", start=dt.strptime("2023-3-7", "%Y-%m-%d")
338
330
  )
@@ -349,13 +341,12 @@ async def test_start_date(mock_enedis: Mock) -> None: # pylint: disable=unused-
349
341
 
350
342
 
351
343
  @freeze_time("2023-3-1")
352
- @pytest.mark.asyncio
353
344
  async def test_twice_call(
354
345
  mock_enedis: Mock, # pylint: disable=unused-argument
355
346
  ) -> None:
356
347
  """Tests raise exception."""
357
348
  intervals = [("01:30:00", "08:00:00"), ("12:30:00", "14:00:00")]
358
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
349
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
359
350
  api.set_collects("consumption_load_curve", intervals=intervals)
360
351
  api.set_collects("daily_production")
361
352
  await api.async_update()
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  from datetime import datetime as dt
6
6
  from unittest.mock import Mock, patch
7
7
 
8
+ from aiohttp import ClientSession
8
9
  from freezegun import freeze_time
9
10
  import pytest
10
11
 
@@ -15,40 +16,37 @@ from .consts import PDL, TOKEN
15
16
 
16
17
 
17
18
  @freeze_time("2023-01-23")
18
- @pytest.mark.asyncio
19
19
  async def test_ecowatt(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
20
20
  """Test get ecowatt."""
21
- api = Enedis(token=TOKEN)
21
+ api = Enedis(token=TOKEN, session=ClientSession())
22
22
  resultat = await api.async_get_ecowatt()
23
23
  assert resultat["2023-01-22"]["value"] == 1
24
24
 
25
- mypdl = EnedisByPDL(pdl=PDL, token=TOKEN)
25
+ mypdl = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
26
26
  mypdl.ecowatt_subscription(True)
27
27
  await mypdl.async_update()
28
28
  assert mypdl.ecowatt_day["message"] == "Pas d’alerte."
29
29
 
30
30
 
31
- @pytest.mark.asyncio
32
31
  @pytest.mark.parametrize("mock_ecowatt", [True], indirect=True)
33
32
  async def test_invalid_ecowatt(mock_enedis: Mock, mock_ecowatt: bool) -> None:
34
33
  """Test ecowatt."""
35
34
  with patch.object(
36
35
  myelectricaldatapy.Enedis, "async_get_ecowatt", return_value=mock_ecowatt
37
36
  ):
38
- api = Enedis(token=TOKEN)
37
+ api = Enedis(token=TOKEN, session=ClientSession())
39
38
  resultat = await api.async_get_ecowatt()
40
39
  assert resultat.get("2023-01-22") is None
41
40
 
42
41
 
43
42
  @freeze_time("2023-3-3")
44
- @pytest.mark.asyncio
45
43
  async def test_tempoday(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
46
44
  """Test get tempo day."""
47
- api = Enedis(token=TOKEN)
45
+ api = Enedis(token=TOKEN, session=ClientSession())
48
46
  resultat = await api.async_get_tempo()
49
47
  assert resultat["2023-3-1"] == "blue"
50
48
 
51
- mypdl = EnedisByPDL(pdl=PDL, token=TOKEN)
49
+ mypdl = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
52
50
  mypdl.set_collects("consumption_load_curve")
53
51
  mypdl.tempo_subscription(True)
54
52
  await mypdl.async_update()
@@ -56,10 +54,9 @@ async def test_tempoday(mock_enedis: Mock) -> None: # pylint: disable=unused-ar
56
54
  assert mypdl.tempo_day == "blue"
57
55
 
58
56
 
59
- @pytest.mark.asyncio
60
57
  async def test_valid_access(mock_enedis: Mock) -> None: # pylint: disable=unused-argument
61
58
  """Test access."""
62
- api = Enedis(token=TOKEN)
59
+ api = Enedis(token=TOKEN, session=ClientSession())
63
60
  resultat = await api.async_valid_access(PDL)
64
61
  assert resultat["valid"] is True
65
62
 
@@ -67,7 +64,6 @@ async def test_valid_access(mock_enedis: Mock) -> None: # pylint: disable=unuse
67
64
  assert resultat is True
68
65
 
69
66
 
70
- @pytest.mark.asyncio
71
67
  @pytest.mark.parametrize("mock_access", [True], indirect=True)
72
68
  async def test_invalid_access(
73
69
  mock_enedis: Mock,
@@ -77,18 +73,17 @@ async def test_invalid_access(
77
73
  with patch.object(
78
74
  myelectricaldatapy.Enedis, "async_valid_access", return_value=mock_access
79
75
  ):
80
- api = Enedis(token=TOKEN)
76
+ api = Enedis(token=TOKEN, session=ClientSession())
81
77
  resultat = await api.async_valid_access(PDL)
82
78
  assert resultat["quota_reached"] is True
83
79
 
84
80
 
85
- @pytest.mark.asyncio
86
81
  async def test_fetch_data(mock_detail) -> None:
87
82
  """Test fetch data."""
88
83
  with patch.object(
89
84
  myelectricaldatapy.auth.EnedisAuth, "async_request", return_value=mock_detail
90
85
  ):
91
- api = Enedis(token=TOKEN)
86
+ api = Enedis(token=TOKEN, session=ClientSession())
92
87
  resultat = await api.async_fetch_datas(
93
88
  service="comsumption_load_curve",
94
89
  pdl=PDL,
@@ -101,7 +96,6 @@ async def test_fetch_data(mock_detail) -> None:
101
96
  )
102
97
 
103
98
 
104
- @pytest.mark.asyncio
105
99
  async def test_force_refresh(
106
100
  mock_enedis: Mock, # pylint: disable=unused-argument
107
101
  ) -> None:
@@ -115,7 +109,7 @@ async def test_force_refresh(
115
109
  with patch.object(
116
110
  myelectricaldatapy.Enedis, "async_valid_access", return_value=access
117
111
  ):
118
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
112
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
119
113
  api.set_collects("consumption_load_curve")
120
114
  await api.async_update()
121
115
  save_refresh = api.last_refresh
@@ -125,7 +119,6 @@ async def test_force_refresh(
125
119
  assert api.last_refresh != save_refresh
126
120
 
127
121
 
128
- @pytest.mark.asyncio
129
122
  async def test_exception(
130
123
  mock_enedis: Mock, # pylint: disable=unused-argument
131
124
  ) -> None:
@@ -135,7 +128,7 @@ async def test_exception(
135
128
  "async_valid_access",
136
129
  side_effect=LimitReached(500, {"detail": "Limit reached"}),
137
130
  ):
138
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
131
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
139
132
  api.set_collects("consumption_load_curve")
140
133
  try:
141
134
  await api.async_update()
@@ -149,7 +142,7 @@ async def test_exception(
149
142
  "async_get_details_consumption",
150
143
  side_effect=LimitReached(500, {"detail": "Limit reached"}),
151
144
  ):
152
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
145
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
153
146
  api.set_collects("consumption_load_curve")
154
147
  try:
155
148
  await api.async_update()
@@ -163,7 +156,7 @@ async def test_exception(
163
156
  "async_get_details_consumption",
164
157
  side_effect=EnedisException(500, {"detail": "Error"}),
165
158
  ):
166
- api = EnedisByPDL(pdl=PDL, token=TOKEN)
159
+ api = EnedisByPDL(pdl=PDL, token=TOKEN, session=ClientSession())
167
160
  api.set_collects("consumption_load_curve")
168
161
  api.set_collects("daily_production")
169
162
  try: