Skip to content

fix: handle timedelta type in calculate_update_interval#46

Closed
Explorer1092 wants to merge 1 commit intohasscc:mainfrom
Explorer1092:fix/calculate-update-interval-timedelta
Closed

fix: handle timedelta type in calculate_update_interval#46
Explorer1092 wants to merge 1 commit intohasscc:mainfrom
Explorer1092:fix/calculate-update-interval-timedelta

Conversation

@Explorer1092
Copy link

Summary

  • Fix TypeError when CONF_SCAN_INTERVAL is validated by Home Assistant's cv.time_period
  • The validator converts the config string to a timedelta object, but calculate_update_interval only expected a string
  • Now supports both string ("HH:MM:SS") and timedelta inputs

Problem

When using YAML configuration, Home Assistant throws:

Error during setup of component catlink: expected string or bytes-like object, got 'datetime.timedelta'

This happens because const.py defines:

vol.Optional(CONF_SCAN_INTERVAL, default=SCAN_INTERVAL): cv.time_period,

The cv.time_period validator converts the string to a timedelta object before it reaches calculate_update_interval.

Test plan

  • Tested with YAML configuration on Home Assistant 2024.12+
  • Verified catlink integration loads successfully after fix

🤖 Generated with Claude Code

The CONF_SCAN_INTERVAL config value is validated by Home Assistant's
cv.time_period validator, which converts the string to a timedelta
object. The calculate_update_interval function was only expecting
a string, causing a TypeError: "expected string or bytes-like object,
got 'datetime.timedelta'".

This fix adds support for both string and timedelta inputs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@milosljubenovic
Copy link
Collaborator

Hey @Explorer1092, your work is included in new release v2.1.1-beta.

Thanks for contributing! 🐱

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