Add configurable update interval for LTR390 sensor#56
Add configurable update interval for LTR390 sensor#56
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. WalkthroughAdded a public template number entity and a global timestamp, and implemented interval-based polling (1s timer) to drive LTR390 updates by comparing now vs last update and calling the sensor's update when the user-configurable interval elapses. Two identical 1s interval blocks were added. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User as User (UI/Config)
participant Num as Number Entity\n`ltr390_update_interval`
participant Timer as 1s Interval Timer
participant Globals as Global Storage\n`ltr390_last_update`
participant Sensor as LTR390 Sensor
User->>Num: set interval (seconds)
Note right of Num: stored as entity state
Timer->>Globals: read `ltr390_last_update`
Timer->>Num: read `.state` (interval)
Timer->>Timer: compute current_time = millis()/1000
alt current_time - last_update >= interval
Timer->>Sensor: call update()
Sensor-->>Globals: return (success)
Timer->>Globals: write `ltr390_last_update = current_time`
else not yet elapsed
Timer-->>Timer: wait next tick
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
83db9fd to
0c067fa
Compare
Allows users to adjust the LTR390 sensor update frequency from the default 60 seconds to any value between 1-300 seconds through the web interface, eliminating the need for YAML edits and firmware recompilation. Uses ESPHome's interval component to manually poll the sensor at the configured rate, as sensor platform update_interval is not templatable. The setting is exposed as a number input under the CONFIG entity category with values persisted across device reboots. Resolves #54 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
0c067fa to
9dd9982
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@Integrations/ESPHome/Core.yaml`:
- Around line 164-176: Add a new template number sensor named ltr390_lux_offset
(same pattern as DPS310 temperature offset: restore_value true, initial_value 0,
wide min/max, unit "lx", entity_category "CONFIG", optimistic true,
update_interval never, step 1, mode box) right after the existing template
numbers block; then update the LTR390 light filter lambda so the filter uses the
offset by changing the current_value assignment from the hardcoded value to
incorporate the offset (replace the current_value assignment with one that adds
id(ltr390_lux_offset).state), ensuring you reference the id ltr390_lux_offset in
the lambda.
Add check for first boot condition (last_update == 0 && current_time > 0) to trigger an immediate sensor update instead of waiting for the full configured interval to elapse. The current_time > 0 guard prevents edge case where both values are 0 in the first second after boot. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
This PR implements the configurable update interval requested in #54 for the LTR390 light sensor.
Changes
Number Input Added
LTR390 Update Interval- Configurable sensor polling rate (1-300 seconds, default: 60s)Sensor Configuration Updates
update_intervaltonever(disables automatic polling)ltr390_last_updateto track last sensor update timeintervalcomponent that runs every 1 second to check if configured interval has elapsedcomponent.update()when neededTechnical Details
Why use interval component?
ESPHome sensor platforms don't support templatable
update_intervalparameters. Attempting to use a lambda forupdate_intervalresults in compilation error: "This option is not templatable!"How it works:
update_interval: never)id(ltr_390).update()The setting:
restore_value: true)Benefits
Users can now adjust the LTR390 sensor update frequency without:
Simply adjust the value through the web interface and the sensor will update at the new interval.
Testing
Resolves
Closes #54
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.