Skip to content

Add support for wireless switch battery status - #376

Open
matiyau wants to merge 8 commits into
valterc:mainfrom
matiyau:add-support-for-wireless-switch-battery-status
Open

matiyau wants to merge 8 commits into
valterc:mainfrom
matiyau:add-support-for-wireless-switch-battery-status

Conversation

@matiyau

@matiyau matiyau commented Oct 3, 2026 •

Copy link
Copy Markdown

[Issue #313] This PR adds battery indicators and low-battery notifications/alerts for wireless switches.

@matiyau matiyau changed the title Add support for wireless switch battery status Add support for wireless switch battery status (#313) Oct 3, 2026
@matiyau matiyau changed the title Add support for wireless switch battery status (#313) Add support for wireless switch battery status (Issue #313) Oct 3, 2026
@matiyau
matiyau force-pushed the add-support-for-wireless-switch-battery-status branch 6 times, most recently from 011daa7 to 1d31059 Compare October 3, 2026 23:47
@matiyau
matiyau force-pushed the add-support-for-wireless-switch-battery-status branch from 1d31059 to fb57c8d Compare October 4, 2026 00:32
…rete levels (unknown/low/mid/high) instead of a percentage.
@matiyau
matiyau force-pushed the add-support-for-wireless-switch-battery-status branch 4 times, most recently from 2334d30 to cde9134 Compare October 4, 2026 21:31
Comment thread app/src/main/java/com/valterc/ki2/data/switches/SwitchChannel.java
<string name="text_signal">Signal</string>
<string name="text_connection_status">Connection Status</string>
<string name="text_battery">Battery</string>
<string name="text_main_battery">Main Battery</string>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not really sure what to call this one: Main Battery/Central Battery/System Battery?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe Shifting Battery? Also not sure...

@matiyau
matiyau force-pushed the add-support-for-wireless-switch-battery-status branch from cde9134 to 6da6ac6 Compare October 4, 2026 22:48
@matiyau
matiyau force-pushed the add-support-for-wireless-switch-battery-status branch from 6da6ac6 to fc0a411 Compare October 4, 2026 23:02
@matiyau
matiyau marked this pull request as ready for review October 4, 2026 23:11
@matiyau matiyau changed the title Add support for wireless switch battery status (Issue #313) Add support for wireless switch battery status Oct 4, 2026

@valterc valterc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is great, thanks!
Looks good overall, some minor comments. Still need to give it a try in Karoo.

Comment on lines +76 to +79
lowBatteryRecords.filter { !it.alertedInRide }.forEach { alertRecord ->
alertRecord.alertedInRide = true
alertInRide(alertRecord)
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Haven't tried it, how does it look when multiple wireless switches have low battery? Would it be better to send a single InRideAlert with all low battery switches like you do for the SystemNotification?

<string name="summary_preference_ant_recording">Record all ANT events and data into a file for debugging</string>
<string name="summary_preference_fit_recording_device_info">Record identifiers of the Di2 device in use into the ride FIT file</string>
<string name="summary_preference_battery_notification">Show notifications when the shifting battery level is at or below a certain value</string>
<string name="summary_preference_battery_notification">Show notifications when the main battery level is at or below a certain value, or when a wireless switch battery is low</string>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
<string name="summary_preference_battery_notification">Show notifications when the main battery level is at or below a certain value, or when a wireless switch battery is low</string>
<string name="summary_preference_battery_notification">Show notifications when the shifting battery level is at or below a certain value, or when a wireless switch battery is low</string>

Maybe keep shifting battery?

Comment on lines +60 to +69
val stateLock = Any()
var state = ViewState()
val states = Channel<ViewState>(Channel.CONFLATED)

fun updateState(transform: (ViewState) -> ViewState) {
synchronized(stateLock) {
state = transform(state)
states.trySend(state)
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
val stateLock = Any()
var state = ViewState()
val states = Channel<ViewState>(Channel.CONFLATED)
fun updateState(transform: (ViewState) -> ViewState) {
synchronized(stateLock) {
state = transform(state)
states.trySend(state)
}
}
var state = ViewState()
val states = Channel<ViewState>(Channel.CONFLATED)
fun updateState(transform: (ViewState) -> ViewState) {
state = transform(state)
states.trySend(state)
}

Not sure why we need the synchronized?

Comment on lines +418 to +422
<LinearLayout
android:id="@+id/linearlayout_device_details_wireless_switch_batteries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'll give it a try, what is displayed for systems without wireless switches?

<string name="text_signal">Signal</string>
<string name="text_connection_status">Connection Status</string>
<string name="text_battery">Battery</string>
<string name="text_main_battery">Main Battery</string>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe Shifting Battery? Also not sure...

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