-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thanks to @docgalaxyblock
- Loading branch information
Showing
5 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app-common/src/main/java/eu/darken/capod/pods/core/apple/beats/PowerBeats4.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package eu.darken.capod.pods.core.apple.beats | ||
|
||
import eu.darken.capod.common.bluetooth.BleScanResult | ||
import eu.darken.capod.common.debug.logging.logTag | ||
import eu.darken.capod.pods.core.PodDevice | ||
import eu.darken.capod.pods.core.apple.ApplePods | ||
import eu.darken.capod.pods.core.apple.SingleApplePods | ||
import eu.darken.capod.pods.core.apple.SingleApplePodsFactory | ||
import eu.darken.capod.pods.core.apple.airpods.HasStateDetectionAirPods | ||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing | ||
import java.time.Instant | ||
import javax.inject.Inject | ||
|
||
data class PowerBeats4( | ||
override val identifier: PodDevice.Id = PodDevice.Id(), | ||
override val seenLastAt: Instant = Instant.now(), | ||
override val seenFirstAt: Instant = Instant.now(), | ||
override val seenCounter: Int = 1, | ||
override val scanResult: BleScanResult, | ||
override val proximityMessage: ProximityPairing.Message, | ||
override val reliability: Float = PodDevice.BASE_CONFIDENCE, | ||
private val rssiAverage: Int? = null, | ||
) : SingleApplePods, HasStateDetectionAirPods { | ||
|
||
override val model: PodDevice.Model = PodDevice.Model.POWERBEATS_4 | ||
|
||
override val rssi: Int | ||
get() = rssiAverage ?: super<SingleApplePods>.rssi | ||
|
||
class Factory @Inject constructor() : SingleApplePodsFactory(TAG) { | ||
|
||
override fun isResponsible(message: ProximityPairing.Message): Boolean = message.run { | ||
getModelInfo().full == DEVICE_CODE && length == ProximityPairing.PAIRING_MESSAGE_LENGTH | ||
} | ||
|
||
override fun create(scanResult: BleScanResult, message: ProximityPairing.Message): ApplePods { | ||
var basic = PowerBeats4(scanResult = scanResult, proximityMessage = message) | ||
val result = searchHistory(basic) | ||
|
||
if (result != null) basic = basic.copy(identifier = result.id) | ||
updateHistory(basic) | ||
|
||
if (result == null) return basic | ||
|
||
return basic.copy( | ||
identifier = result.id, | ||
seenFirstAt = result.seenFirstAt, | ||
seenLastAt = scanResult.receivedAt, | ||
seenCounter = result.seenCounter, | ||
reliability = result.reliability, | ||
rssiAverage = result.rssiSmoothed(basic.rssi), | ||
) | ||
} | ||
} | ||
|
||
companion object { | ||
private val DEVICE_CODE = 0x0D20.toUShort() | ||
private val TAG = logTag("PodDevice", "Beats", "PowerBeats", "4") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app-common/src/test/java/eu/darken/capod/pods/core/apple/beats/PowerBeats4Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package eu.darken.capod.pods.core.apple.beats | ||
|
||
import eu.darken.capod.pods.core.PodDevice | ||
import eu.darken.capod.pods.core.apple.BaseAirPodsTest | ||
import eu.darken.capod.pods.core.apple.airpods.HasStateDetectionAirPods | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
|
||
class PowerBeats4Test : BaseAirPodsTest() { | ||
|
||
@Test | ||
fun `playing music`() = runTest { | ||
create<PowerBeats4>("07 19 01 0D 20 00 02 80 01 00 05 07 C5 E1 9C BD 9A 05 0E AE 9E 56 53 2F F9 75 4A") { | ||
rawPrefix shouldBe 0x01.toUByte() | ||
rawDeviceModel shouldBe 0x0D20.toUShort() | ||
rawStatus shouldBe 0x0.toUByte() | ||
rawPodsBattery shouldBe 0x02.toUByte() | ||
rawFlags shouldBe 0x8.toUShort() | ||
rawCaseBattery shouldBe 0x0.toUShort() | ||
rawCaseLidState shouldBe 0x01.toUByte() | ||
rawDeviceColor shouldBe 0x00.toUByte() | ||
rawSuffix shouldBe 0x05.toUByte() | ||
|
||
batteryHeadsetPercent shouldBe 0.2f | ||
|
||
model shouldBe PodDevice.Model.POWERBEATS_4 | ||
|
||
state shouldBe HasStateDetectionAirPods.ConnectionState.MUSIC | ||
} | ||
} | ||
|
||
@Test | ||
fun `extra test case`() = runTest { | ||
create<PowerBeats4>("07 19 01 0D 20 00 02 80 02 00 04 80 90 60 77 32 C2 0C 75 7A 3D 7E D7 1C 0E B8 43") { | ||
rawPrefix shouldBe 0x01.toUByte() | ||
rawDeviceModel shouldBe 0x0D20.toUShort() | ||
rawStatus shouldBe 0x0.toUByte() | ||
rawPodsBattery shouldBe 0x02.toUByte() | ||
rawFlags shouldBe 0x8.toUShort() | ||
rawCaseBattery shouldBe 0x0.toUShort() | ||
rawCaseLidState shouldBe 0x02.toUByte() | ||
rawDeviceColor shouldBe 0x00.toUByte() | ||
rawSuffix shouldBe 0x04.toUByte() | ||
|
||
batteryHeadsetPercent shouldBe 0.2f | ||
|
||
model shouldBe PodDevice.Model.POWERBEATS_4 | ||
|
||
state shouldBe HasStateDetectionAirPods.ConnectionState.IDLE | ||
} | ||
} | ||
|
||
|
||
@Test | ||
fun `disconnected state`() = runTest { | ||
create<PowerBeats4>("07 19 01 0D 20 00 02 80 01 00 00 25 DF 66 40 AF 44 7B 77 95 8F D1 92 50 26 11 74") { | ||
rawPrefix shouldBe 0x01.toUByte() | ||
rawDeviceModel shouldBe 0x0D20.toUShort() | ||
rawStatus shouldBe 0x0.toUByte() | ||
rawPodsBattery shouldBe 0x02.toUByte() | ||
rawFlags shouldBe 0x8.toUShort() | ||
rawCaseBattery shouldBe 0x0.toUShort() | ||
rawCaseLidState shouldBe 0x01.toUByte() | ||
rawDeviceColor shouldBe 0x00.toUByte() | ||
rawSuffix shouldBe 0x00.toUByte() | ||
|
||
batteryHeadsetPercent shouldBe 0.2f | ||
|
||
model shouldBe PodDevice.Model.POWERBEATS_4 | ||
|
||
state shouldBe HasStateDetectionAirPods.ConnectionState.DISCONNECTED | ||
} | ||
} | ||
} |