Skip to content

Add configurable update interval for LTR390 sensor#72

Merged
bharvey88 merged 3 commits into
betafrom
ltr390-configurable-interval
Mar 3, 2026
Merged

Add configurable update interval for LTR390 sensor#72
bharvey88 merged 3 commits into
betafrom
ltr390-configurable-interval

Conversation

@bharvey88
Copy link
Copy Markdown
Contributor

@bharvey88 bharvey88 commented Mar 2, 2026

Version: 26.3.2.1

What does this implement/fix?

Ports the configurable LTR390 update interval from MSR-2 (PR #56) to MSR-1.

  • Adds ltr390_last_update global to track last poll timestamp
  • Adds LTR390 Update Interval number entity (1–300s, default 60s, CONFIG category, persists across reboots)
  • Sets update_interval: never on the LTR390 sensor to disable auto-polling
  • Drives polling via a 1s interval lambda — triggers immediately on boot, then respects the configured interval

Types of changes

  • Bugfix (fixed change that fixes an issue)
  • New feature (thanks!)
  • Breaking change (repair/feature that breaks existing functionality)
  • Dependency Update - Does not publish
  • Other - Does not publish
  • Website of github readme file update - Does not publish
  • Github workflows - Does not publish

Checklist / Checklijst:

  • The code change has been tested and works locally
  • The code change has not yet been tested

If user-visible functionality or configuration variables are added/modified:

  • Added/updated documentation for the web page

Summary by CodeRabbit

  • New Features
    • LTR390 sensor now supports a configurable update interval (default 60s, range 1–300s) for flexible monitoring.
    • Sensor refreshes are now scheduled by that interval (no automatic continuous updates), with an immediate refresh on boot.
    • Scheduling checks occur at a 1-second cadence for timely, interval-driven updates.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 2, 2026

Warning

Rate limit exceeded

@bharvey88 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 26 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 60196d1 and a0f8fce.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

Walkthrough

Added interval-driven update control for the LTR390 sensor: a global uint32_t timestamp tracks last update, a public template number configures the update cadence (1–300s, default 60s), the sensor's automatic updates are disabled, and a 1s interval block conditionally triggers sensor refreshes.

Changes

Cohort / File(s) Summary
LTR390 Configurable Update Interval
Integrations/ESPHome/Core.yaml
Added public global ltr390_last_update (uint32_t). Introduced public template number ltr390_update_interval (units: seconds, initial: 60, min: 1, max: 300). Set id: ltr_390 sensor to update_interval: never. Added interval: 1s block that checks ltr390_last_update vs ltr390_update_interval and calls id(ltr_390).update(); updates ltr390_last_update on refresh and performs immediate boot update when last_update == 0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble on timestamps and tune the beat,
every second I check with tiny feet.
Sixty by default, you set the race,
LTR390 hops on cue — steady pace. 🐇✨

🚥 Pre-merge checks | ✅ 3
✅ 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 clearly describes the main change: adding a configurable update interval for the LTR390 sensor, which is the primary objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 ltr390-configurable-interval

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
Copy Markdown

@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

🧹 Nitpick comments (1)
Integrations/ESPHome/Core.yaml (1)

154-167: Please confirm disabled_by_default is intentional for this new user-facing control.

Line 157 disables the new interval entity by default, which can make the feature harder to discover.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Integrations/ESPHome/Core.yaml` around lines 154 - 167, Review whether the
template sensor "LTR390 Update Interval" (id: ltr390_update_interval) should be
user-visible by default; if disabling by default was unintended, remove the
disabled_by_default: true line (or set it to false) so the new entity is enabled
and discoverable, otherwise leave it and add a comment in the YAML documenting
the intentional reason for keeping disabled_by_default on this entity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 729-745: The interval parsing is brittle because
id(ltr390_update_interval).state may be NAN at boot and the first-poll check
uses an unnecessary current_time > 0 guard; update the lambda to read the float
configured_interval = id(ltr390_update_interval).state, use
isnan(configured_interval) and configured_interval >= 1.0f to decide the
interval (fallback to a safe default like 60s), cast that to uint32_t for
interval, and remove the current_time > 0 check so the immediate boot update
triggers when id(ltr390_last_update) == 0; ensure you still call
id(ltr_390).update() and set id(ltr390_last_update) = current_time as before.

---

Nitpick comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 154-167: Review whether the template sensor "LTR390 Update
Interval" (id: ltr390_update_interval) should be user-visible by default; if
disabling by default was unintended, remove the disabled_by_default: true line
(or set it to false) so the new entity is enabled and discoverable, otherwise
leave it and add a comment in the YAML documenting the intentional reason for
keeping disabled_by_default on this entity.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81535a9 and 1e3829a.

📒 Files selected for processing (1)
  • Integrations/ESPHome/Core.yaml

Comment thread Integrations/ESPHome/Core.yaml
@bharvey88 bharvey88 merged commit 6b34d27 into beta Mar 3, 2026
11 checks passed
@bharvey88 bharvey88 deleted the ltr390-configurable-interval branch March 3, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants