Files

Testing Documentation for Panasonic Heatpump Component

This directory contains comprehensive tests for the panasonic_heatpump ESPHome component.

Test Structure

Unit Tests (test_panasonic_heatpump_unit.py)

  • Tests Python configuration validation
  • Tests component metadata (CODEOWNERS, DEPENDENCIES, etc.)
  • Tests configuration schema structure
  • Tests all platform imports (sensor, binary_sensor, text_sensor, number, select, switch, climate)
  • Tests code generation logic

Integration Tests (test_panasonic_heatpump_integration.py)

  • Tests minimal feature configuration on ESP32 board
  • Tests full feature configuration on ESP32 board
  • Tests configuration on ESP32-S2 board
  • Tests configuration on ESP32-C3 board
  • Tests configuration with CZ-TAW1 (UART-proxy)

Test Configuration Files

  • test_panasonic_heatpump_esp32s2.yaml - ESP32-S2 Wemos S2 Mini
  • test_panasonic_heatpump_esp32c3.yaml - ESP32-C3 mini (RISC-V)
  • test_panasonic_heatpump_cztaw1.yaml - UART proxy setup for CZ-TAW1 client support
  • test_panasonic_heatpump_mini.yaml - Minimal ESP32 configuration for basic testing
  • test_panasonic_heatpump_full.yaml - Comprehensive ESP32 configuration with all features

Running Tests Locally

Prerequisites

pip install -r tests/requirements.txt

Run All Tests

pytest tests/panasonic_heatpump/ -v

Run Only Unit Tests

pytest tests/panasonic_heatpump/test_panasonic_heatpump_unit.py -v

Run Only Integration Tests

pytest tests/panasonic_heatpump/test_panasonic_heatpump_integration.py -v

Run with Coverage

pytest tests/panasonic_heatpump/ -v --cov=components/panasonic_heatpump --cov-report=html

View coverage report by opening htmlcov/index.html in a browser.

Run Specific Test

pytest tests/panasonic_heatpump/test_panasonic_heatpump_unit.py::TestPanasonicHeatpumpConfig::test_component_metadata -v

GitHub Actions Workflow

The GitHub Actions workflow (.github/workflows/test_panasonic_heatpump.yml) includes:

Jobs

  1. test-build: Validates and compiles the component

    • Tests on multiple board types: ESP32 (full), ESP32-S2, ESP32-C3 and with CZ-TAW1 (UART-proxy)
    • Uses esphome/build-action for firmware compilation
  2. lint-code: Runs clang-format on C++ code

    • Ensures consistent code formatting
    • Checks all .cpp and .h files
  3. lint-python: Runs Python linters

    • black: Code formatting
    • flake8: Style guide enforcement
  4. test-python: Runs Python unit tests

    • Executes pytest with coverage
    • Uploads coverage to Codecov
  5. test-minimal-config: Tests minimal configuration

    • Validates minimal configuration file
    • Ensures component works with bare minimum settings
  6. test-full-config: Tests full configuration

    • Validates full feature configuration with all platforms
  7. summary: Aggregates all test results

    • Fails if any test job fails
    • Provides overview of all test results

Triggers

The workflow runs on:

  • Push to main or heatpump** branches
  • Pull requests to main branch
  • Manual workflow dispatch
  • When relevant files change:
    • components/panasonic_heatpump/**
    • tests/panasonic_heatpump/**
    • .github/workflows/test_panasonic_heatpump.yml

Test Coverage

The test suite covers:

✅ Component configuration validation
✅ UART dependency checking
✅ All sensor platforms
✅ All binary sensor platforms
✅ All text sensor platforms
✅ All number control platforms
✅ All select control platforms
✅ All switch control platforms
✅ All climate control platforms
✅ Code compilation for different ESP boards
✅ C++ code formatting
✅ Python code formatting and style

Configuration Examples

Minimal Configuration

uart:
  - id: uart_hp
    tx_pin: GPIO1
    rx_pin: GPIO3
    baud_rate: 9600
    parity: EVEN

panasonic_heatpump:
  id: hp

Full Configuration

uart:
  - id: uart_heatpump
    tx_pin: GPIO37
    rx_pin: GPIO39
    baud_rate: 9600
    parity: EVEN
  - id: uart_client
    tx_pin: GPIO18
    rx_pin: GPIO16
    baud_rate: 9600
    parity: EVEN

panasonic_heatpump:
  id: my_heatpump
  uart_id: uart_heatpump
  uart_client_id: uart_client
  log_uart_msg: true
  update_interval: 3s

Adding New Tests

When adding new features to the component:

  1. Update test_panasonic_heatpump.yaml with new configuration options
  2. Add unit tests in test_panasonic_heatpump_unit.py
  3. Add integration tests in test_panasonic_heatpump_integration.py if needed
  4. Update this README with new test coverage information

Troubleshooting

ESPHome Not Found

If you get "ESPHome not installed" errors, install it:

pip install esphome

Import Errors

Make sure you're running pytest from the repository root:

cd /path/to/esphome_components
pytest tests/ -v

Timeout Errors

Some tests may timeout on slower systems. Increase the timeout in pytest.ini:

timeout = 600  # 10 minutes

Continuous Integration

All tests must pass before merging to main branch. The GitHub Actions workflow ensures:

  • Code compiles successfully
  • Code follows formatting standards
  • All unit and integration tests pass
  • Latest ESPHome versions is supported
  • Only ESP32 boards are supported

Contributing

When contributing to the panasonic_heatpump component:

  1. Write tests for new features
  2. Ensure all existing tests pass
  3. Maintain or improve code coverage
  4. Follow the existing code style
  5. Update this documentation as needed