Add AirPods Gen3 support

This commit is contained in:
darken
2022-01-09 19:03:38 +01:00
parent 604502ae76
commit a8f2fdf03a
3 changed files with 95 additions and 0 deletions
@@ -165,6 +165,12 @@ class AppleFactory @Inject constructor(
proximityMessage = pm,
cachedBatteryPercentage = cachedCaseBattery,
)
dm == 0x1320.toUShort() -> AirPodsGen3(
identifier = identifier,
scanResult = scanResult,
proximityMessage = pm,
cachedBatteryPercentage = cachedCaseBattery,
)
dm == 0x0e20.toUShort() -> AirPodsPro(
identifier = identifier,
scanResult = scanResult,
@@ -0,0 +1,26 @@
package eu.darken.capod.pods.core.apple.airpods
import android.content.Context
import eu.darken.capod.R
import eu.darken.capod.common.bluetooth.BleScanResult
import eu.darken.capod.pods.core.PodDevice
import eu.darken.capod.pods.core.apple.DualApplePods
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
import java.time.Instant
data class AirPodsGen3 constructor(
override val identifier: PodDevice.Id = PodDevice.Id(),
override val lastSeenAt: Instant = Instant.now(),
override val scanResult: BleScanResult,
override val proximityMessage: ProximityPairing.Message,
private val cachedBatteryPercentage: Float?,
) : DualApplePods {
override fun getLabel(context: Context): String = "AirPods (Gen 3)"
override val iconRes: Int
get() = R.drawable.ic_device_airpods_gen2
override val batteryCasePercent: Float?
get() = super.batteryCasePercent ?: cachedBatteryPercentage
}
@@ -0,0 +1,63 @@
package eu.darken.capod.pods.core.apple.airpods
import eu.darken.capod.pods.core.apple.BaseAirPodsTest
import eu.darken.capod.pods.core.apple.DualApplePods
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Test
class AirPodsGen3Test : BaseAirPodsTest() {
@Test
fun `AirPods Gen3`() = runBlockingTest {
create<AirPodsGen3>("07 19 01 13 20 75 AA B9 31 00 04 67 9A 57 DF BE F6 90 52 B0 04 1F 8D 89 DA F4 9E") {
rawPrefix shouldBe 0x01.toUByte()
rawDeviceModel shouldBe 0x1320.toUShort()
rawStatus shouldBe 0x75.toUByte()
rawPodsBattery shouldBe 0xAA.toUByte()
rawCaseBattery shouldBe 0xB9.toUByte()
rawCaseLidState shouldBe 0x31.toUByte()
rawDeviceColor shouldBe 0x00.toUByte()
rawSuffix shouldBe 0x04.toUByte()
batteryLeftPodPercent shouldBe 1.0f
batteryRightPodPercent shouldBe 1.0f
isCaseCharging shouldBe false
isLeftPodCharging shouldBe true
isRightPodCharging shouldBe true
isLeftPodInEar shouldBe false
isRightPodInEar shouldBe false
batteryCasePercent shouldBe 0.9f
caseLidState shouldBe DualApplePods.LidState.OPEN
connectionState shouldBe DualApplePods.ConnectionState.IDLE
deviceColor shouldBe DualApplePods.DeviceColor.WHITE
}
}
@Test
fun `random guy at bus stop`() = runBlockingTest {
create<AirPodsGen3>("07 19 01 13 20 2B 88 8F 01 00 08 E2 0E 84 37 C5 98 16 D4 B7 37 ED 23 8B 08 EA A1") {
batteryLeftPodPercent shouldBe null
batteryRightPodPercent shouldBe 0.9f
isCaseCharging shouldBe false
isLeftPodCharging shouldBe false
isRightPodCharging shouldBe false
isLeftPodInEar shouldBe false
isRightPodInEar shouldBe true
batteryCasePercent shouldBe null
caseLidState shouldBe DualApplePods.LidState.NOT_IN_CASE
connectionState shouldBe DualApplePods.ConnectionState.MUSIC
deviceColor shouldBe DualApplePods.DeviceColor.WHITE
}
}
}