@mdjhnson/homebridge-yoto 1.0.0 → 1.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,76 @@ Homebridge plugin that exposes Yoto players to HomeKit: playback and volume, car
26
26
 
27
27
  This is a maintained fork of [bcomnes/homebridge-yoto](https://github.com/bcomnes/homebridge-yoto).
28
28
 
29
+ ## Native iPhone Now Playing (experimental)
30
+
31
+ Enable **Native iPhone Now Playing** in the plugin's **Accessory Services** settings
32
+ and restart Homebridge. Stop the standalone prototype/container first so its port
33
+ and name do not conflict. Each Yoto appears under **Control Other Speakers & TVs**,
34
+ with live card/track metadata, available cover artwork, volume, and play/pause/stop controls. Previous/next
35
+ select adjacent tracks when ordered card details from `/card/{cardId}` and the current track keys are
36
+ available; navigation stops at the card boundaries. Volume follows the player
37
+ and respects its active maximum volume limit.
38
+ Homebridge starts and stops the receivers automatically and reuses its existing
39
+ Yoto account. No separate receiver container, bridge token, or device-ID lookup is
40
+ needed. This research branch must be installed in Homebridge; it is not an npm
41
+ release yet.
42
+
43
+ The Homebridge environment needs Python with `venv`/`pip`. The plugin
44
+ installs the pinned receiver dependencies into its persistent storage on the first
45
+ startup; allow a few minutes. Python must be installed **inside** the Homebridge
46
+ container when using Docker. For Debian/Ubuntu containers the packages are
47
+ `python3`, `python3-venv`, and `python3-pip`; keep these in your container
48
+ image or persistent startup setup so recreating it does not remove them. The
49
+ plugin does not install system packages or require Homebridge to run as root.
50
+ Linux and macOS are supported; Windows is not supported for this feature.
51
+
52
+ **Pairing PIN.** The first start generates a random 8-digit **Pairing PIN** and saves
53
+ it under **Advanced → Native iPhone Controls** (the log says when it does, but never
54
+ prints the PIN). Your iPhone asks for it the first time it controls a Yoto; change it
55
+ there at any time (4–32 characters, no spaces) and restart. Repeated wrong guesses
56
+ are slowed down. If you want any phone on your network, guests included, to control
57
+ the Yotos without a PIN, turn on **Allow anyone on my network (no PIN)**.
58
+
59
+ Restricting control to people in your Apple Home isn't possible: that needs the
60
+ receiver to be a HomeKit-certified AirPlay speaker, which this is not.
61
+
62
+ Under **Advanced → Native iPhone Controls**, optionally select player names (empty
63
+ means all), override the Python executable, or choose the first receiver port
64
+ (default 7100, followed by the next free port per player; avoid 7000, which macOS
65
+ AirPlay Receiver uses). Players with the same name get a short device ID suffix. The LAN address is detected when
66
+ there is one external IPv4 interface. On Unraid, enter the Homebridge host's LAN IP
67
+ if there are multiple interfaces. Homebridge Docker must use **host networking**
68
+ for multicast discovery and the dynamically allocated event/data ports.
69
+
70
+ For JSON configuration, add these fields to the existing Yoto platform entry:
71
+
72
+ ```json
73
+ "services": {
74
+ "nativeControls": true
75
+ },
76
+ "nativeControls": {
77
+ "pin": "24681357",
78
+ "address": "192.0.2.10",
79
+ "port": 7100
80
+ }
81
+ ```
82
+
83
+ Merge `nativeControls` into your existing `services` object; keep the other service
84
+ settings. The separate `nativeControls` object is optional: leave out `pin` to have one
85
+ generated, and add `"allowAnyoneOnNetwork": true` only if you want no PIN at all. Turn the switch off and restart to remove the receivers.
86
+
87
+ This remains experimental. Play/pause, volume, artwork, and previous/next have
88
+ been tested with physical Yoto players and an iPhone. Integration tests cover
89
+ pairing, encrypted transport, command forwarding, offline handling, and receiver
90
+ lifecycle with fake devices. Progress uses timestamped positions and smooths minor
91
+ reporting jitter; long-session and card removal/reinsertion behaviour still need
92
+ broader testing. Seeking, audio reception, and persistent pairing are not implemented.
93
+ Previous/next are disabled when card navigation metadata is unavailable or no
94
+ adjacent track exists. Interactive cards do not expose linear navigation.
95
+ Anyone who knows the pairing PIN (or anyone on your network, if **Allow anyone on my
96
+ network** is on) can play, pause, skip and change the volume of the selected Yotos, up
97
+ to their maximum volume limit. Do not expose these ports to the internet.
98
+
29
99
  ## Install
30
100
 
31
101
  Search for `@mdjhnson/homebridge-yoto` in the Homebridge UI **Plugins** tab, or run:
@@ -125,7 +195,12 @@ The TV accessory, and the legacy Smart Speaker below, are external accessories.
125
195
 
126
196
  ## Privacy
127
197
 
128
- The plugin only connects to Yoto's API and MQTT service, using your own sign-in. It has no analytics or tracking. The only file it changes is Homebridge's `config.json`, to save refreshed sign-in tokens. It writes a temporary copy next to `config.json` first and renames it into place, so an interrupted save can't corrupt the file.
198
+ The plugin connects to Yoto's API and MQTT service using your own sign-in. It has
199
+ no analytics or tracking. Optional native controls also download cover artwork
200
+ from metadata URLs and advertise receiver services on your LAN. First-run receiver
201
+ setup downloads pinned Python dependencies and keeps its runtime in Homebridge's
202
+ persistent storage. The plugin updates Homebridge's `config.json` to save refreshed
203
+ sign-in tokens. It writes a temporary copy next to `config.json` first and renames it into place, so an interrupted save can't corrupt the file.
129
204
 
130
205
  ## Development
131
206
 
@@ -174,6 +174,62 @@
174
174
  "type": "boolean",
175
175
  "default": true,
176
176
  "description": "Expose day/night max volume controls."
177
+ },
178
+ "nativeControls": {
179
+ "title": "Native iPhone Now Playing (Experimental)",
180
+ "type": "boolean",
181
+ "default": false,
182
+ "description": "Show each Yoto in Control Other Speakers & TVs with card artwork, playback navigation and volume controls. Homebridge manages the receiver. Requires Python 3 with venv and pip; dependencies install automatically on first startup. iPhones must enter the pairing PIN from the Native iPhone Controls settings under Advanced."
183
+ }
184
+ }
185
+ },
186
+ "nativeControls": {
187
+ "title": "Native iPhone Controls",
188
+ "type": "object",
189
+ "properties": {
190
+ "pin": {
191
+ "title": "Pairing PIN",
192
+ "type": "string",
193
+ "minLength": 4,
194
+ "maxLength": 32,
195
+ "pattern": "^[\\x21-\\x7E]+$",
196
+ "description": "Entered on an iPhone the first time it controls a Yoto. Leave blank to have a random 8-digit PIN generated and saved here on the next start. 4 to 32 characters, no spaces."
197
+ },
198
+ "allowAnyoneOnNetwork": {
199
+ "title": "Allow anyone on my network (no PIN)",
200
+ "type": "boolean",
201
+ "default": false,
202
+ "description": "Turn off the PIN. Any phone or device on your network, including guests, can then play, pause, skip and change the volume of the selected Yotos."
203
+ },
204
+ "address": {
205
+ "title": "LAN address",
206
+ "type": "string",
207
+ "description": "Leave blank to detect a single LAN IPv4 address. On Unraid with multiple interfaces, enter the Homebridge host LAN address. Homebridge must use host networking."
208
+ },
209
+ "port": {
210
+ "title": "First port",
211
+ "type": "integer",
212
+ "minimum": 1024,
213
+ "maximum": 65535,
214
+ "default": 7100,
215
+ "description": "First receiver TCP port. Each Yoto uses the next free port; event/data ports are assigned automatically. Avoid 7000, which macOS AirPlay Receiver uses.",
216
+ "x-schema-form": {
217
+ "type": "number"
218
+ }
219
+ },
220
+ "pythonPath": {
221
+ "title": "Python executable",
222
+ "type": "string",
223
+ "default": "python3",
224
+ "description": "Python executable or absolute path. A dedicated runtime is created automatically in Homebridge storage."
225
+ },
226
+ "devices": {
227
+ "title": "Players",
228
+ "type": "array",
229
+ "items": {
230
+ "type": "string"
231
+ },
232
+ "description": "Optional player names or device IDs. Leave empty to expose all Yotos."
177
233
  }
178
234
  }
179
235
  }
