Skip to content

feat: Add Xiaomi MiMo provider with session-based authentication#10

Merged
DimazzzZ merged 4 commits into
mainfrom
feat/xiaomi-providers
Jun 22, 2026
Merged

feat: Add Xiaomi MiMo provider with session-based authentication#10
DimazzzZ merged 4 commits into
mainfrom
feat/xiaomi-providers

Conversation

@DimazzzZ

Copy link
Copy Markdown
Owner

What

Adds Xiaomi MiMo as a supported provider with two connection types: API (pay-as-you-go) and Token Plan (subscription Credits), using session-based authentication like Nebius.

Why

Xiaomi MiMo platform requires session cookies for balance/usage tracking, similar to Nebius. This PR implements the full provider with shared infrastructure for session-based providers.

Changes

New Provider

  • XiaomiProviderClient — Fetches balance (XIAOMI_API) and Token Plan usage (XIAOMI_TOKEN_PLAN) from Xiaomi platform
  • XiaomiConnectDialog — UI for capturing Xiaomi session via cURL pasting
  • ConnectionType.XIAOMI_API and XIAOMI_TOKEN_PLAN — New connection types with proper metadata

Shared Infrastructure (Refactoring)

  • SessionParser — Generic session parsing with validation, shared across Nebius and Xiaomi
  • HttpErrorHandler — HTTP error code mapping to ProviderResult.Failure, shared across providers
  • CurlCookieExtractor — Cookie extraction from cURL commands, shared across connect dialogs

Status Bar Improvements

  • formatAutoMode now iterates all accounts until finding usable data (fixes "TP: --" bug)
  • Widget refreshes immediately when settings change
  • Xiaomi Token Plan supports all format options: Percentage, Used/Remaining, Remaining only
  • Short number formatting (B/M/K) for credits display
  • Compact and Descriptive format variants for all options

Bug Fixes

  • Account fields changed to var for XStream serialization (fixes accounts not persisting)
  • XIAOMI_TOKEN_PLAN added to usagePercentageTypes (fixes percentage display)
  • Widget refresh on settings change (fixes format dropdown not applying)

Test Coverage

  • 8 new tests for XiaomiProviderClient (error branches, unsupported types, missing fields)
  • 17 new tests for BalanceFormatter (formatShortCredits, formatShortDollars, Xiaomi formatting)
  • All tests pass, detekt clean

Files Modified

  • src/main/kotlin/.../provider/SessionParser.kt (new)
  • src/main/kotlin/.../provider/HttpErrorHandler.kt (new)
  • src/main/kotlin/.../utils/CurlCookieExtractor.kt (new)
  • src/main/kotlin/.../provider/xiaomi/XiaomiProviderClient.kt (new)
  • src/main/kotlin/.../ui/XiaomiConnectDialog.kt (new)
  • src/main/kotlin/.../provider/nebius/NebiusProviderClient.kt (refactored)
  • src/main/kotlin/.../ui/NebiusCurlParser.kt (refactored)
  • src/main/kotlin/.../ui/BalanceFormatter.kt (enhanced)
  • src/main/kotlin/.../ui/TokenPulseStatusBarWidget.kt (enhanced)
  • src/main/kotlin/.../settings/Account.kt (fixed)
  • src/test/kotlin/.../provider/xiaomi/XiaomiProviderClientTest.kt (new)
  • src/test/kotlin/.../ui/BalanceFormatterTest.kt (enhanced)
  • src/test/kotlin/.../ui/XiaomiConnectDialogTest.kt (new)

Verification

  • All tests pass ✓
  • Detekt clean ✓
  • Plugin builds successfully ✓

DimazzzZ added 2 commits June 22, 2026 16:05
…s, add test coverage (#9)

* refactor: clean up code structure and improve utility functions

* refactor: update detekt configuration for improved code analysis
@DimazzzZ DimazzzZ force-pushed the feat/xiaomi-providers branch from a37589c to 42738f3 Compare June 22, 2026 14:08
Comment thread src/main/kotlin/org/zhavoronkov/tokenpulse/ui/BalanceFormatter.kt Fixed
Comment thread src/main/kotlin/org/zhavoronkov/tokenpulse/ui/BalanceFormatter.kt Fixed
Comment thread src/main/kotlin/org/zhavoronkov/tokenpulse/ui/BalanceFormatter.kt Fixed
Comment thread src/main/kotlin/org/zhavoronkov/tokenpulse/ui/BalanceFormatter.kt Fixed
Comment thread src/main/kotlin/org/zhavoronkov/tokenpulse/ui/BalanceFormatter.kt Fixed
@DimazzzZ DimazzzZ force-pushed the feat/xiaomi-providers branch from 3e537df to abad3f6 Compare June 22, 2026 14:18
- Remove unused HTTP constants from NebiusProviderClient
- Remove unused extractCookiesFromBFlag from NebiusCurlParser
- Refactor CurlCookieExtractor to reduce return count
- Fix ArgumentListWrapping in TokenPulseStatusBarWidget and BalanceFormatter
- Extract formatXiaomiTokenPlanCredits and formatUsagePercentage to reduce complexity
- Add SHORT_FORMAT constant for magic number
- Add 1000000000 to detekt ignore list
- Increase TooManyFunctions threshold to 30
- Exclude test files from LargeClass rule
@DimazzzZ DimazzzZ merged commit e6e80cb into main Jun 22, 2026
2 checks passed
@DimazzzZ DimazzzZ deleted the feat/xiaomi-providers branch June 22, 2026 14:38
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