Merged
Conversation
Copilot
AI
changed the title
[WIP] Update rate API for improved data formatting
Add OpenEI TOU rate plan integration and CLI
Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements complete Time-of-Use rate plan workflow via OpenEI Utility Rates API v7, matching the Navien mobile app's functionality.
Core Components
OpenEIClient(src/nwp500/openei.py) - Async client for browsing 10,000+ utility rate plans by ZIP codeconvert_tou()delegates conversion to Navien backend,update_tou()applies plans to devicesConvertedTOUPlanmodel - Type-safe representation of server-converted schedules with season bitfields and scaled pricingCLI Commands
Output Formatting
Table output with intelligent day/month range collapsing:
Monday, Tuesday, Wednesday, Thursday, Friday 16:00-21:00Mon–Fri 16:00-21:00Handles edge cases: weekends (
Sat–Sun), all days (Every day), non-contiguous ranges (Mon–Wed, Fri).Implementation Notes
OPENEI_API_KEYenvironment variablePOST /device/tou/converteliminates client-side bitfield encoding@click.pass_contextdecorators that caused argument collision withasync_commandWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/graphql/usr/bin/gh gh pr list --repo eman/nwp500-python --head copilot/different-tuna(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
commit changes and create pr for the rate api
**Chronological Review:** 1. User requested implementation of `get_tou_info()` REST method → Already existed in codebase 2. User asked about CLI exposure, OpenEI API key source, and app workflow → Analyzed HAR files, discovered hardcoded API key in Navien app, identified missing endpoints 3. User requested a plan for full TOU workflow implementation → Created plan.md with 8 phases 4. User said "go" → Implemented all 8 phases: OpenEI client, API methods, models, CLI commands, handlers, tests, docs, changelog 5. User reported `tou get` output was hard to read → Added `--json` flag, made table default, added `print_tou_schedule()` to `OutputFormatter` with both plain and rich implementations 6. User reported Monday was separated from other days in formatting → Fixed `_abbreviate_days()` to collapse consecutive days into ranges (e.g., "Tue–Sat"), added `_collapse_ranges()` helper, fixed weekend special case 7. User reported `tou plan` command crashed with "multiple values for argument 'zip_code'" → Fixed by removing redundant `@click.pass_context` decorators from `tou_plan`, `tou_apply`, and `tou_get` commands 8. User requested `tou plan` also show table by default with `--json` option → Added `--json` flag and `output_json` parameter, refactored handler to use `print_tou_schedule()` by defaultIntent Mapping:
@click.pass_contexttou planmatchtou getformatting (table default,--jsonoption)Technical Inventory:
Code Archaeology:
async_commanddecorator wraps Click commands, injects(mqtt, device, *args, **kwargs)@click.pass_contextis handled BYasync_command— adding it to individual commands causes double-passing bugsOutputFormatterinrich_output.pyhas dual plain/rich implementations for each output methodProgress Assessment:
Recent Commands Analysis:
The most recent operations were:
--jsonflag totou planCLI command in__main__.pyhandle_tou_plan_request()handler withoutput_jsonkwargoutput_json=False(default), delegates to_formatter.print_tou_schedule()output_json=True, builds decoded JSON and usesprint_json()1. Conversation Overview: - Primary Objectives: Implement full OpenEI TOU (Time-of-Use) rate plan integration for nwp500-python library. User said: "I expect to use the cli (or the python api) to be able to perform the same actions as the app via the same api key the app would use. 1. Supply a zip code 2. List utility providers 3. select a utility provider 4. list rate plans 5. Select a specific rate plan and view the rate plan details and metadata 6. Apply the rate plan to the water heater" - Session Context: Started with exploration of existing code, created implementation plan, built all 8 phases (OpenEI client, API methods, models, CLI commands, handlers, tests, docs, validation), then iterated on CLI output formatting and bug fixes across 4 additional rounds. - User Intent Evolution: Implementation → Make output human-readable (table by default, `--json` option) → Fix day formatting (Monday separated) → Fix CLI crash (duplicate `@click.pass_context`) → Make `tou plan` match `tou get` formatting- Technical Foundation:
- nwp500-python: Python async control library for Navien NWP500 heat pump water heaters
- OpenEI API v7:
- Navien TOU flow (from HAR captures): GET /device/tou → GET openei.org → POST /device/tou/convert → PUT /device/tou → MQTT tou-on
- Linting: ruff (80 char line limit), mypy, pyright;
- Testing: pytest, 426 tests passing (excluding
- CLI framework: Click with
- Output:
https://api.openei.org/utility_rates— utility rate plan database; API key fromOPENEI_API_KEYenv var (Navien app hardcodesD8QhQKaB0DCM77tEhklCCjPDkjzxO9ZKJcW8zuMe)make ci-lintruns all threetest_mqtt_hypothesis.pywhich needs missinghypothesismodule)async_commanddecorator that handles auth/MQTT connection and passes(mqtt, device, *args, **kwargs)to command functionsOutputFormatterclass inrich_output.pywith dual...Created from Copilot CLI via the copilot delegate command.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.