Skip to main content

Async Python wrapper for Netro API (HTTP-agnostic, HA-friendly)

Project description

pynetro

Async Python wrapper for the Netro API — HTTP-agnostic.

Netro Public API

Installation

Quick install

git clone https://github.com/kcofoni/pynetro.git
cd pynetro
pip install -e .

Development setup

  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate   # Linux / macOS
# .venv\Scripts\activate    # Windows
  1. Install the package and dev dependencies:
pip install -e .
pip install -r requirements-dev.txt
  1. Verify basic checks:
# run unit tests
pytest tests/test_client.py -v

# lint
ruff check src/ tests/

Testing

This project provides two kinds of tests:

  • Unit tests

    • Fast, offline, no network required.
    • Located mainly in tests/test_client.py.
    • Run locally or in CI without environment variables.
  • Integration tests

    • Interact with the Netro API (or rely on prepared reference responses).
    • Marked with @pytest.mark.integration in tests/test_integration.py.
    • Require device serial numbers and/or reference files.

Running tests:

# run all tests
pytest tests/ -v

# unit tests only
pytest tests/test_client.py -v

# integration tests (requires env vars / references)
pytest tests/test_integration.py -m integration -v

Reference files & templates

  • Sensitive reference files that include real serials are NOT committed.
  • Committed templates live under tests/reference_data/*_template.json.
  • The test helpers in tests/conftest.py expose fixtures (e.g. need_sensor_reference, need_controller_reference, need_sensor_data_reference) that:
    • If a reference file already exists, use it unchanged.
    • If the reference is missing but a template exists:
      • If a serial env var is provided (NETRO_SENS_SERIAL or NETRO_CTRL_SERIAL), the test helper generates the reference from the template by performing an internal token substitution (no external script). Common dummy tokens such as DUMMY_SERIAL, 000000000000, SENSOR_SERIAL or CTRL_SERIAL are replaced by the provided serial.
      • If the template contains no serials (pure fixtures), it will be copied to create the reference (copy_if_template=True).
    • If neither reference nor template is available (or a required env var is unset), the fixture calls pytest.skip() so the integration test is skipped cleanly.

Note: generate_reference.py is no longer used and has been removed — the generation is handled internally by tests/conftest.py.

Environment variables used by fixtures:

  • NETRO_SENS_SERIAL — sensor serial used to generate sensor reference
  • NETRO_CTRL_SERIAL — controller serial used to generate controller reference

Fixtures used in tests (examples):

  • need_sensor_reference — ensures sensor_response.json
  • need_controller_reference — ensures sprite_response.json
  • need_sensor_data_reference — ensures sensor_response_data.json
  • need_schedules_reference, need_moistures_reference, need_events_reference — ensure other refs (copy from templates if necessary)

.env.example and local .env

A .env.example file (if present) documents the environment variables the tests may require. To provide values locally, copy it to .env and edit the values:

cp .env.example .env
# then open .env and fill NETRO_SENS_SERIAL / NETRO_CTRL_SERIAL etc.

Notes:

  • tests/conftest.py attempts to load a .env file automatically (using python-dotenv if installed, otherwise a fallback). This allows running integration tests without exporting variables manually.
  • Do NOT commit your .env containing real serials or secrets. .env is ignored by the repo (.gitignore) by default.
  • In CI, either install python-dotenv or provide the required variables as repository Actions secrets / environment variables.

Security & gitignore

  • By default all .json files are ignored and only *_template.json are tracked. Keep real reference files out of the repository.
  • If a sensitive .json is already tracked, remove it from the index without deleting local copy:
git rm --cached path/to/file.json

Troubleshooting

  • ImportError in CI for dotenv: ensure python-dotenv is installed in the job or make import optional in tests/conftest.py.
  • If integration tests are skipped, confirm NETRO_SENS_SERIAL and NETRO_CTRL_SERIAL are set or that reference templates exist.

Contributing

  • Add templates (*_template.json) for any reference data you add.
  • Do not commit files containing real serials or private tokens.

For more details about tests and reference management see tests/conftest.py and the test files under tests/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynetro-0.1.5.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynetro-0.1.5-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pynetro-0.1.5.tar.gz.

File metadata

  • Download URL: pynetro-0.1.5.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for pynetro-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a9d8c980be3f3140a99d578eb5dd9c05da9ba7dc9cda4ee63eb0f2e11b1f006c
MD5 b4f4ce9c598969f008e53e71fd422f48
BLAKE2b-256 30622b9df2da4d2426352d9a45cf249db1688849f006e17e723dfbbc897c2723

See more details on using hashes here.

File details

Details for the file pynetro-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pynetro-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for pynetro-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 63239f5b829736105d174d3b3ca899e1ce014f199dc9b35f13ca193e6974d5c7
MD5 eb09d8f1926e863f5a9449aeff2864e6
BLAKE2b-256 0887cadb6e6b930bdda872fecb1c93b20f9134fa1c525f45154993ca5cb468ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page