Skip to content

Conversation

dcapslock
Copy link
Collaborator

Closes #436

Screen.Recording.2025-08-31.at.5.00.35.pm.mov

@Copilot Copilot AI review requested due to automatic review settings August 31, 2025 07:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an update_timer feature that allows button cards to automatically refresh at specified intervals. This is particularly useful for cards without entities or when triggers_update is not suitable.

Key changes:

  • Added new update_timer configuration option that accepts a number (>=100ms) or template
  • Implemented timer-based card refresh mechanism with proper cleanup
  • Added comprehensive documentation and test examples

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/types/types.ts Added update_timer property to button card configuration interfaces
src/button-card.ts Implemented timer logic with timeout management and refresh mechanism
test/ui-lovelace.yaml Added test cases demonstrating static and template-based update timers
README.md Documented the new update_timer feature with usage guidelines

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@RomRider
Copy link
Collaborator

Thanks!

What about using https://www.npmjs.com/package/parse-duration to parse the field to make it a bit more user friendly?

One thing however, I think that if update_interval is set, nothing else should trigger an update of the card. WDYT?

@dcapslock
Copy link
Collaborator Author

I have implemented parse, also added as a helper parseDuration which will a good addition. I added locale support but not 100% dynamic if locales added due to how the parse library manages locales. I think it is OK maintenence wise.

Regarding when to update, I have left as is. Suppose a user is using an entity, which needs to update, but then also an update timer of say '1 minute' for a slow updating custom_field. In this case only updating on the updates_timer will miss the entity update.

@RomRider
Copy link
Collaborator

RomRider commented Sep 1, 2025

Regarding when to update, I have left as is. Suppose a user is using an entity, which needs to update, but then also an update timer of say '1 minute' for a slow updating custom_field. In this case only updating on the updates_timer will miss the entity update.

I do agree with the use case, but I'm pretty sure some users would want to ONLY update on interval 😄 Maybe an option to force only updating on interval? enforce_update_timer with a default to false?

@dcapslock
Copy link
Collaborator Author

enforce_update_timer with a default to false?

How about triggers_update: update_timer?

@dcapslock
Copy link
Collaborator Author

dcapslock commented Sep 1, 2025

How about triggers_update: update_timer?

This has been added including to make sure that if update_timer is in use and hass updated that the duration is checked, and if not the same as active, then return true for shouldUpdate. New timer will be started after the update (existing) which makes sure not to intriduced any update loops.

I think the doco makes sense. I tried not to be too wordy.

@RomRider RomRider dismissed their stale review September 15, 2025 14:02

Not needed

@RomRider RomRider merged commit 4717feb into custom-cards:dev Sep 16, 2025
3 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 16, 2025
## [5.0.0-dev.1](v4.3.0...v5.0.0-dev.1) (2025-09-16)

### ⚠ BREAKING CHANGES

* **color:** Card background color will always be `var
(--card-background-color)` when state is inactive and `color_type:
card`. You can set card background with state.

### Features

* Add `icon_*_action` support ([#984](#984)) ([4e02887](4e02887)), closes [#739](#739)
* Support update timer ([#981](#981)) ([4717feb](4717feb)), closes [#436](#436)

### Bug Fixes

* **color:** inactive card background no longer inactive color when `colour_type: card` and `color` set. ([#987](#987)) ([b4f00f9](b4f00f9)), closes [#754](#754)
* Embedded light card handle issue ([#989](#989)) ([d01ef37](d01ef37)), closes [#427](#427) [#901](#901)
* Hold action on picture entity ([#996](#996)) ([9f2501f](9f2501f)), closes [#994](#994)
* Move while hold on touch devices ([#993](#993)) ([2c17386](2c17386))
Copy link

🎉 This PR is included in version 5.0.0-dev.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@dcapslock dcapslock deleted the update-timer branch September 16, 2025 11:47
dcapslock added a commit to dcapslock/button-card that referenced this pull request Sep 17, 2025
dcapslock pushed a commit to dcapslock/button-card that referenced this pull request Sep 17, 2025
## [5.0.0-dev.1](custom-cards/button-card@v4.3.0...v5.0.0-dev.1) (2025-09-16)

### ⚠ BREAKING CHANGES

* **color:** Card background color will always be `var
(--card-background-color)` when state is inactive and `color_type:
card`. You can set card background with state.

### Features

* Add `icon_*_action` support ([custom-cards#984](custom-cards#984)) ([4e02887](custom-cards@4e02887)), closes [custom-cards#739](custom-cards#739)
* Support update timer ([custom-cards#981](custom-cards#981)) ([4717feb](custom-cards@4717feb)), closes [custom-cards#436](custom-cards#436)

### Bug Fixes

* **color:** inactive card background no longer inactive color when `colour_type: card` and `color` set. ([custom-cards#987](custom-cards#987)) ([b4f00f9](custom-cards@b4f00f9)), closes [custom-cards#754](custom-cards#754)
* Embedded light card handle issue ([custom-cards#989](custom-cards#989)) ([d01ef37](custom-cards@d01ef37)), closes [custom-cards#427](custom-cards#427) [custom-cards#901](custom-cards#901)
* Hold action on picture entity ([custom-cards#996](custom-cards#996)) ([9f2501f](custom-cards@9f2501f)), closes [custom-cards#994](custom-cards#994)
* Move while hold on touch devices ([custom-cards#993](custom-cards#993)) ([2c17386](custom-cards@2c17386))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants