Skip to content

Conversation

@firstof9
Copy link
Owner

@firstof9 firstof9 commented Jan 4, 2026

Related to firstof9/ha-openei#96

Summary by CodeRabbit

  • Refactor

    • Streamlined rate schedule calculation logic for clearer, more maintainable behavior without changing public interfaces
  • Style

    • Minor docstring and formatting cleanups
  • Chores

    • Package version bumped to 0.2.8
    • Development lint/config updated (line-length relaxed)

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

This pull request streamlines next_rate_schedule logic in openeihttp/__init__.py, simplifying docstrings and control flow for detecting rate changes; fixes a docstring formatting minor issue in openeihttp/cache.py; bumps package VERSION to 0.2.8 in setup.py; and raises flake8 max-line-length to 100 in tox.ini.

Changes

Cohort / File(s) Summary
Rate Schedule Logic Refactor
openeihttp/__init__.py
Simplified next_rate_schedule docstring and control flow: adjusted existence check, streamlined outer 12-month loop and month/year handling, appended an extra schedule when current hour > 0, replaced multi-branch change detection with a concise compare-and-return flow, simplified month-boundary check, and now returns (None, current_structure) when search window is exhausted.
Docstring Formatting
openeihttp/cache.py
Removed a leading space in the module-level docstring opening triple quotes; no behavioral changes.
Version & Lint Config
setup.py, tox.ini
Bumped VERSION from 0.2.7 to 0.2.8 in setup.py. Increased flake8 max-line-length from 88 to 100 in tox.ini.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through schedules, trimmed the prose,
Snipped tangled branches where logic grows,
A version bumped, a lint rule raised,
Small tweaks that leave the code well-phrased,
I twitch my nose and on I go! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: fixing end-of-year handling in next_rate_schedule function, which aligns with the substantial logic refactoring shown in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (4.0.4)
openeihttp/__init__.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72d2e90 and 023a2e3.

📒 Files selected for processing (4)
  • openeihttp/__init__.py
  • openeihttp/cache.py
  • setup.py
  • tox.ini
🧰 Additional context used
🪛 Ruff (0.14.10)
openeihttp/__init__.py

269-269: Test for membership should be not in

Convert to not in

(E713)

🔇 Additional comments (5)
tox.ini (1)

43-43: LGTM! Reasonable adjustment to line length limit.

Increasing the max line length from 88 to 100 characters provides more flexibility while maintaining readability.

openeihttp/cache.py (1)

1-1: LGTM! Docstring formatting improvement.

The docstring formatting is now consistent with standard Python conventions.

setup.py (1)

9-9: LGTM! Appropriate version bump for a bug fix.

The patch version increment from 0.2.7 to 0.2.8 correctly follows semantic versioning for a bug fix release.

openeihttp/__init__.py (2)

267-267: LGTM! Clearer, more concise docstring.

The simplified docstring is more direct and easier to understand.


275-333: End-of-year and month boundary transitions are already comprehensively tested.

The year-wrapping logic is correct and mathematically sound. The code already includes six test cases covering all the edge cases you mentioned:

  • test_get_next_rate_structure_next_year (Nov 1, 2024 → May 1, 2025) explicitly validates year boundary transitions
  • test_get_next_rate_structure_next_month covers month-end transitions
  • test_get_next_rate_structure_next_month_weekend_start covers weekend/weekday transitions at month boundaries
  • Additional tests cover same-day, next-day, and weekend loop scenarios

The month_idx loop correctly wraps from December to January: when month_idx=12, the calculation year = start.year + (month_idx // 12) increments the year, and month = (month_idx % 12) + 1 resets to month 1.

No additional test coverage is needed.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
openeihttp/__init__.py (1)

269-270: Membership test fix looks good.

The not in operator is now correctly placed, following Python conventions.

🧹 Nitpick comments (1)
openeihttp/__init__.py (1)

301-318: Rate change detection logic is sound.

The logic correctly handles:

  1. Same-day rate changes (line 305-306)
  2. Next-day transitions within the same month (lines 309-318)
  3. Skipping Friday and Sunday for next-day returns since those cross schedule type boundaries

Consider adding a brief comment explaining why [4, 6] (Friday/Sunday) are excluded—they require schedule-type transitions handled by the outer loop.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 023a2e3 and 250e525.

📒 Files selected for processing (1)
  • openeihttp/__init__.py
🔇 Additional comments (2)
openeihttp/__init__.py (2)

322-325: This is the correct fix for end-of-year handling.

Changing from > to != ensures the month boundary check works across year boundaries. Previously, when transitioning from December (12) to January (1), the comparison 1 > 12 was False, causing incorrect behavior. With !=, the check 1 != 12 correctly identifies the month change and breaks to advance through the month loop.


333-333: Appropriate fallback return value.

Returning (None, current_structure) when no rate change is found within the 12-month window is sensible—callers get None for the time (indicating no upcoming change) and the current rate structure as the rate value.

@firstof9 firstof9 merged commit 9602da0 into main Jan 4, 2026
5 checks passed
@firstof9 firstof9 deleted the fix-96 branch January 4, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants