Conversation
There was a problem hiding this comment.
Pull request overview
Adds NFC tag write support to the Compose-based FrontendScreen flow by wiring the tag/write external-bus message through the handler + ViewModel into a host-launched NFC write activity contract, then responding back to the frontend with a result message.
Changes:
- Introduces
tag/writeas a typed incoming external-bus message and maps it to a newWriteNfcTaghandler event - Adds a new one-shot navigation event (
LaunchNfcWrite) and launchesWriteNfcTagvia anActivityResultContractfromFrontendNavigation - Sends a
resultresponse back to the frontend when the NFC write flow completes, plus adds/updates unit tests across parsing/handler/viewmodel/event-handler layers
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/externalbus/incoming/IncomingExternalBusMessage.kt | Adds TagWriteMessage / TagWritePayload for tag/write incoming messages |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/handler/FrontendMessageHandler.kt | Handles TagWriteMessage and emits FrontendHandlerEvent.WriteNfcTag |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/handler/FrontendHandlerEvent.kt | Adds WriteNfcTag handler event to carry messageId/tagId |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/navigation/FrontendEvent.kt | Adds FrontendEvent.LaunchNfcWrite one-shot event |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/navigation/FrontendNavigation.kt | Launches NFC write flow with rememberLauncherForActivityResult and consumes LaunchNfcWrite |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/externalbus/outgoing/OutgoingExternalBusMessage.kt | Adds ResultMessage.success(...) helper for sending empty success results |
| app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModel.kt | Emits LaunchNfcWrite on handler event and sends ResultMessage on NFC completion |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/externalbus/incoming/IncomingExternalBusMessageTest.kt | Adds JSON parsing tests for tag/write |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/handler/FrontendMessageHandlerTest.kt | Adds handler mapping tests for TagWriteMessage → WriteNfcTag |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/navigation/FrontendEventHandlerTest.kt | Adds event-handler tests for LaunchNfcWrite routing |
| app/src/test/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModelTest.kt | Adds ViewModel tests for emitting LaunchNfcWrite and sending ResultMessage on completion |
| * @param messageId Correlation id from the originating `tag/write` request. | ||
| * @param tagId Optional pre-filled tag identifier. | ||
| */ | ||
| data class LaunchNfcWrite(val messageId: Int, val tagId: String?) : FrontendEvent |
There was a problem hiding this comment.
For consistency with other events: why not navigate to / open NFC write?
Did you already have something specific in mind for delegation/do you have an example? |
Not yet TBH, I need to have another example to brainstorm about what I could do. |
Summary
Add support for NFC write action on the FrontendScreen.
Checklist
Any other notes
I'm not a super fan of adding more and more methods to the view model, we might need to think about how we can limit that a first "easy" thing might be using delegation, but let see how it goes.