aiopvpc-ng 5.0.1__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 (43) hide show
  1. aiopvpc_ng-5.0.1/.github/workflows/main.yml +43 -0
  2. aiopvpc_ng-5.0.1/.github/workflows/publish.yml +35 -0
  3. aiopvpc_ng-5.0.1/.gitignore +103 -0
  4. aiopvpc_ng-5.0.1/.pre-commit-config.yaml +37 -0
  5. aiopvpc_ng-5.0.1/AGENTS.md +101 -0
  6. aiopvpc_ng-5.0.1/CHANGELOG.md +285 -0
  7. aiopvpc_ng-5.0.1/LICENSE +21 -0
  8. aiopvpc_ng-5.0.1/PKG-INFO +73 -0
  9. aiopvpc_ng-5.0.1/README.md +50 -0
  10. aiopvpc_ng-5.0.1/aiopvpc/__init__.py +15 -0
  11. aiopvpc_ng-5.0.1/aiopvpc/const.py +112 -0
  12. aiopvpc_ng-5.0.1/aiopvpc/ha_helpers.py +51 -0
  13. aiopvpc_ng-5.0.1/aiopvpc/parser.py +176 -0
  14. aiopvpc_ng-5.0.1/aiopvpc/prices.py +152 -0
  15. aiopvpc_ng-5.0.1/aiopvpc/pvpc_data.py +420 -0
  16. aiopvpc_ng-5.0.1/aiopvpc/pvpc_tariff.py +55 -0
  17. aiopvpc_ng-5.0.1/aiopvpc/utils.py +14 -0
  18. aiopvpc_ng-5.0.1/pyproject.toml +95 -0
  19. aiopvpc_ng-5.0.1/tests/__init__.py +1 -0
  20. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1001_2021_06_01.json +1007 -0
  21. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1001_2021_10_30.json +1007 -0
  22. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1001_2021_10_31.json +1047 -0
  23. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1001_2024_03_09.json +1007 -0
  24. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_10211_2021_10_30.json +223 -0
  25. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_10211_2021_10_31.json +231 -0
  26. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_10211_2024_03_09.json +223 -0
  27. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1739_2021_10_30.json +223 -0
  28. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1739_2021_10_31.json +231 -0
  29. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1739_2024_03_09.json +223 -0
  30. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_1900_2024_03_09.json +1007 -0
  31. aiopvpc_ng-5.0.1/tests/api_examples/PRICES_ESIOS_2108_2024_03_09.json +1007 -0
  32. aiopvpc_ng-5.0.1/tests/api_examples/PVPC_CURV_DD_2021_06_01.json +604 -0
  33. aiopvpc_ng-5.0.1/tests/api_examples/PVPC_CURV_DD_2021_10_30.json +604 -0
  34. aiopvpc_ng-5.0.1/tests/api_examples/PVPC_CURV_DD_2021_10_31.json +629 -0
  35. aiopvpc_ng-5.0.1/tests/api_examples/PVPC_CURV_DD_2022_03_27.json +579 -0
  36. aiopvpc_ng-5.0.1/tests/conftest.py +169 -0
  37. aiopvpc_ng-5.0.1/tests/test_ha_helpers.py +131 -0
  38. aiopvpc_ng-5.0.1/tests/test_pvpc.py +183 -0
  39. aiopvpc_ng-5.0.1/tests/test_pvpc_parsing.py +229 -0
  40. aiopvpc_ng-5.0.1/tests/test_pvpc_zones.py +70 -0
  41. aiopvpc_ng-5.0.1/tests/test_real_api_calls.py +63 -0
  42. aiopvpc_ng-5.0.1/tests/test_tariff_attributes.py +94 -0
  43. aiopvpc_ng-5.0.1/uv.lock +1449 -0
