Skip to content

Refactor Improv flow to be more modern and usable in FrontendScreen#6876

Open
TimoPtr wants to merge 2 commits into
mainfrom
feature/refactor_improv_manager
Open

Refactor Improv flow to be more modern and usable in FrontendScreen#6876
TimoPtr wants to merge 2 commits into
mainfrom
feature/refactor_improv_manager

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented May 21, 2026

Summary

This is coming from splitting #6865 in two to isolate the refactor from the actual new code in the FrontendScreen. The idea of the refactor is to fully test the managers and make it more usable for the FrontendScreen.

I've also adjusted the UI, the screenshots are going to be made in the next PR since I want then on top of the FrontendScreen.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Copilot AI review requested due to automatic review settings May 21, 2026 10:44
@TimoPtr TimoPtr requested a review from jpelgrom May 21, 2026 10:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the Improv (BLE Wi‑Fi onboarding) flow to a more lifecycle-driven, Flow-based repository/API and moves the UI components under frontend/improv to make them reusable from FrontendScreen and easier to unit test.

Changes:

  • Replaced the legacy improv repository with a new frontend.improv repository exposing scanDevices() and provisionDevice() as collector-driven Flows, plus new ImprovUIState/ProvisioningEvent models
  • Updated WebView presenter + dialogs to use the new repository API and new Compose UI components (HA design system)
  • Added unit tests for ImprovRepositoryImpl

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/src/test/kotlin/io/homeassistant/companion/android/webview/WebViewPresenterImplTest.kt Updates import to the new frontend.improv.ImprovRepository
app/src/test/kotlin/io/homeassistant/companion/android/frontend/improv/ImprovRepositoryImplTest.kt Adds unit tests for permissions, scanning lifecycle, and provisioning event flow
app/src/main/kotlin/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt Switches presenter Improv scanning to scanDevices() and new permission API
app/src/main/kotlin/io/homeassistant/companion/android/improv/ui/ImprovSetupDialog.kt Reworks dialog to use new ImprovUIState + provisioning flow and HA-themed sheet content
app/src/main/kotlin/io/homeassistant/companion/android/improv/ui/ImprovPermissionDialog.kt Updates permission rationale dialog to use new UI + requiredPermissions API
app/src/main/kotlin/io/homeassistant/companion/android/improv/ui/ImprovSheetView.kt Removes legacy Improv sheet UI implementation (moved to frontend)
app/src/main/kotlin/io/homeassistant/companion/android/improv/ui/ImprovSheetState.kt Removes legacy sheet state model (replaced by ImprovUIState)
app/src/main/kotlin/io/homeassistant/companion/android/improv/ui/ImprovPermissionView.kt Removes legacy permission view (moved to frontend)
app/src/main/kotlin/io/homeassistant/companion/android/improv/ImprovRepositoryImpl.kt Removes legacy repository implementation
app/src/main/kotlin/io/homeassistant/companion/android/improv/ImprovRepository.kt Removes legacy repository interface
app/src/main/kotlin/io/homeassistant/companion/android/improv/ImprovModule.kt Removes legacy Hilt module (bindings moved to frontend module)
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ui/ImprovSheetView.kt Adds new HA design system sheet body driven by ImprovUIState
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ui/ImprovPermissionView.kt Adds new HA design system permission rationale content
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ProvisioningEvent.kt Adds provisioning event model emitted by provisionDevice()
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ImprovUIState.kt Adds UI state machine model for the Improv flow
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ImprovRepositoryImpl.kt Adds new Flow-driven repository with WhileSubscribed scan management and provisioning flow
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ImprovRepository.kt Adds new repository interface with requiredPermissions, scanDevices, provisionDevice
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/ImprovManagerFactory.kt Adds factory abstraction to avoid Context in the repository and improve testability
app/src/main/kotlin/io/homeassistant/companion/android/frontend/improv/FrontendImprovModule.kt Binds new repository and provides ImprovManagerFactory

Comment on lines +67 to +70
if (savedInstanceState == null) {
val name = arguments?.getString(ARG_NAME).orEmpty()
screenState.value = ImprovUIState.SearchingDevice(deviceName = name)
}
* sentinel returned by [WifiManager.getConnectionInfo] when the app lacks the location permission.
*/
private fun String?.takeIfDisplayable(): String? = takeIf {
!it.isNullOrBlank() && (Build.VERSION.SDK_INT < Build.VERSION_CODES.R || it !== WifiManager.UNKNOWN_SSID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants