Orbit Companion phase 1: the phone page becomes a remote for the TV
Remote, Guide, Catch Up, Rooms and More, served by the TV in its own look. New phone routes for what's on, the remote's buttons, volume, channels, sections, the guide, Catch Up and rooms, set before any screen returns so they work in every section. Settings gets Connect a phone; the last setup step mentions it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -130,4 +130,55 @@ class PhoneLinkTest {
|
||||
val everything = call("/api/channels", cookie = cookie).body + suggest
|
||||
listOf("token", "api_key", "password", "X-Emby", "MediaBrowser", "http").forEach { assertFalse(it, everything.contains(it, ignoreCase = true)) }
|
||||
}
|
||||
|
||||
// --- Orbit Companion (phase 1) ---
|
||||
private val minute = 60_000L
|
||||
private fun media(id: String, title: String) = ScheduledMedia(SampleItem(title, "Episode", 30, "", id, 30 * minute), "s-$id", 30 * minute)
|
||||
private val now = 1_793_000_000_000L
|
||||
private val companionChannels = listOf(SampleChannel(listOf(media("a1", "Friends / S1 E1"), media("a2", "Friends / S1 E2")), "Orbit One", 101),
|
||||
SampleChannel(listOf(media("b1", "Hot Fuzz"), media("b2", "Paul")), "BritX", 308))
|
||||
private val tuned = mutableListOf<Pair<Int, Long>>()
|
||||
private var selected = 101
|
||||
private fun joinedCookie(): String { val p = PhoneLink.beginPairing(); return call("/join", "POST", "code=${p.code}", form = true).cookie!! }
|
||||
|
||||
@Test fun theCompanionIsARemoteForTheTvItCameFrom() {
|
||||
val pressed = mutableListOf<Int>(); val volume = mutableListOf<Int>()
|
||||
OrbitCompanion.inject = { synchronized(pressed) { pressed += it } }; OrbitCompanion.volume = { volume += it }
|
||||
PhoneLink.clock = { now }
|
||||
PhoneLink.screen = CompanionScreen({ companionChannels }, { selected }, { true }, { 0 }, { n, o -> tuned += n to o; selected = n })
|
||||
try {
|
||||
assertTrue(call("/api/now").body.contains("Enter the code")) // not joined: nothing
|
||||
val cookie = joinedCookie()
|
||||
assertTrue(call("/", cookie = cookie).status == 200)
|
||||
val n = JSONObject(call("/api/now", cookie = cookie).body)
|
||||
assertEquals(101, n.getJSONObject("channel").getInt("number")); assertEquals("Friends", n.getJSONObject("now").getString("title"))
|
||||
assertTrue(n.getJSONObject("look").getString("accent").startsWith("#")); assertTrue(n.getBoolean("watching"))
|
||||
val g = JSONObject(call("/api/guide", cookie = cookie).body).getJSONArray("channels")
|
||||
assertEquals(listOf(101, 308), (0 until g.length()).map { g.getJSONObject(it).getInt("number") })
|
||||
// Buttons are pressed as the TV's own remote would, and only the known ones.
|
||||
assertEquals(202, call("/api/key", "POST", """{"key":"ok"}""", cookie = cookie).status)
|
||||
assertEquals(400, call("/api/key", "POST", """{"key":"power"}""", cookie = cookie).status)
|
||||
assertEquals(403, call("/api/key", "POST", """{"key":"ok"}""", cookie = cookie, orbit = false).status)
|
||||
repeat(50) { if (synchronized(pressed) { pressed.isEmpty() }) Thread.sleep(20) }
|
||||
assertEquals(listOf(android.view.KeyEvent.KEYCODE_DPAD_CENTER), synchronized(pressed) { pressed.toList() })
|
||||
assertEquals(200, call("/api/volume", "POST", """{"change":"up"}""", cookie = cookie).status); assertEquals(1, volume.size)
|
||||
// Channels round the guide, and tuning only to a channel this TV shows.
|
||||
assertEquals(308, JSONObject(call("/api/channel", "POST", """{"step":1}""", cookie = cookie).body).getInt("number"))
|
||||
assertEquals(101, JSONObject(call("/api/channel", "POST", """{"step":1}""", cookie = cookie).body).getInt("number"))
|
||||
assertEquals(404, call("/api/tune", "POST", """{"number":999}""", cookie = cookie).status)
|
||||
assertEquals(200, call("/api/tune", "POST", """{"number":308}""", cookie = cookie).status)
|
||||
assertEquals(listOf(308 to 0L, 101 to 0L, 308 to 0L), tuned)
|
||||
assertEquals(200, call("/api/section", "POST", """{"section":"arcade"}""", cookie = cookie).status); assertEquals("Arcade", OrbitCompanion.asked?.first)
|
||||
assertEquals(400, call("/api/section", "POST", """{"section":"settings"}""", cookie = cookie).status)
|
||||
// Catch Up only from what's really in it: these channels have no committed plan, so nothing is offered.
|
||||
assertEquals(0, JSONObject(call("/api/catchup", cookie = cookie).body).getJSONArray("shelves").let { a -> (0 until a.length()).sumOf { a.getJSONObject(it).getJSONArray("entries").length() } })
|
||||
assertEquals(410, call("/api/catchup/watch", "POST", """{"number":101,"startMs":${now - 60 * minute}}""", cookie = cookie).status)
|
||||
// Titles and times only.
|
||||
val everything = call("/api/now", cookie = cookie).body + call("/api/guide", cookie = cookie).body + call("/api/rooms", cookie = cookie).body
|
||||
listOf("token", "api_key", "password", "X-Emby", "MediaBrowser", "s-a1", "a1").forEach { assertFalse(it, everything.contains("\"$it\"", ignoreCase = true)) }
|
||||
// With the screen not ready, the phone is told so rather than refused.
|
||||
PhoneLink.screen = null
|
||||
assertEquals(409, call("/api/now", cookie = cookie).status)
|
||||
} finally { PhoneLink.screen = null; OrbitCompanion.inject = { } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user