Conversation
- Socket API: Document all 7 commands with request/response examples - list_devices, get_instantaneous_demand, get_device_data - get_network_info, get_history_data, plus unsupported commands - Add field-by-field explanations and unit conversion formulas - HTTP API: Expand documentation with complete endpoint details - Authentication (HTTP Basic Auth) with curl examples - Document get_usage_data, get_device_list, get_instantaneous_demand - Include request/response examples in XML and JSON - Clients API: Add comprehensive usage guide - Full Python examples for both Socket and HTTP clients - Comparison table: Socket vs HTTP (protocol, auth, speed, features) - Clear recommendations for when to use each approach - Data Models: Complete reference with all fields documented - Document all 6 models: DeviceInfo, DeviceList, InstantaneousDemand - CurrentSummation, UsageData, NetworkInfo - Include JSON response examples and usage patterns - Explain computed properties and unit conversions - Remove embedded agent reasoning from socket_api.md - Clean up parenthetical authentication discussion - Professional reference manual format throughout Expands documentation from ~130 lines to 838 lines with 35+ code examples.
… capabilities - Add comprehensive real-time monitoring examples (polling-based) - Basic continuous demand monitoring with 10s interval - Alert example for high demand with cooldown - Data logging to CSV with network status - Peak demand tracking with summation - Clarify push notification capabilities - Acknowledge gateway may support event callbacks - Don't claim definitively that push is unsupported - Note that library doesn't currently expose these features - Recommend checking official API docs and web interface - Add performance considerations for polling - Socket connection efficiency - Monitoring scale limits - Network impact analysis - Graceful error handling patterns - Revise comparison table to reflect polling-based approach
Add comprehensive support for /cgi-bin/post_manager endpoint: - New EagleConfigClient class for system-level configuration - Methods for mDNS, remote management, cloud status, device config - Full documentation of all configuration commands - Proper HTTP Basic Auth integration Supported operations: - get_mdns_status() / set_mdns(enabled) - Local network discovery - get_device_config() - Firmware, hardware, MAC address - get_cloud_status() - Cloud service connectivity - get_remote_management_status() / set_remote_management(enabled) - get_time_status() - NTP synchronization - get_network_info() - IP, DNS, DHCP settings - get_ssh_status() - SSH access status - run_command(name, **kwargs) - Generic command execution Documentation updates: - Add api/config.md with complete reference - Expand openapi.yaml with post_manager endpoints - Update mkdocs.yml navigation to include Configuration section - Update index.md to highlight configuration capabilities - Update clients.md overview to mention all three client types Exports in __all__: - EagleConfigClient now exported from meter_reader package - ConfigClient alias available in clients module
Test Coverage: - test_config_client.py: 25 tests targeting EagleConfigClient - Client initialization (basic and custom timeout) - All 8 configuration methods (mDNS, device, cloud, remote, time, network, SSH) - Generic run_command() with and without parameters - Error handling (HTTP errors, connection failures) - XML command structure validation - Authentication and timeout passing - Content-Type header verification - URL format validation - Parameter filtering (None values excluded) - JSON response parsing - Multiple independent calls - test_integration.py: 16 tests for package-level integration - Package exports verification (3 clients, 5 models) - Client instantiation (all three types) - Module exports from clients package - Client method presence (data vs configuration) - Address/URL format consistency - Authentication format consistency Test Results: - Total tests: 41 new tests + 82 existing tests = 123 total - All 123 tests PASS - Coverage: 92% overall, 100% for config client - Config client: 47/47 statements covered (100%) - HTTP client: 48/48 statements covered (100%) Target Coverage Achievement: - Config client: 100% (target: 80%) ✅ - HTTP client: 100% (target: 80%) ✅ - Overall: 92% (target: 80%) ✅ Key Test Areas: ✓ Client initialization patterns ✓ HTTP request parameters (auth, timeout, headers) ✓ XML command formatting ✓ JSON response parsing ✓ Error handling and exceptions ✓ Parameter validation and filtering ✓ Multiple sequential operations ✓ Package exports and compatibility
Property-based testing for critical protocol functions using Hypothesis: Coverage Areas: 1. Two's Complement Conversions (10 tests) - Positive value preservation across bit widths (8, 16, 32-bit) - Negative value conversion validation - Boundary condition testing (max/min values) - Roundtrip consistency validation 2. Data Conversion Functions (9 tests) - None value handling - MAC address formatting (DeviceMacId, MeterMacId) - Timestamp conversion (BEGINNING_OF_TIME epoch handling) - Hex value conversion and edge cases - InstallCode formatting 3. Demand Calculations (2 tests) - Demand formula consistency: (demand × multiplier) ÷ divisor - Non-negativity with positive inputs - Arbitrary multiplier and divisor combinations 4. Summation Calculations (2 tests) - Summation formula consistency for delivered and received - Non-negativity with positive inputs - Large value handling 5. Network Status Properties (2 tests) - Link strength range validation (0-100) - ZigBee channel range validation (11-26) 6. Usage Data Properties (2 tests) - Usage data consistency with varying inputs - Unix timestamp to datetime conversion - Field value validation 7. Model Field Validation (2 tests) - Device list size consistency - Device model fields accept arbitrary values - Network status field variations Test Configuration: - Reduced example count (50-100) for reasonable runtime - Health check suppression for slow test detection - Proper NaN/infinity handling for float strategies Results: - 31 property-based tests all passing - 154 total tests (123 previous + 31 new) - Coverage maintained at 92% - Test execution time: ~78 seconds Benefits of Property-Based Testing: ✓ Discovers edge cases not covered by example-based tests ✓ Tests mathematical correctness of conversions ✓ Validates boundary conditions across all bit widths ✓ Tests with thousands of generated values per property ✓ Ensures protocol robustness against arbitrary inputs ✓ Finds off-by-one errors and precision issues
Linting Fixes: - Remove unused imports (pytest, call, assume) from test files - Remove unused variable assignments - Restore pytest import in test_config_client.py (actually needed) Dependency Management: - Add hypothesis>=6.0 to dev dependencies in pyproject.toml - Required for property-based tests using Hypothesis All 154 tests passing: - 123 example-based tests - 31 property-based tests with Hypothesis - 92% code coverage Ruff linting: All checks passed ✓
There was a problem hiding this comment.
Pull request overview
This PR expands the project into a more complete reference by adding extensive API documentation and introducing a new HTTP configuration client, backed by integration + property-based tests.
Changes:
- Added
EagleConfigClientfor/cgi-bin/post_managersystem configuration commands and exported it from the package. - Added integration tests plus a new Hypothesis-based property test suite for protocol/model behaviors.
- Overhauled and expanded documentation (Socket API, HTTP API, models, clients) and updated MkDocs navigation/OpenAPI content.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_property_based.py | Adds Hypothesis property-based tests for low-level conversions and model computed properties. |
| tests/test_integration.py | Verifies package exports and basic client instantiation/shape. |
| tests/test_config_client.py | Adds unit tests for the new configuration client using request mocking. |
| src/meter_reader/clients/config.py | Introduces the new configuration client making XML POST calls to /cgi-bin/post_manager. |
| src/meter_reader/clients/init.py | Exports ConfigClient from meter_reader.clients. |
| src/meter_reader/init.py | Exports EagleConfigClient at package top-level. |
| pyproject.toml | Adds Hypothesis to dev dependencies to support new property tests. |
| mkdocs.yml | Adds Configuration docs page to the nav. |
| docs/socket_api.md | Rewrites Socket API docs with detailed command coverage and examples. |
| docs/openapi.yaml | Expands OpenAPI descriptions and adds post_manager-related entries/examples. |
| docs/index.md | Updates library feature bullets to include gateway/system configuration. |
| docs/http_api.md | Replaces minimal note with a full HTTP API reference and examples. |
| docs/api/models.md | Expands model documentation with field descriptions, examples, and computed properties. |
| docs/api/config.md | Adds configuration client documentation and usage patterns. |
| docs/api/clients.md | Expands client docs, adds configuration client notes, and adds usage examples/comparisons. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Security & Code Quality:
1. XML Injection Prevention (config.py)
- Added xml.sax.saxutils.escape() for safe XML text encoding
- Implemented tag name validation (alphanumeric + underscore allowlist)
- Prevents injection via special characters like <, >, &
- All values converted to strings and properly escaped
2. Fixed Hypothesis Test Strategies (test_property_based.py)
- test_network_status_field: Changed from st.text() to st.sampled_from()
* Was generating random strings like 'c,nJ' instead of valid statuses
* Now constrained to: ['Connected', 'Unavailable', 'Joining']
3. Floating-Point Comparison Fixes
- test_demand_calculation_consistency: Added tolerance comparison (< 1e-9)
- test_summation_calculation_consistency: Added tolerance comparison (< 1e-9)
- Prevents brittle failures due to rounding differences
4. Improved Test Assertions
- test_hex_value_conversion_positive: Changed to use 'Multiplier' key
* Now properly tests hex-to-integer conversion
* Stronger assertions: isinstance(int) AND result == value
5. Implemented Roundtrip Property Test
- test_roundtrip_consistency: Actual roundtrip validation
* Truncates value to bit width
* Converts to signed via twos_complement()
* Reconstructs unsigned from signed
* Verifies reconstruction matches truncated value
6. OpenAPI Specification Refactor
- Consolidated synthetic endpoints (/cgi-bin/post_manager-get-*)
- Single endpoint: /cgi-bin/post_manager with multiple examples
- Uses 'examples:' field with named request/response examples
- Commands distinguished via 'name' field in XML payload
- More realistic and follows OpenAPI best practices
All Tests: 154/154 PASSING ✅
Coverage: 92% maintained
Execution time: ~72 seconds
eman
left a comment
There was a problem hiding this comment.
Addressed all review comments:
✅ Comment 1 (XML injection): Added xml.sax.saxutils.escape() and tag name validation to config.py
✅ Comment 2 (Hypothesis status strategy): Changed to st.sampled_from() for valid status values
✅ Comment 3 (Float equality): Added tolerance comparison (< 1e-9) for demand/summation tests
✅ Comment 4 (OpenAPI endpoints): Consolidated to single /cgi-bin/post_manager with examples
✅ Comment 5 (Roundtrip property): Implemented actual roundtrip invariant validation
✅ Comment 6 (Weak assertion): Strengthened with isinstance(int) AND result == value check
All 154 tests passing, 92% coverage maintained.
Overview
Comprehensive documentation overhaul transforming light reference material into a professional API reference manual.
Changes
Socket API Documentation (259 lines)
list_devices,get_instantaneous_demand,get_device_dataget_network_info,get_history_dataHTTP API Documentation (143 lines)
/cgi-bin/cgi_managerendpoint thoroughlyget_usage_data,get_device_list,get_instantaneous_demandClients API Documentation (139 lines)
Data Models Documentation (255 lines)
Cleanup
Statistics
Type