Python library for reading and interpreting CEZ Distribution HDO (NT/VT) switch schedules.
Project description
cez-distribution-hdo
Python library for reading and interpreting HDO (low/high tariff) switch times from the CEZ Distribution “switch-times / signals” API.
This repository contains the core library only. A Home Assistant integration is planned as a separate project.
Features
- Async HTTP client (
httpx) for the CEZ Distribution API (POST JSON) - Parsing of
signals[]including multiplesignalsets (e.g. boiler vs heating) - Robust handling of
24:00and cross-midnight low-tariff windows - Per-signal schedule utilities:
- current tariff (NT/VT)
- current window start/end
- next switch time
- next NT/VT window (future-only)
- remaining time until next switch
- High-level service (
TariffService) that:- refreshes data occasionally (API call)
- computes “snapshots” frequently without extra network calls (ideal for HA)
See examples/ for runnable demos (e.g., demo_cli.py).
Requirements
- Python
>= 3.13 - Runtime dependency:
httpx
Development tools (optional): uv, ruff, pyright, pytest, pytest-asyncio.
Version
The package version is derived from git tags via uv-dynamic-versioning.
from cez_distribution_hdo import __version__
print(__version__)
Install
From PyPI (recommended)
pip install cez-distribution-hdo
Using uv:
uv add cez-distribution-hdo
From TestPyPI (pre-releases)
TestPyPI is useful for verifying releases before publishing to PyPI. Pre-releases may require
--pre.
With pip:
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple cez-distribution-hdo
With uv (using the testpypi index from pyproject.toml):
uv add --index testpypi cez-distribution-hdo
From Git (development)
Using uv:
uv add "cez-distribution-hdo @ git+https://github.com/pokornyIt/cez-distribution-hdo.git"
Or with pip:
pip install "cez-distribution-hdo @ git+https://github.com/pokornyIt/cez-distribution-hdo.git"
Logging
This library uses Python's standard logging module and does not configure logging by itself.
To see debug logs from the library, configure logging in your application:
import logging
logging.basicConfig(level=logging.INFO)
# Increase verbosity for this library
logging.getLogger("cez_distribution_hdo").setLevel(logging.DEBUG)
If you also want to see HTTPX request logs:
import logging
logging.getLogger("httpx").setLevel(logging.INFO)
Quickstart
1) Fetch schedules (API call)
import asyncio
from cez_distribution_hdo import CezHdoClient
async def main() -> None:
async with CezHdoClient() as client:
resp = await client.fetch_signals(ean="859182400123456789")
print(f"Signals returned: {len(resp.data.signals)}")
for s in resp.data.signals[:3]:
print(s.signal, s.date_str, s.times_raw)
if __name__ == "__main__":
asyncio.run(main())
2) High-level service (recommended)
Refresh schedules occasionally (e.g. hourly) and compute values frequently (e.g. every 1–5 seconds) without extra API calls.
import asyncio
from datetime import datetime
from zoneinfo import ZoneInfo
from cez_distribution_hdo import TariffService, snapshot_to_dict
async def main() -> None:
tz = ZoneInfo("Europe/Prague")
svc = TariffService(tz_name="Europe/Prague")
# One API call (do this occasionally)
await svc.refresh(ean="859182400123456789")
print("Available signals:", svc.signals)
# Compute values (no network) - do this often
now = datetime.now(tz)
for signal in svc.signals:
snap = svc.snapshot(signal, now=now)
print(snapshot_to_dict(snap))
if __name__ == "__main__":
asyncio.run(main())
Data model
The API returns a list of signal entries:
signal– identifies a “signal set” (multiple sets may be returned)datum– date (DD.MM.YYYY)casy– semicolon-separated time ranges where low tariff (NT) is active (everything outside those windows is high tariff (VT))
Example:
{
"signal": "PTV2",
"datum": "03.01.2026",
"casy": "00:00-06:00; 17:00-24:00"
}
Cross-midnight handling
24:00 is treated as 00:00 of the next day.
If a low-tariff window ends at 24:00 and the next day starts with 00:00-06:00,
the library merges these into one continuous interval:
03.01 17:00 → 04.01 06:00
This makes “current window”, “next switch”, and “remaining time” behave correctly.
Error handling
The client raises:
InvalidRequestError– no identifier provided (ean/sn/place)HttpRequestError– network/timeout/non-2xx HTTP errorsInvalidResponseError– unexpected JSON schema or invalid time/date formatsApiError– API returned non-200statusCodein JSON payload
Development
Setup
uv venv
uv sync
Lint / typecheck / tests
uv run ruff check .
uv run pyright
uv run pytest
Pre-commit
uv add --group dev pre-commit
uv run pre-commit install
uv run pre-commit run --all-files
Build
uv build
License
This project is licensed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cez_distribution_hdo-0.2.0.tar.gz.
File metadata
- Download URL: cez_distribution_hdo-0.2.0.tar.gz
- Upload date:
- Size: 44.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
019110f3d021ecb6a374473f0fa874ee618b9d5115d4574950847f50944f7407
|
|
| MD5 |
ab980cb12f965f6c27ce8edb57a85c6f
|
|
| BLAKE2b-256 |
92de6a9485efa2e0d227ee7bc9d861c69194c08636f1135cf5b01604235d4e3f
|
File details
Details for the file cez_distribution_hdo-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cez_distribution_hdo-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
919471062e7385badb941203378eb8af93d91d8db8421c8ac853473807d5f275
|
|
| MD5 |
431279fc35c9225a1059aaf0a69a95e1
|
|
| BLAKE2b-256 |
7d1c34b3819189a242f6ba93aa36ceb18feaff944accc4b8cfe8f9024b324377
|