@@ -208,6 +264,7 @@
208
264
  "helpvalue": "<p>The older <strong>External Smart Speaker</strong> option has moved to the <em>Advanced</em> section below.</p>"
209
265
  },
210
266
  "services.playbackControls",
267
+ "services.nativeControls",
211
268
  "services.television",
212
269
  {
213
270
  "key": "services.televisionLibrary",
@@ -255,6 +312,42 @@
255
312
  "items": [
256
313
  "name",
257
314
  "httpPollIntervalMs",
315
+ {
316
+ "type": "section",
317
+ "title": "Native iPhone Controls",
318
+ "condition": {
319
+ "functionBody": "return model.services && model.services.nativeControls === true"
320
+ },
321
+ "items": [
322
+ "nativeControls.pin",
323
+ "nativeControls.allowAnyoneOnNetwork",
324
+ "nativeControls.address",
325
+ {
326
+ "key": "nativeControls.port",
327
+ "type": "number"
328
+ },
329
+ "nativeControls.pythonPath",
330
+ {
331
+ "type": "help",
332
+ "helpvalue": "<p class=\"mb-1\">Players</p><p class=\"text-muted small\">Optional player names or device IDs. Leave empty to expose all Yotos.</p>"
333
+ },
334
+ {
335
+ "key": "nativeControls.devices",
336
+ "type": "array",
337
+ "notitle": true,
338
+ "description": "",
339
+ "startEmpty": true,
340
+ "buttonText": "Add player",
341
+ "items": [
342
+ {
343
+ "key": "nativeControls.devices[]",
344
+ "notitle": true,
345
+ "placeholder": "Player name or device ID"
346
+ }
347
+ ]
348
+ }
349
+ ]
350
+ },
258
351
  {
259
352
  "type": "help",
260
353
  "helpvalue": "<p><strong>Legacy: External Smart Speaker.</strong> Older playback option kept for existing setups. It only works in scenes and automations. The Home app shows \"Controls not available\" for it and can't show what's playing, because iOS only offers those for AirPlay speakers. For more features, turn on the <strong>TV Playback Accessory</strong> under <em>Accessory Services</em> instead. It supports the iPhone remote, volume buttons, and inputs for card controls and shortcuts. If you switch, remove the old Smart Speaker from the Home app by hand.</p>"
@@ -0,0 +1,206 @@
1
+ # MediaRemote receiver experiment
2
+
3
+ This is an experimental remote-only AirPlay/MediaRemote receiver. Native iPhone
4
+ Now Playing and transport controls have been verified with fictional playback
5
+ using `AudioAccessory5,1` and authentication feature bit 14. It receives no audio.
6
+
7
+ By default it uses fictional playback. The opt-in Homebridge adapter below reads
8
+ real Yoto metadata and forwards transport commands through the plugin's existing
9
+ account. This integration is covered by simulated-device tests; physical Yoto
10
+ operation has not yet been verified.
11
+
12
+ ## Run on a Mac or Linux machine
13
+
14
+ Use Python 3.12 with `venv` and `pip`. Connect the machine and iPhone to the same LAN. Replace
15
+ `192.168.1.100` below with the machine's LAN IPv4 address (on a Wi-Fi Mac,
16
+ `ipconfig getifaddr en0` usually shows it).
17
+
18
+ ```sh
19
+ git clone https://github.com/mdjhnson/homebridge-yoto.git
20
+ cd homebridge-yoto/experiments/mediaremote
21
+ python3 -m venv .venv
22
+ .venv/bin/pip install -r requirements.txt
23
+ YOTO_NATIVE_CONTROLS_PIN=24681357 .venv/bin/python receiver.py --address 192.168.1.100
24
+ ```
25
+
26
+ The iPhone asks for the PIN when it first connects. To let any client on the LAN
27
+ pair without one (AirPlay's public transient PIN), pass `--open-access` instead of
28
+ setting `YOTO_NATIVE_CONTROLS_PIN`. The receiver refuses to start with neither.
29
+
30
+ Allow Python incoming LAN connections if macOS asks. Stop with Ctrl-C. The service
31
+ uses TCP 7100, ephemeral TCP ports for event/data channels, and multicast DNS on
32
+ UDP 5353. Port 7100 can be changed with `--port` (avoid 7000, which macOS AirPlay
33
+ Receiver uses). Identity is regenerated on each
34
+ restart to avoid retaining experimental pairing state.
35
+
36
+ ## Run on Unraid with Docker
37
+
38
+ From the repository root:
39
+
40
+ ```sh
41
+ docker build -t yoto-mediaremote-prototype experiments/mediaremote
42
+ docker run --rm --name yoto-mediaremote-prototype --network host \
43
+ -e YOTO_NATIVE_CONTROLS_PIN=24681357 \
44
+ yoto-mediaremote-prototype --address 192.168.1.100
45
+ ```
46
+
47
+ Use the Unraid LAN IP. Host networking is required for multicast discovery and
48
+ session ports. There are no Yoto settings or volumes to configure. The Dockerfile
49
+ runs as an unprivileged user. The image build has not been tested in this workspace.
50
+ For desktop macOS use native Python rather than Docker's virtual network.
51
+
52
+ ## Managed plugin mode
53
+
54
+ The plugin now manages receivers directly. Enable **Native iPhone Now Playing**
55
+ in its settings and restart Homebridge. See the [main README](../../README.md#native-iphone-now-playing-experimental)
56
+ for prerequisites and optional LAN/player settings. The manual bridge below is
57
+ retained for development; it is no longer the normal setup path.
58
+
59
+ ## Connect a real Yoto through Homebridge
60
+
61
+ Install this research branch of the Homebridge plugin as well as rebuilding the
62
+ receiver image. Pulling/rebuilding only the receiver does not install the adapter.
63
+ For a local Homebridge plugin install, use the repository root:
64
+
65
+ ```sh
66
+ npm install
67
+ npm link
68
+ ```
69
+
70
+ Run `npm link` in the Homebridge environment, where its global plugins are installed.
71
+ Keep that checkout on a persistent Unraid volume if Homebridge runs in Docker.
72
+
73
+ Generate a bridge token locally with `openssl rand -hex 32`. Add this object to
74
+ **the Yoto platform entry** in Homebridge's JSON configuration (alongside its
75
+ existing `platform`, login and accessory settings):
76
+
77
+ ```json
78
+ "mediaRemoteBridge": {
79
+ "host": "0.0.0.0",
80
+ "port": 9220,
81
+ "token": "PASTE_YOUR_GENERATED_TOKEN_HERE"
82
+ }
83
+ ```
84
+
85
+ This experimental setting is edited in JSON; there is no settings-form toggle.
86
+ Restart Homebridge. Its log should report `Experimental MediaRemote bridge
87
+ listening`. The adapter is disabled when this object is absent. The default bind
88
+ address is loopback; the explicit address above allows a separate container to
89
+ connect. With Docker bridge networking, publish TCP 9220 on the Homebridge
90
+ container; with host networking no port mapping is needed. Keep it on your trusted
91
+ LAN. The bearer token grants metadata access and playback control of your Yotos.
92
+ The plain HTTP example does not encrypt traffic; use only your trusted network.
93
+
94
+ Set the same token in your terminal and list device IDs (this is read-only):
95
+
96
+ ```sh
97
+ read -r -s -p "Bridge token: " YOTO_MEDIAREMOTE_TOKEN
98
+ echo
99
+ export YOTO_MEDIAREMOTE_TOKEN
100
+ curl --fail --silent --show-error \
101
+ -H "Authorization: Bearer $YOTO_MEDIAREMOTE_TOKEN" \
102
+ http://192.0.2.10:9220/devices
103
+ ```
104
+
105
+ Replace the IP with the Homebridge host. Copy the selected Yoto's `id` from that
106
+ response. Stop the fictional receiver, then start bridge mode:
107
+
108
+ ```sh
109
+ docker run --rm --name yoto-mediaremote-prototype --network host \
110
+ -e YOTO_MEDIAREMOTE_TOKEN -e YOTO_NATIVE_CONTROLS_PIN \
111
+ yoto-mediaremote-prototype --address 192.0.2.10 \
112
+ --model AudioAccessory5,1 --bridge-url http://192.0.2.10:9220 \
113
+ --device-id YOUR_YOTO_DEVICE_ID
114
+ ```
115
+
116
+ For native Python, pass those same flags to `receiver.py`. The receiver uses the
117
+ selected Yoto's name unless overridden with `--name`. One receiver process serves
118
+ one selected Yoto; additional processes need distinct `--port` values.
119
+
120
+ Open **Control Other Speakers & TVs**. It should show card/track title, author or
121
+ narrator, available cover artwork, duration and reported position. State is polled
122
+ from Homebridge every second and published to every connected control session.
123
+ Play, pause, toggle and stop forward to Yoto. Commands are acknowledged as sent;
124
+ actual playback status follows MQTT updates rather than an optimistic local edit.
125
+ Offline devices and disconnected accounts reject commands and show offline state.
126
+ Previous/next use ordered chapter and track keys fetched from `/card/{cardId}` or
127
+ the family library. Buttons are enabled only when an adjacent track exists.
128
+ Volume uses the Yoto 0–16 scale and respects its active maximum volume limit.
129
+ Seeking is not implemented.
130
+
131
+ Turning off bridge mode requires stopping the receiver and removing the
132
+ `mediaRemoteBridge` setting, then restarting Homebridge. The existing HomeKit
133
+ accessories continue using the same account.
134
+
135
+ ## iPhone experiment
136
+
137
+ 1. Start with the default identity, `YotoPrototype`. Look for **Yoto Prototype**
138
+ in expanded Control Centre media controls / the AirPlay menu, including
139
+ **Control Other Speakers & TVs** if your iOS version offers it.
140
+ 2. If absent, stop the process and repeat with an experimental identity:
141
+
142
+ ```sh
143
+ .venv/bin/python receiver.py --address 192.168.1.100 --model AudioAccessory5,1
144
+ ```
145
+
146
+ Then try `--model AppleTV6,2` separately. In Docker append `--model ...` to
147
+ the run command. These are discovery/classification experiments, not genuine
148
+ HomePods or Apple TVs. They may be hidden or request pairing we do not support.
149
+ 3. Do not send iPhone audio to the prototype. Selecting an audio output alone
150
+ is not success. We need an independently controllable session showing
151
+ **Prototype story — Chapter 1**, fictional card artwork, and transport controls.
152
+ 4. Try pause, play, and next. Watch the terminal: `COMMAND ... (simulated only)`
153
+ must appear, and the state should update. Next changes the title to Chapter 2.
154
+ 5. Record the iOS version, identity tested, what appears on screen, and terminal
155
+ logs from `READY` onwards. Stop the prototype after testing.
156
+
157
+ ## What is implemented
158
+
159
+ - `_airplay._tcp` and `_raop._tcp` discovery and `/info` with matching TXT data
160
+ and experimental receiver-format/capability hints. Audio remains rejected.
161
+ - Transient SRP pairing with a pairing PIN (advertised as password-required), or
162
+ AirPlay's public transient PIN with `--open-access`; repeated wrong PINs back off
163
+ up to 5 minutes. Encrypted control/event/data channels.
164
+ - Remote-only RTSP SETUP, RECORD, feedback, and teardown.
165
+ - Stream type 130 carrying length-prefixed MediaRemote protobuf messages.
166
+ - Device information, subscription response, playback queue, generated fictional
167
+ PNG artwork, play/pause/stop/toggle, and chapter next/previous.
168
+ - State publication to channels in the commanding session after a command.
169
+
170
+ ## Limits
171
+
172
+ No persistent HomeKit/AirPlay pairing, companion-link service, audio output,
173
+ or seeking. Volume control is available in live mode. Timeline values follow Yoto updates; they are not
174
+ interpolated locally. Do not add it as a replacement Homebridge accessory. It rejects audio stream setup and
175
+ persistent pairing. The advertised audio-related feature bits are experimental
176
+ discovery hints; they do not signify working audio reception. An iPhone insisting
177
+ on persistent pairing is a useful negative result, not something this implements.
178
+
179
+ Any client that knows the pairing PIN can control the selected player (fictional by
180
+ default, real in bridge mode); with `--open-access`, any client on the LAN can. There
181
+ is no per-user access-control list. Do not expose it beyond your LAN. The PIN and
182
+ other pairing secrets are never logged.
183
+
184
+ ## Validate locally
185
+
186
+ ```sh
187
+ .venv/bin/python -m unittest -v test_receiver.py
188
+ ```
189
+
190
+ The bridge tests also check authentication, live metadata, command forwarding,
191
+ and offline rejection with fake Yoto devices. No physical-player commands run.
192
+
193
+ The tests use loopback and real pyatv transient pairing to establish encrypted
194
+ remote-only channels, inspect metadata/artwork, pause/toggle/advance chapters,
195
+ reject unsupported commands/audio, reject an invalid pairing proof, require the
196
+ configured PIN, and back off after repeated wrong PINs.
197
+
198
+ ## References and dependency
199
+
200
+ - [pyatv remote-only protocol notes](https://pyatv.dev/documentation/protocols/#airplay-2)
201
+ - [pyatv data/event channels](https://github.com/postlund/pyatv/blob/b277a4c8222ecdcbaab8a24e3e713ca44765adb4/pyatv/protocols/airplay/channels.py)
202
+ - [pyatv simulated MRP receiver](https://github.com/postlund/pyatv/blob/b277a4c8222ecdcbaab8a24e3e713ca44765adb4/tests/fake_device/mrp.py)
203
+
204
+ The pyatv dependency is installed from an archive pinned to the inspected revision because this uses
205
+ internal protocol APIs. Its dependencies are pinned to the versions pyatv tests at that revision;
206
+ unpinned installs break (srptools 2.x changed its API). Its MIT license is supplied by the installed dependency.
@@ -0,0 +1,9 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Pierre Ståhl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.