Skip to content

Refactor Zaptec integration to improve polling and command handling#201

Merged
sveinse merged 3 commits intocustom-components:masterfrom
sveinse:feature-poll-functions
Jul 19, 2025
Merged

Refactor Zaptec integration to improve polling and command handling#201
sveinse merged 3 commits intocustom-components:masterfrom
sveinse:feature-poll-functions

Conversation

@sveinse
Copy link
Collaborator

@sveinse sveinse commented Jul 18, 2025

  • New feature: When HA initiates a change or command, the integration will poll the device 2, 5 and 14 seconds after to fetch updated data quickly.
  • Introduced polling methods for charger and installation updates.
  • Replaced direct state updates with trigger_poll calls in various components.
  • Updated command handling in services and entities to use a unified command method.
  • Removed direct commands in favor of the command method

Note

This PR contains a known issue: It contains a new feature which issue a sequence of polls immediately after any HA imitated command or change. If HA makes very frequent changes (<20 secs), there might be many updates running in parallel for the same resource which is not good. This is planned to be fixed in a later PR.

- Introduced polling methods for charger and installation updates.
- Replaced direct state updates with trigger_poll calls in various components.
- Updated command handling in services and entities to use a unified command method.
- Removed direct commands in favor of the command method
@sveinse sveinse added this to the v0.8 milestone Jul 18, 2025
Copy link
Contributor

@steinmn steinmn left a comment

Choose a reason for hiding this comment

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

Doesn't the Zaptec API cache values for 15 seconds or did I misunderstand the docs ( https://docs.zaptec.com/docs/api-fair-use-policy#2-api-usage-and-rate-limiting)? Would we really gain anything by polling multiple times within a 15 second span?

@sveinse
Copy link
Collaborator Author

sveinse commented Jul 18, 2025

Doesn't the Zaptec API cache values for 15 seconds or did I misunderstand the docs ( https://docs.zaptec.com/docs/api-fair-use-policy#2-api-usage-and-rate-limiting)? Would we really gain anything by polling multiple times within a 15 second span?

I am disucussing a lot with Zaptec about this. Notice what is said in #176 (comment)

"There is no caching like mentioned #189 (comment), this is outdated info (fixed now). So, if value in states in still old one it only means that charger hasn't reported it back yet."

@sveinse
Copy link
Collaborator Author

sveinse commented Jul 18, 2025

Would we really gain anything by polling multiple times within a 15 second span?

Zaptec basically want us to significantly increase the poll intervals. Let's say we have a poll interval of 10 minutes during not charging. This means that if we don't poll after sending a command, it may take up to 10 minutes until the user sees the change in HA. I'm sure that won't be acceptable.

The number of polls and timing between them are configurable. So we if find that the proposed scheme is pointless or that we need other timings, we can change it later.

The second half of this post can be worth reading: #176 (comment)

@steinmn
Copy link
Contributor

steinmn commented Jul 18, 2025

Ah, ok, then that objection was based on outdated info and can be safely ignored👌

@sveinse
Copy link
Collaborator Author

sveinse commented Jul 18, 2025

For reference, I created #202

* Make TRIGGER_DELAYS as absolute, adding code for calculating the deltas
* Fixup inconsisten log messages
* Accept both snake_case and PascalCase commands
* Fix variable naming in _trigger_poll
* Add type CommandType to help dev users to suggest what commands to use
* Add docstrings to ZConst
Copy link
Contributor

@steinmn steinmn left a comment

Choose a reason for hiding this comment

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

LGTM

@sveinse sveinse merged commit 0ca219f into custom-components:master Jul 19, 2025
1 check passed
@sveinse sveinse deleted the feature-poll-functions branch July 19, 2025 16:21
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