Do not ensure token for calls to gestalt#49
Conversation
WalkthroughAdds an optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ttls/client.py (1)
216-216: Consider updating test mocks for consistency.The test mocks in
tests/test_generic.py(lines 23-30) don't explicitly declare therequire_tokenparameter. They'll work correctly since**kwargsabsorbs it, but you may want to update them for documentation purposes:async def _post(self, endpoint: str, require_token: bool = True, **kwargs) -> Any: async def _get(self, endpoint: str, require_token: bool = True, **kwargs) -> Any:This is optional—the tests will pass either way.
Also applies to: 241-241
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ttls/client.py(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ttls/client.py (1)
tests/test_generic.py (2)
_post(24-25)_get(27-31)
🔇 Additional comments (3)
ttls/client.py (3)
216-219: LGTM!Clean implementation with backward-compatible default. The conditional token enforcement is clear and maintainable.
241-244: Approve with minor note on retry behavior.The implementation is correct. However, note that
_handle_authorized(line 283) doesn't forward therequire_tokenparameter when retrying—it defaults back toTrue. This is acceptable for thegestaltendpoint since it won't return 401, and for other endpoints using the defaultrequire_token=True, this behavior is correct.If you later add other endpoints with
require_token=Falsethat might return 401 for other reasons, consider preserving the parameter:async def _handle_authorized(self, request_method: Callable, endpoint: str, exception: Exception, **kwargs) -> None: # ... - return await request_method(endpoint, headers=self._headers, retry_num=retry_num, **kwargs) + return await request_method(endpoint, require_token=kwargs.pop("require_token", True), headers=self._headers, retry_num=retry_num, **kwargs)For the current use case, this is not necessary.
Also applies to: 260-266
338-339: LGTM! Correctly addresses issue #48.This change prevents
ensure_token()from being called for thegestaltendpoint, which doesn't require authentication. This fixes the Home Assistant discovery issue where token handling was being triggered unnecessarily.
|
Can confirm this is working for me as expected. ttls --host 192.168.0.245 mode |
Calling
gestaltdoes not require an authentication token.Closes #48
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.