Skip to content

Fix excessive token api calls during reconnections#259

Open
elad-bar wants to merge 49 commits into
mainfrom
develop
Open

Fix excessive token api calls during reconnections#259
elad-bar wants to merge 49 commits into
mainfrom
develop

Conversation

@elad-bar
Copy link
Copy Markdown
Collaborator

  • Implement exponential backoff for reconnection attempts to prevent aggressive retries
    • Initial retry after 1 minute, increasing to 2, 4, 8, and maximum 15 minutes
    • Reduces server load during extended connection issues
  • Add AWS IoT credential caching with 2-hour validity
    • Credentials are cached and reused for 1h50m after successful fetch
    • Eliminates redundant token API calls when credentials are still valid
  • Implement rate limiting for token endpoint calls
    • Minimum 5-minute interval between token API requests
    • Protects against API rate limiting during recurring disconnection issues
  • Reduce token API calls from ~20-30 per hour during outages to ~1 per hour maximum
  • Fix excessive API calls to Maytronics token endpoint during recurring disconnections
  • Fix integration-version header value

Elad Bar and others added 24 commits December 30, 2025 14:17
…-during-reconnections

Fix excessive token api calls during reconnections
…ion. Added is_disconnected method to ConnectivityStatus, updated reset_login_details to preserve motor unit serial, and refined error handling in RestAPI for better token management and logging.
…edentials before API calls. This ensures fresh authentication when tokens are outdated, improving overall security and reliability.
…tes and adjust update intervals. Implement debouncing for MQTT refresh to optimize performance and prevent excessive calls. Update tests to reflect changes in AWSClient initialization.
…andling, refactoring AWSClient for real-time MQTT updates, and enhancing connectivity status handling. Add documentation for MQTT update debouncing and workflows.
Maytronics retired the legacy mbapp18.maytronics.com email/password
login. Switch to the working scheme: Cognito CUSTOM_AUTH email OTP +
bearer-token calls against apps.maytronics.com.

- Two-step config flow: collect email -> Cognito InitiateAuth ->
  collect OTP -> RespondToAuthChallenge -> profile + AWS STS creds
- Persist id-token / refresh-token / id-token-expires-at; refresh via
  REFRESH_TOKEN_AUTH within 5 min of expiry
- Swap robot details refresh to apps.maytronics.com/mobapi/user/
  authenticate-user/ (bearer) and AWS creds to /mt-sso/aws/getToken/
- Preserve develop's improvements: IntegrationInfo User-Agent header,
  AWS_CREDENTIALS_TTL caching, MIN_TOKEN_FETCH_INTERVAL rate limit,
  RECONNECT_BACKOFF_MAX 401 token-age check, force_log_level on
  _set_status, is_disconnected() resets _device_loaded,
  reset_login_details() preserves motor_unit_serial
- Drop password field, AES helpers, email-validation, reset-password,
  and the now-unused PasswordManager
- Existing users: remove and re-add the integration after upgrading
- Bump version to 1.0.25b6 (pre-release)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… enhancing validation for motor unit serials and AWS tokens, and improving connectivity status handling. Refactor AWSClient for real-time MQTT updates and add relevant documentation.
@elad-bar
Copy link
Copy Markdown
Collaborator Author

elad-bar commented May 9, 2026

@sh00t2kill can you pls approve this pr, also if you can exclude me from the rule that i need you for merging it, thank you!

@elad-bar
Copy link
Copy Markdown
Collaborator Author

elad-bar commented May 9, 2026

Settings → Branch protection rules → Edit (main branch) →
“Allow specified actors to bypass required pull requests”

Just add my user there.

elad-bar and others added 4 commits May 9, 2026 12:31
Replace login with Cognito OTP flow
…eflect new Cognito OTP login flow integration.
…ve code formatting across multiple files. Adjust README formatting for clarity and enhance import organization in MyDolphin Plus component files.
elad-bar and others added 21 commits May 9, 2026 12:48
- Introduced STORAGE_DATA_LAST_AWS_CREDENTIALS_FETCH to track the last fetch timestamp for AWS credentials.
- Updated ConfigManager to include a property for last AWS credentials fetch and methods to update this timestamp.
- Enhanced REST API calls to include user-agent headers using IntegrationInfo.
- Added tests to verify user-agent header inclusion and AWS credentials fetch behavior under rate-limiting conditions.
- Added support for reauthentication when the refresh token expires, allowing users to complete the OTP login flow without needing to remove and re-add the integration.
- Updated README to clarify the reconfiguration process for users upgrading from pre-OTP versions.
- Enhanced flow manager and coordinator to handle reauthentication logic and state management.
- Introduced new strings for reauthentication prompts and success messages.
- Added tests to ensure the reauthentication flow behaves as expected under various scenarios.
- Introduced new strings for successful reauthentication and session expiration prompts in English and Italian translations.
- Enhanced user experience by providing clear instructions for reauthentication when sessions expire.
Add CONTRIBUTING.md and update README to include contribution guidelines
- Preserve stored Cognito tokens across Home Assistant restarts when cached AWS IoT credentials expire.
- Clear only stale AWS credential cache metadata to allow for refreshing credentials without requiring reauthentication.
- Bump version in manifest.json to v1.0.26b2.
- Added entry for version v1.0.26b3 in CHANGELOG.md.
- Fixed vacuum pause control to send the power-off command for active robots instead of only when docked.
- Bumped version in manifest.json to v1.0.26b3.
- Added tests to verify vacuum pause functionality for active and docked states.
Update changelog and fix vacuum pause behavior
- Updated CHANGELOG.md for version v1.0.26b3 with new config entry handling and removal of deprecated connection class usage.
- Refactored async_unload_entry and async_remove_entry methods to improve config entry management and ensure proper unloading of platforms.
- Adjusted DomainFlowHandler and DomainOptionsFlowHandler to eliminate deprecated connection class references and streamline options flow handling.
Add French translation (fr.json)
Update changelog and refactor MyDolphin Plus integration
- Updated fr.json to include new configuration steps and error messages in French.
- Enhanced user experience with detailed descriptions for account setup and reauthentication processes.
- Updated CHANGELOG.md to reflect the addition of French translation support.
…Maytronics integration, covering setup, startup, ongoing calls, error recovery, and entity actions. This update enhances user guidance and clarifies integration processes with detailed diagrams and flow descriptions.
- Updated tables in overview, OTP setup, startup, ongoing calls, error recovery, and entity actions sections for better readability.
- Enhanced formatting for endpoints, parameters, and status values to ensure uniformity across documents.
- Improved overall structure and presentation of information to facilitate user understanding of the Maytronics integration processes.
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.

3 participants