Skip to content

fix: clamp 24:00 end times to 23:59 (#95)#243

Open
tomquist wants to merge 6 commits intodevelopfrom
fix/issue-95-time-period-24h
Open

fix: clamp 24:00 end times to 23:59 (#95)#243
tomquist wants to merge 6 commits intodevelopfrom
fix/issue-95-time-period-24h

Conversation

@tomquist
Copy link
Owner

@tomquist tomquist commented Feb 4, 2026

Fixes #95.

Home Assistant time text entities do not accept "24:00" (regex allows 00:00..23:59 only). Some devices report end-times as "24:00" as an end-of-day marker, which leads to HA log errors like:

ValueError: Entity ..._end_time provides state 24:00 which does not match expected pattern ...

This PR:

  • clamps received/parsing end times of exactly "24:00" to "23:59" so HA accepts the state
  • maps "23:59" back to "24:00" when building time-period commands so the device keeps the intended end-of-day semantics

Applies to:

  • B2500V2 end-time fields via timeString({ clamp24hEnd: true }) + command parameter mapping in buildTimePeriodParams
  • Venus/Jupiter time period parsing (24:00 -> 23:59) and command building (23:59 -> 24:00)

Tests:

  • added unit test for the new timeString({ clamp24hEnd: true }) option

Summary by CodeRabbit

  • Bug Fixes

    • Fixed end-of-day time handling for device commands to properly convert between 24:00 and 23:59 formats when communicating with Home Assistant.
  • Tests

    • Added tests to verify correct time formatting for end-of-day scenarios across supported devices.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

Warning

Rate limit exceeded

@tomquist has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

Multiple device implementations and the core transform system are updated to handle time period end times. The solution converts "24:00" (device-side end-of-day marker) to "23:59" (Home Assistant valid format) to resolve Home Assistant text entity validation failures. This involves adding an optional clamp24hEnd parameter to the timeString transform and applying it selectively across device implementations.

Changes

Cohort / File(s) Summary
Core Transform Enhancement
src/transforms.ts, src/transforms.test.ts
Adds optional clamp24hEnd?: boolean to TimeStringTransform interface and timeString() factory. Implements clamping logic in runtime execution and Jinja2 template generation to convert "24:00" to "23:59" when enabled. Test verifies clamp behavior for 24:00 specifically while preserving padding for other times like 24:01.
B2500V2 Device
src/device/b2500V2.ts
Updates endTime transformation to use timeString({ clamp24hEnd: true }), enabling clamped formatting for end times.
Multi-Device Time Period Mapping
src/device/jupiter.ts, src/device/venus.ts
Implements bidirectional time conversion: outbound mapping transforms endTime "23:59" to "24:00" when publishing; inbound parsing derives startTime and endTime from parts and normalizes "24:00" to "23:59" for Home Assistant text entities. Mapping applied across all time-period-related commands.
Control Handler Tests
src/controlHandler.test.ts
Adds new test verifying that B2500 devices do not transform end time of 23:59 to 24:00, asserting payload contains e1=23:59.
Documentation
CHANGELOG.md
Adds changelog entry documenting the fix for transforming time period end times between device marker (24:00) and Home Assistant entity format (23:59).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • #246: Modifies B2500 timer period field formatting to normalize times via formatTimeForB2500V2, directly related to end-time handling for the same device model.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: clamp 24:00 end times to 23:59 (#95)' directly and clearly summarizes the main change: clamping 24:00 end times to 23:59 to resolve Home Assistant validation errors.
Linked Issues check ✅ Passed The PR fully addresses issue #95 requirements: clamping device 24:00 end times to 23:59 for HA compatibility via timeString({ clamp24hEnd: true }), mapping 23:59 back to 24:00 in commands, and adding unit tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the 24:00/23:59 time-clamping objective: transform updates, B2500V2/Venus/Jupiter device mappings, tests, and changelog entry.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-95-time-period-24h

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.

@tomquist tomquist force-pushed the fix/issue-95-time-period-24h branch 2 times, most recently from f948257 to 7bb9ebc Compare February 5, 2026 11:24
@tomquist tomquist force-pushed the fix/issue-95-time-period-24h branch from 4063517 to 5ae91fe Compare February 5, 2026 11:36
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.

1 participant