@@ -0,0 +1,43 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ python-version: ["3.11", "3.12", "3.13", "3.14"]
18
+ steps:
19
+ - name: Check out repository
20
+ uses: actions/checkout@v7
21
+
22
+ - name: Set up uv and Python ${{ matrix.python-version }}
23
+ uses: astral-sh/setup-uv@v10.4.0
24
+ with:
25
+ enable-cache: true
26
+ python-version: ${{ matrix.python-version }}
27
+
28
+ - name: Install dependencies
29
+ run: uv sync --locked
30
+
31
+ - name: Lint and format check
32
+ run: |
33
+ uv run ruff check --no-fix .
34
+ uv run ruff format --check .
35
+
36
+ - name: Type check
37
+ run: uv run mypy aiopvpc tests
38
+
39
+ - name: Run tests
40
+ run: uv run pytest --cov-report xml:coverage.xml
41
+
42
+ - name: Build package
43
+ run: uv build
@@ -0,0 +1,35 @@
1
+ name: Publish package to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ contents: read
14
+ id-token: write
15
+ steps:
16
+ - name: Check out repository
17
+ uses: actions/checkout@v7
18
+
19
+ - name: Set up uv and Python
20
+ uses: astral-sh/setup-uv@v10.4.0
21
+ with:
22
+ enable-cache: true
23
+ python-version: "3.12"
24
+
25
+ - name: Install dependencies
26
+ run: uv sync --locked
27
+
28
+ - name: Run tests
29
+ run: uv run pytest
30
+
31
+ - name: Build distributions
32
+ run: uv build
33
+
34
+ - name: Publish release distributions to PyPI
35
+ run: uv publish --trusted-publishing always
@@ -0,0 +1,103 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ env/
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ pip-wheel-metadata/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ .idea
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ .hypothesis/
50
+
51
+ # Translations
52
+ *.mo
53
+ *.pot
54
+
55
+ # Django stuff:
56
+ *.log
57
+ local_settings.py
58
+
59
+ # Flask stuff:
60
+ instance/
61
+ .webassets-cache
62
+
63
+ # Scrapy stuff:
64
+ .scrapy
65
+
66
+ # Sphinx documentation
67
+ docs/_build/
68
+
69
+ # PyBuilder
70
+ target/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # pyenv
76
+ .python-version
77
+
78
+ # celery beat schedule file
79
+ celerybeat-schedule
80
+
81
+ # SageMath parsed files
82
+ *.sage.py
83
+
84
+ # dotenv
85
+ .env
86
+
87
+ # virtualenv
88
+ .venv
89
+ venv/
90
+ ENV/
91
+
92
+ # Spyder project settings
93
+ .spyderproject
94
+ .spyproject
95
+
96
+ # Rope project settings
97
+ .ropeproject
98
+
99
+ # mkdocs documentation
100
+ /site
101
+
102
+ # mypy
103
+ .mypy_cache/
@@ -0,0 +1,37 @@
1
+ minimum_pre_commit_version: "4.0.0"
2
+ repos:
3
+ - repo: https://github.com/astral-sh/ruff-pre-commit
4
+ rev: v0.17.6
5
+ hooks:
6
+ - id: ruff-check
7
+ args:
8
+ - --fix
9
+ - id: ruff-format
10
+ - repo: https://github.com/pre-commit/pre-commit-hooks
11
+ rev: v6.0.0
12
+ hooks:
13
+ - id: end-of-file-fixer
14
+ - id: trailing-whitespace
15
+ - id: check-json
16
+ - id: check-toml
17
+ - id: check-yaml
18
+ - repo: https://github.com/rbubley/mirrors-prettier
19
+ rev: v3.10.1
20
+ hooks:
21
+ - id: prettier
22
+ - repo: https://github.com/pre-commit/mirrors-mypy
23
+ rev: v2.4.1
24
+ hooks:
25
+ - id: mypy
26
+ name: "Check type hints (mypy)"
27
+ verbose: true
28
+ ci:
29
+ autofix_commit_msg: |
30
+ [pre-commit.ci] auto fixes from pre-commit.com hooks
31
+
32
+ for more information, see https://pre-commit.ci
33
+ autofix_prs: true
34
+ autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
35
+ autoupdate_schedule: monthly
36
+ skip: []
37
+ submodules: false
@@ -0,0 +1,101 @@
1
+ # AGENTS.md β€” `aiopvpc-ng`
2
+
3
+ ## 1. Project Identity & Mission
4
+
5
+ **`aiopvpc-ng`** is the independent, next-generation successor to [`azogue/aiopvpc`](https://github.com/azogue/aiopvpc).
6
+
7
+ - **Why this project exists:** The upstream `azogue/aiopvpc` repository has been unmaintained for over 2 years (last release `v4.3.1` on 2024-03-25), leaving critical maintenance gaps (such as hardcoded national holiday tables expiring after 2025, deprecated Python stdlib/async patterns, stale CI/packaging, and unaddressed ESIOS / Spanish market evolutions).
8
+ - **Mission:** Provide a modern, actively maintained, reliable asynchronous Python library for fetching Spanish electricity prices (**PVPC 2.0TD**, surplus/injection, MAG, OMIE, market adjustment, and composed indexed tariffs) from Red ElΓ©ctrica de EspaΓ±a's official ESIOS API (`api.esios.ree.es`).
9
+ - **Primary consumers:** Home Assistant integrations (such as `pvpc_hourly_pricing` and custom HACS forks) as well as standalone Python energy automation and analytics tools.
10
+ - **Repository & License:** Independently hosted at `https://github.com/marcomsousa/aiopvpc-ng` under the **MIT License**, preserving full Git history and copyright attribution to the original author (Eugenio Panadero / `azogue`).
11
+
12
+ ---
13
+
14
+ ## 2. Next-Gen (`ng`) Goals & Modernization Priorities
15
+
16
+ When planning features, refactors, or fixes in this repository, uphold and advance these core objectives (initial v5.0.0 baseline completed):
17
+
18
+ 1. **Zero Time-Bomb & Maintenance Debt**
19
+ - `aiopvpc/pvpc_tariff.py` computes Spanish 24h P3 national holidays deterministically using the 9 fixed-date non-substitutable national holidays under CNMC Circular 3/2020 Art. 7.3 (`is_national_p3_holiday`), excluding movable Good Friday.
20
+ - Legacy browser `User-Agent` rotation (`pvpc_data.py`), `dict.pop()` mutation, and geozone `TODO`s (`parser.py` now provides `resolve_geo_zone` and optional `geo_zone`) have been resolved.
21
+
22
+ 2. **Modern Python Runtime, Tooling & CI**
23
+ - Uses Python `>=3.11` stdlib APIs (`datetime.now(UTC)`, `asyncio.timeout`, built-in `TimeoutError`) without external `async_timeout`.
24
+ - Managed with `uv`, `hatchling` (PEP 621 / PEP 639 / PEP 735), modern `.pre-commit-config.yaml`, and GitHub Actions running `ruff`, `mypy`, `pytest`, and `uv build` across Python 3.11–3.14.
25
+
26
+ 3. **Keep Up With ESIOS API & Spanish Electricity Market Changes**
27
+ - Maintain compatibility with `api.esios.ree.es` public archives and token-authenticated `/indicators/{id}` endpoints.
28
+ - Preserve and evolve quarter-hourly / 15-minute pricing readiness (`_update_prices_series` date checks, 15-minute slot snapping, `price_HHhMM` attributes) alongside regulatory/market changes.
29
+
30
+ 4. **Preserve Home Assistant Integration Ergonomics**
31
+ - Keep the public interface (`PVPCData`, `EsiosApiData`, `BadApiTokenAuthError`, `TARIFFS`, `GEOZONES`, `DEFAULT_POWER_KW`, `get_enabled_sensor_keys`) clean, typed, and predictable.
32
+ - Follow Semantic Versioning (`SemVer`): document any intentional breaking changes clearly in `CHANGELOG.md`.
33
+
34
+ 5. **High Reliability & Test Rigor**
35
+ - Maintain **>= 95% branch test coverage** (`pyproject.toml` enforces `fail_under = 95`).
36
+ - Keep the default test suite 100% deterministic and offline using recorded JSON fixtures in `tests/api_examples/`.
37
+
38
+ ---
39
+
40
+ ## 3. Repository Architecture
41
+
42
+ ```text
43
+ aiopvpc-ng/
44
+ β”œβ”€β”€ aiopvpc/
45
+ β”‚ β”œβ”€β”€ __init__.py # Public exports (PVPCData, EsiosApiData, BadApiTokenAuthError, etc.)
46
+ β”‚ β”œβ”€β”€ const.py # ESIOS URLs, indicator IDs (1001, 1739, 1900, 10211, 2108), tariffs, geozones, dataclasses
47
+ β”‚ β”œβ”€β”€ pvpc_data.py # Async HTTP client (PVPCData), request throttling, auth error handling, state processing
48
+ β”‚ β”œβ”€β”€ parser.py # Parsers for public archive JSON and token-authenticated ESIOS indicator JSON
49
+ β”‚ β”œβ”€β”€ prices.py # Today/tomorrow splitting, price ranking/stats attributes, composed sensors (INDEXED)
50
+ β”‚ β”œβ”€β”€ pvpc_tariff.py # 2.0TD tariff period logic (P1/P2/P3), Peninsula vs Ceuta/Melilla, P3 national holidays
51
+ β”‚ β”œβ”€β”€ ha_helpers.py # Home Assistant unique_id mapping and enabled-sensor resolution
52
+ β”‚ └── utils.py # UTC datetime normalization helpers
53
+ β”œβ”€β”€ tests/
54
+ β”‚ β”œβ”€β”€ api_examples/ # Recorded ESIOS JSON responses (including DST spring/fall days)
55
+ β”‚ β”œβ”€β”€ conftest.py # Pytest fixtures and mock HTTP helpers
56
+ β”‚ β”œβ”€β”€ test_pvpc.py # End-to-end PVPCData download & caching tests
57
+ β”‚ β”œβ”€β”€ test_pvpc_parsing.py
58
+ β”‚ β”œβ”€β”€ test_pvpc_zones.py
59
+ β”‚ β”œβ”€β”€ test_tariff_attributes.py
60
+ β”‚ β”œβ”€β”€ test_ha_helpers.py
61
+ β”‚ └── test_real_api_calls.py # Marked `real_api_call` (deselected by default)
62
+ β”œβ”€β”€ .github/workflows/
63
+ β”‚ β”œβ”€β”€ main.yml # Push & PR CI test, coverage, and package build workflow
64
+ β”‚ └── publish.yml # Release-triggered PyPI publish workflow
65
+ β”œβ”€β”€ pyproject.toml # PEP 621 package metadata, uv dependency groups, ruff, pytest, coverage
66
+ β”œβ”€β”€ uv.lock # Reproducible uv lockfile
67
+ └── CHANGELOG.md # Release history
68
+ ```
69
+
70
+ ---
71
+
72
+ ## 4. Domain Invariants (Must Not Break)
73
+
74
+ Agents modifying parsing, scheduling, or tariff logic must uphold these invariants:
75
+
76
+ - **Timezone & Local-Hour Semantics:** Prices are stored in `dict[datetime, float]` keyed by tz-aware UTC datetimes, but Spanish electricity prices apply by **local wall-clock hour** (e.g., 10:00 in Canary Islands applies the 10:00 price, shifted relative to `Europe/Madrid`). Always test both `Europe/Madrid` and `Atlantic/Canary`.
77
+ - **Daylight Saving Time (DST):** Spring-forward (23-hour) and fall-back (25-hour, duplicated hour suffixed with `_d` in attributes) transitions must remain fully supported and tested.
78
+ - **Tariff Zones & Holidays:** Support both `2.0TD` (`PCB`, Peninsula/Balearics/Canaries) and `2.0TD (Ceuta/Melilla)` (`CYM`, shifted `P2` hours: 8–10, 15–18, 23), explicit optional `geo_zone` overrides from `GEOZONES`, and 24h `P3` on weekends + the 9 fixed-date non-substitutable national holidays per CNMC Circular 3/2020 Art. 7.3.
79
+ - **ESIOS Rate-Limit Respect:** `PVPCData._update_prices_series` intentionally avoids redundant API calls once today's (or today + tomorrow's after 20:00 `Europe/Madrid`, checked by date for both hourly and 15-minute series) prices are cached. Do not introduce polling behavior that increases requests per day.
80
+ - **Auth Error Contract:** When using `data_source="esios"` with an API token, HTTP `401` and `403` responses must raise `BadApiTokenAuthError` so Home Assistant can trigger its re-authentication flow.
81
+ - **Units:** ESIOS API returns prices in `€/MWh`; `aiopvpc` converts and exposes all prices in `€/kWh` rounded to `PRICE_PRECISION` (5 decimal places).
82
+
83
+ ---
84
+
85
+ ## 5. Development, Testing & Release Guidelines
86
+
87
+ ### Code Quality & Tests
88
+ - **Environment & Packaging:** Managed with `uv` (`uv sync --locked`, `uv run pytest`, `uv build`). Uses PEP 621 metadata with `hatchling` as the build backend.
89
+ - **Linting & Formatting:** Configured via `ruff` in `pyproject.toml` (line length `88`, strict rule selection including `ASYNC`, `B`, `C4`, `I`, `PTH`, `RUF`, `SIM`, `TCH`). Run `uv run ruff check --no-fix .` and `uv run ruff format --check .` before committing.
90
+ - **Offline Test Suite (Default):** `uv run pytest` automatically runs with coverage (`fail_under = 95`) and `-m 'not real_api_call'`. All PRs and commits must pass offline tests with >= 95% branch coverage.
91
+ - **Live ESIOS API Tests:** `tests/test_real_api_calls.py` requires a personal ESIOS API token via environment variable / local `.env` and explicit `uv run pytest -m real_api_call`. **Never commit API tokens or `.env` files.**
92
+
93
+ ### CI/CD & Packaging
94
+ - `.github/workflows/main.yml` runs `uv sync --locked`, `ruff`, `mypy`, tests, coverage checks, and `uv build` across Python 3.11–3.14 on pushes to `master` and pull requests.
95
+ - `.github/workflows/publish.yml` publishes `aiopvpc-ng` to PyPI via `uv publish --trusted-publishing always` only on GitHub Release publication (`release: [published]`) or manual `workflow_dispatch` using OIDC Trusted Publishing (`environment: pypi`).
96
+ - Distribution package name is `aiopvpc-ng`, while the Python import package remains `aiopvpc` (`[tool.hatch.build.targets.wheel] packages = ["aiopvpc"]`) for drop-in compatibility with Home Assistant.
97
+
98
+ ### Git & Contribution Conventions
99
+ - Commit as `Marco Sousa <marcomsousa@gmail.com>` under GitHub account `marcomsousa`.
100
+ - Use clear, atomic Conventional Commits (`feat(...)`, `fix(...)`, `refactor(...)`, `chore(...)`, `docs(...)`, `test(...)`).
101
+ - Do not mix unrelated refactors with behavioral fixes; update `CHANGELOG.md` and tests alongside functional changes.
@@ -0,0 +1,285 @@
1
+ # Changelog
2
+
3
+ ## [v5.0.1](https://github.com/marcomsousa/aiopvpc-ng/tree/v5.0.1) - πŸ“¦ Initial PyPI publication (2026-11-20)
4
+
5
+ [Full Changelog](https://github.com/marcomsousa/aiopvpc-ng/compare/v5.0.0...v5.0.1)
6
+
7
+ - πŸ“¦ Bump patch version to `5.0.1` for initial PyPI publication of the `v5.0.0` Next-Gen modernization release (`5.0.0` filename previously deleted on PyPI)
8
+
9
+ ## [v5.0.0](https://github.com/marcomsousa/aiopvpc-ng/tree/v5.0.0) - πŸš€ Next-Gen modernization & Python 3.11+ (2026-11-20)
10
+
11
+ [Full Changelog](https://github.com/marcomsousa/aiopvpc-ng/compare/v4.3.1...v5.0.0)
12
+
13
+ ### Breaking Changes
14
+
15
+ - πŸ’₯ Rename PyPI distribution package to `aiopvpc-ng` (keeping the `aiopvpc` import namespace as a drop-in successor to `azogue/aiopvpc`)
16
+ - πŸ’₯ Require Python `>=3.11` (dropped EOL Python 3.9 and 3.10) and remove external `async-timeout` dependency in favor of stdlib `asyncio.timeout`
17
+ - πŸ’₯ Align P3 national holidays strictly with **CNMC Circular 3/2020 (Art. 7.3)**: 24h P3 valley period applies on weekends and the 9 fixed-date non-substitutable national holidays (Jan 1, Jan 6, May 1, Aug 15, Oct 12, Nov 1, Dec 6, Dec 8, Dec 25), excluding movable Good Friday
18
+
19
+ ### Features
20
+
21
+ - ✨ Replace hardcoded 2021–2025 holiday table in `aiopvpc/pvpc_tariff.py` with non-expiring fixed-date P3 holiday detection (`is_national_p3_holiday`), eliminating `KeyError: 2026` onward
22
+ - ✨ Add optional `geo_zone` parameter on `PVPCData` (backed by `resolve_geo_zone` and exported `GEOZONES`) with fail-fast validation
23
+ - ✨ Prepare for quarter-hourly (15-minute) ESIOS pricing: date-based next-day fetch check at 20:00 `Europe/Madrid`, 15-minute slot snapping in `process_state_and_attributes`, and `price_HHhMM` attribute keys
24
+
25
+ ### Fixes & Improvements
26
+
27
+ - ♻️ Replace deprecated `datetime.utcnow()` calls with timezone-aware `datetime.now(UTC)`
28
+ - 🧹 Remove obsolete 2016–2019 browser `User-Agent` rotation from `PVPCData`
29
+ - πŸ›‘οΈ Avoid mutating caller dicts in `extract_prices_from_esios_token` and handle unknown ESIOS `geo_id`s safely without `KeyError`
30
+
31
+ ### Tooling & CI
32
+
33
+ - πŸ“¦ Migrate packaging and dependency management from Poetry to `uv` + `hatchling` (PEP 621 / PEP 639 / PEP 735)
34
+ - ⬆️ Update all runtime/dev dependencies and `.pre-commit-config.yaml` hooks
35
+ - πŸ‘· Run CI matrix across Python 3.11–3.14 with `ruff` lint/format checks, `mypy`, `pytest` (100% branch coverage), and `uv build`, plus release-triggered PyPI OIDC Trusted Publishing
36
+
37
+ ## [v4.3.1](https://github.com/azogue/aiopvpc/tree/v4.3.1) - πŸ› Fix unsorted prices in composed sensor 'INDEXED' (2024-03-25)
38
+
39
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.3.0...v4.3.1)
40
+
41
+ - πŸ› Fix unsorted prices in composed sensor 'INDEXED' (#72)
42
+ - πŸ‘· ci: Split actions for tests on PRs and publish package on main
43
+ - πŸ‘· Remove codecov integration and produce reports instead (#71)
44
+
45
+ ## [v4.3.0](https://github.com/azogue/aiopvpc/tree/v4.3.0) - ✨ Add new _composed_ sensor for Indexed tariff (2024-03-10)
46
+
47
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.2.2...v4.3.0)
48
+
49
+ - ✨ Add new price sensors: **Market adjustment** (from ESIOS API indicator 2108), and **Indexed tariff** (as _composed_ price sensor calculated as `PVPC - ADJUSTMENT`), from first-time contributor @MiguelAngelLV in #69 🍻, and some adjustments in #70
50
+ - 🎨 pre-commit updates and change to `ruff` + `ruff-format` instead of `black` and `isort`
51
+ - πŸš€ Bump minor version and update deps and CHANGELOG.md
52
+
53
+ ## [v4.2.2](https://github.com/azogue/aiopvpc/tree/v4.2.2) - ♻️ Remove python upper limit (2023-07-30)
54
+
55
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.2.1...v4.2.2)
56
+
57
+ - ♻️ Remove python upper limit (from @cdce8p in #59)
58
+ - 🎨 pre-commit autoupdate
59
+ - πŸ“¦οΈ Bump minor version and update deps and CHANGELOG.md
60
+
61
+ ## [v4.2.1](https://github.com/azogue/aiopvpc/tree/v4.2.1) - Fix injection price sensor attributes (2) (2023-05-29)
62
+
63
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.2.0...v4.2.1)
64
+
65
+ - πŸ› Fix one-line conditional matching for 'not None' instead of positive value πŸ™ˆ
66
+ - βœ… tests: Add unit test for price sensor attributes
67
+
68
+ ## [v4.2.0](https://github.com/azogue/aiopvpc/tree/v4.2.0) - Fix injection price sensor attributes (2023-05-29)
69
+
70
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.1.0...v4.2.0)
71
+
72
+ - πŸ› Fix attributes 'max_price_at' and 'min_price_at' for injection price sensor (were swapped)
73
+ - πŸ“¦οΈ Bump minor version and update deps
74
+ - πŸ“ Fix usage example in README.md
75
+ - 🎨 pre-commit autoupdate and swap `flake8` for `ruff`
76
+ - πŸ“ Fix links in CHANGELOG.md
77
+
78
+ ## [v4.1.0](https://github.com/azogue/aiopvpc/tree/v4.1.0) - Adapt to 403 unauthorized error (2023-03-12)
79
+
80
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.0.1...v4.1.0)
81
+
82
+ - πŸ› Process 403 error from server like '401 unauthorized', raising `BadApiTokenAuthError`
83
+ to signal HA for reauth-config for both status codes, when API token is enabled.
84
+
85
+ ## [v4.0.1](https://github.com/azogue/aiopvpc/tree/v4.0.1) - Minor fixes (2023-01-11)
86
+
87
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.0.0...v4.0.1)
88
+
89
+ - ✏️ Fix typo on 'injection' keyword (was badly typed as _spanglish_ 'inyection' πŸ˜…)
90
+ - πŸ› Fix unit for price sensors attributes (from €/MWh to €/kWh)
91
+
92
+ ## [v4.0.0](https://github.com/azogue/aiopvpc/tree/v4.0.0) - Implement ESIOS API Token (2023-01-09)
93
+
94
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v3.0.0...v4.0.0)
95
+
96
+ - ✨ Implement **support to access the extended ESIOS API** with a personal token
97
+ (you must request yours by mailing to [consultasios@ree.es](mailto:consultasios@ree.es?subject=Personal%20token%20request)),
98
+ with initial support for the existent PVPC price sensor (ESIOS indicator code: **1001**), and **3 new ones** 🀩:
99
+
100
+ - **Inyection price** sensor (ESIOS indicator code: **1739**),
101
+ name: "Precio de la energΓ­a excedentaria del autoconsumo para el mecanismo de compensaciΓ³n simplificada"
102
+ - **MAG price** sensor (ESIOS indicator code: **1900**),
103
+ name: "Desglose peaje por defecto 2.0TD excedente o dΓ©ficit de la liquidaciΓ³n del mecanismo de ajuste de costes de producciΓ³n"
104
+ - **OMIE price** sensor (ESIOS indicator code: **10211**),
105
+ name: "Precio medio horario final suma de componentes"
106
+
107
+ - πŸ’₯ Remove 'apidatos' support as alternative _data-source_, leaving only public and private paths for https://api.esios.ree.es
108
+
109
+ - ✨ Signal bad auth for esios token calls with a custom exception, to handle 'reauth' flow in Home-Assistant
110
+
111
+ - ✨ Add helper methods for HA integration to manage unique ids for each sensor, to update the enabled sensors to download, and to check the API token
112
+
113
+ - ♻️ Use dataclasses for `EsiosApiData` and `EsiosResponse` data containers, instead of typed dicts
114
+
115
+ - βœ… tests: Update fixtures for esios sensors and adapt tests to the new interface and the multiple-sensors behaviour
116
+
117
+ - πŸ“¦οΈ Bump mayor version to **v4** and lighten dev-env, removing pre-commit related modules and adding python-dotenv
118
+
119
+ - (from #46, with v3.1.0) Remove `holidays` dependency to evaluate special days under 'P3' period and fix tests
120
+
121
+ ## [v3.0.0](https://github.com/azogue/aiopvpc/tree/v3.0.0) - Change Data Source to apidatos.ree.es (2021-12-05)
122
+
123
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.3.0...v3.0.0)
124
+
125
+ πŸ”₯ **BREAKING-CHANGE**: this release **removes support for the old PVPC tariffs**
126
+ (prices < 2021-06-01), and the extra methods to use this library as a _dataloader_
127
+ (`.download_prices_for_range(...)`), leaving only the **code to support the HA Core integration**.
128
+
129
+ Motivated by recent successful attempts to kick us out from `api.esios.ree.es`,
130
+ we are changing the data source to another REE public server, at `apidatos.ree.es`,
131
+ with the same information than the current one, available without authentication πŸ‘Œ
132
+
133
+ **This release implements the new data-source**, but also maintains the _legacy_ one.
134
+
135
+ - Initial configuration is set with a new `data_source` parameter, **with the new source as default**.
136
+ - If a 403 status-code is received, the **data source is switched** (new to legacy / legacy to new), no retry is done,
137
+ and the User-Agent loop trick is only used for the legacy data-source.
138
+
139
+ **Changes:**
140
+
141
+ - :fire: Remove support for old PVPC tariffs and range download methods,
142
+ and make `tariff` and `websession` required arguments
143
+
144
+ - :sparkles: Add alternative data-source from 'apidatos.ree.es'
145
+
146
+ - Implement data parsing from `apidatos.ree.es`, using endpoint at `/es/datos/mercados/precios-mercados-tiempo-real`
147
+ - Add `data_source` parameter with valid keys 'apidatos' and 'esios_public', setting the new one as default ;-)
148
+ - Remove retry call if 403 status is received, but maintain the User-Agent loop, and also toggle the data-source for the next call
149
+ - Move old ATTRIBUTION to `.attribution` property, as function of the data-source
150
+
151
+ - :truck: Change test patterns to new tariffs by substituting old examples in DST days from 2019 to equivalent days since 2021-06, using the new tariff keys
152
+
153
+ - :truck: Add test patterns from new data-source, and adjust tests
154
+
155
+ ## [v2.3.0](https://github.com/azogue/aiopvpc/tree/v2.3.0) - Decrease API refresh rate and try to avoid banning (2021-12-01)
156
+
157
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.2.4...v2.3.0)
158
+
159
+ Quick-Fix Release motivated by the last change in the ESIOS server (on 2021-11-30 😱),
160
+ which is now apparently banning HomeAssistant requests,
161
+ filtering us out because of the 'User-Agent' headers data 😀,
162
+ as the server is returning a 403 status code error for a PUBLIC url 🀷.
163
+
164
+ **Changes:**
165
+
166
+ - :zap: **Substantially decrease the number of API requests to ESIOS**,
167
+ avoiding unnecesary calls to refresh data for the same electricity prices.
168
+ Before, when used from the `pvpc_hourly_pricing` HA Core integration,
169
+ the ESIOS API was called 2 times/hour from 0h to 20h, and 4 times/hour in the evening,
170
+ from 20h to 0h, retrieving today + tomorrow prices.
171
+ This makes a total of ~56 requests/day, which is _not a lot_ πŸ˜…,
172
+ but it seems the aggregated total for the HA user base (πŸ”₯ >30k requests/day just
173
+ counting users pushing HA analytics) is being some kind of a problem for ESIOS,
174
+ as it looks like they're trying to bane us πŸ₯ΊπŸ˜­
175
+ Now, the API handler avoids calls to retrieve already available prices,
176
+ cutting down the number of requests to just 1-2 requests/day 🀩
177
+
178
+ - :bug: **Set standard `User-Agent` header info**, to try to avoid server-side banning πŸ™ˆ,
179
+ and _rotate_ it if banning is detected, using common User-Agent browser identifiers.
180
+
181
+ - :recycle: Minor code refactor to prepare for future library changes, in order to move to authenticated API endpoints in future versions.
182
+
183
+ ## [v2.2.4](https://github.com/azogue/aiopvpc/tree/v2.2.4) - Split today / tomorrow price sensor attributes (2021-11-20)
184
+
185
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.2.2...v2.2.4)
186
+
187
+ **Changes:**
188
+
189
+ - Generate different sets of sensor attributes for hourly prices for current day and for the next day (available at evening), so attrs like `price_position` or `price_ratio` don't change for the current day when next-day prices are received.
190
+
191
+ ## [v2.2.2](https://github.com/azogue/aiopvpc/tree/v2.2.2) - Migrate CI from travis to gh-actions (2021-11-04)
192
+
193
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.2.1...v2.2.2)
194
+
195
+ **Changes:**
196
+
197
+ - :art: Add isort to pre-commit config
198
+ - :green_heart: Add configuration for pre-commit.ci to run linter checks there
199
+ - :green_heart: CI flow with GitHub Actions to
200
+ - install library with `poetry`
201
+ - run tests
202
+ - upload coverage when merging to master
203
+ - publish a new pypi version when merging to master if `pyproject.toml` changes
204
+ - :fire: Remove previus travis CI config
205
+
206
+ ## [v2.2.1](https://github.com/azogue/aiopvpc/tree/v2.2.1) - Quickfix for 403 status code from ESIOS API (2021-11-03)
207
+
208
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.2.0...v2.2.1)
209
+
210
+ **Changes:**
211
+
212
+ - Fix Esios request returning a 403 status code since 2021-11-02, by:
213
+ - just adding an 'User-Agent' to request headers, if `aiohttp==3.7.4.post0`
214
+ - or upgrading to `aiohttp==3.8.0`, where it is not needed and the original request works like before
215
+ - Add better error logging for this 'forbidden' error if reappears in the future
216
+ - Update deps, requiring holidays>0.11.1
217
+
218
+ ## [v2.2.0](https://github.com/azogue/aiopvpc/tree/v2.2.0) - New sensor attributes for new tariff 2.0TD (2021-06-12)
219
+
220
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.1.2...v2.2.0)
221
+
222
+ **Changes:**
223
+
224
+ - Determine tariff period (P1/P2/P3) for current hour, and calculate the delta hours to the next one, publishing attributes `period`, `next_period`, and `hours_to_next_period`
225
+ - Add `price_ratio`, `max_price`, and `max_price_at` attributes
226
+ - When there are cheaper prices ahead, add attributes `next_better_price`, `hours_to_better_price`, and `num_better_prices_ahead`
227
+ - Add `price_position` attribute (1 for cheaper price, 24 for the most high-priced), as suggested by @r-jordan in #23
228
+ - Add contracted power in kW as new parameters (power for P1/P2 and power for P3) to show the `available_power` for each period
229
+ - Use `holidays` library to retrieve national holidays where to apply the valley period P3 for the full day
230
+
231
+ ## [v2.1.2](https://github.com/azogue/aiopvpc/tree/v2.1.2) - Quick adapt to new tariff 2.0TD (2021-05-31)
232
+
233
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.1.1...v2.1.2)
234
+
235
+ **Changes:**
236
+
237
+ - Use "PCB" and "CYM" keys to retrieve prices for dates > 2021-06-01 to match new JSON from Esios API for new '2.0 TD' tariff.
238
+ - Add new flag to set prices for Ceuta & Melilla (to use "CYM" identifier instead of "PCB")
239
+
240
+ ## [v2.1.1](https://github.com/azogue/aiopvpc/tree/v2.1.1) - Fix prices badly assigned outside default timezone (2021-05-16)
241
+
242
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.0.2...v2.1.1)
243
+
244
+ **Changes:**
245
+
246
+ - Remove `pytz` dependency and handle timezones with `zoneinfo` (related to [this article](https://developers.home-assistant.io/blog/2021/05/07/switch-pytz-to-python-dateutil)),
247
+ and adapt to use input timezone as a time zone object or a string identifier.
248
+ - **Fix prices being badly assigned in Canary Islands timezone**.
249
+ Before, prices where **assumed absolute in time**, and marked with tz-aware UTC datetimes,
250
+ but that behavior was incorrect πŸ˜”, as prices are applicable _by-hour_, independently of the timezone.
251
+ So now the produced prices are **shifted**, to apply the correct ones for each local hour, so given the price at 10AM,
252
+ it will be the same across all timezones. THIS IS A **BREAKING CHANGE** over the old behavior, if you live in the Canary Islands (because before the prices were incorrect!)
253
+ - Fix sensor attributes in month changes (there were badly tagged as "price last day" instead of "price next day" πŸ€ͺ).
254
+ - Update tests suite to use `pytest-asyncio` instead of `pytest-aiohttp`, add `mypy` to pre-commit, and a general dependency update.
255
+
256
+ ## [v2.0.2](https://github.com/azogue/aiopvpc/tree/v2.0.2) - Unpinned requirements (2020-08-04)
257
+
258
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v2.0.1...v2.0.2)
259
+
260
+ **Changes:**
261
+
262
+ - Fix outdated pinned requirements by setting just a minimal version, and syncing those with HomeAssistant
263
+
264
+ ## [v2.0.1](https://github.com/azogue/aiopvpc/tree/v2.0.1) - Add methods to download a range of days (2020-05-07)
265
+
266
+ [Full Changelog](https://github.com/azogue/aiopvpc/compare/v1.0.2...v2.0.1)
267
+
268
+ **Implemented enhancements:**
269
+
270
+ - Async & blocking methods to download prices for a range of days.
271
+ - Use an `asyncio.Queue` to control concurrency for downloading a bunch of days, by creating a `concurrency_calls` number of workers.
272
+ - Make specific tariff optional, to get ALL PVPC detailed data when None, with schema `Dict[datetime, Dict[str, float]` instead of tariff-specific `Dict[datetime, float]`.
273
+
274
+ **Changes:**
275
+
276
+ - Make rest of init parameters also optional, to easier instantiation with `PVPCData()`.
277
+ - Add minimal doc in README and an example of use for bulk download of PVPC prices
278
+
279
+ ## [v1.0.2](https://github.com/azogue/aiopvpc/tree/v1.0.2) - Fix timezone support outside Europe/Madrid zone.
280
+
281
+ ## [1.0.0] - Initial
282
+
283
+ **Implemented**
284
+
285
+ - Basic data handler `PVPCData` to `.async_update_prices` and `process_state_and_attributes` for the PVPC HA sensor.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Eugenio Panadero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.