Skip to content

Conversation

@AlexF090
Copy link

Problem

Fixes #919

The integration was vulnerable to string boolean values (like "false") being passed through service calls or configuration, which could cause unexpected behavior since non-empty strings are truthy in Python.

Solution

  • Added ensure_bool() utility function in helpers.py for robust boolean validation
  • Integrated the function in critical service handlers and configuration methods
  • Added comprehensive test coverage for the new function

Changes

  • New: ensure_bool() function with support for common boolean string representations
  • Fixed: Service handlers now use safe boolean validation
  • Fixed: Configuration methods now validate boolean values properly
  • Added: Test coverage for the new utility function

Testing

  • ✅ Unit tests pass
  • ✅ Function handles all common boolean string formats
  • ✅ Backward compatible with existing boolean values

AlexF090 and others added 2 commits July 26, 2025 11:43
- Introduced ensure_bool function to convert various input types to boolean values, enhancing input validation.
- Updated switch.py to utilize ensure_bool for configuration parameters, ensuring consistent boolean handling.
- Added comprehensive unit tests for ensure_bool to cover valid and invalid cases, ensuring reliability.
@AlexF090 AlexF090 marked this pull request as ready for review July 26, 2025 09:51
@AlexF090 AlexF090 requested a review from basnijholt as a code owner July 26, 2025 09:51
@AlexF090
Copy link
Author

I've opened this PR because I'm experiencing the same issue again.
I believe this shouldn't be the responsibility of the users to fix — especially considering that many inexperienced users will likely encounter the same problem in the future.
Maybe it's time to address this properly in the codebase rather than relying on workarounds or custom configurations.

AlexF090 and others added 3 commits July 26, 2025 11:57
- Changed error messages in test_invalid_values and test_error_message_includes_value to use English instead of German for better clarity and consistency.
- Ensured that all invalid input cases provide uniform error messaging.
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.

Assert-error in HA LOG regularly

1 participant