evandcoleman / homebridge-theater-mode

A homebridge plugin to make your HomeKit devices react to the play/pause state of your Apple TV. Configured via the Home app.
MIT License
95 stars 15 forks source link

Homebridge crashes when turning on theater mode #4

Open pccaredk opened 6 years ago

pccaredk commented 6 years ago

/usr/local/lib/node_modules/homebridge-theater-mode/dist/index.js:41 this.device.on('supportedCommands', function (commands) { ^ TypeError: Cannot read property 'on' of undefined at AppleTVProgrammableSwitch.setEnabled (/usr/local/lib/node_modules/homebridge-theater-mode/dist/index.js:41:25) at Characteristic.On. (/usr/local/lib/node_modules/homebridge-theater-mode/dist/index.js:86:18) at emitMany (events.js:147:13) at Characteristic.On.emit (events.js:224:7) at Characteristic.On.Characteristic.setValue (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Characteristic.js:319:10) at Bridge. (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:867:22) at Array.forEach () at Bridge.Accessory._handleSetCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:807:8) at emitMany (events.js:147:13) at HAPServer.emit (events.js:224:7) at HAPServer._handleCharacteristics (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:972:10) at HAPServer. (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:209:39) at emitNone (events.js:106:13) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1055:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)

vdesabou commented 6 years ago

I got the same problem. Posting here how I worked around it:

My network is pretty slow so I got this:

Sep 14 14:56:51 raspberrypi homebridge[1239]: [2018-9-14 14:56:51] [Apple TV Salon] Error: Failed to locate specified AppleTV on the network
Sep 14 14:56:51 raspberrypi homebridge[1239]:     at Timeout.setTimeout (/opt/node/lib/node_modules/homebridge-theater-mode/node_modules/node-appletv/dist/lib/browser.js:48:28)
Sep 14 14:56:51 raspberrypi homebridge[1239]:     at ontimeout (timers.js:466:11)
Sep 14 14:56:51 raspberrypi homebridge[1239]:     at tryOnTimeout (timers.js:304:5)
Sep 14 14:56:51 raspberrypi homebridge[1239]:     at Timer.listOnTimeout (timers.js:267:5)

So I edited the file /opt/node/lib/node_modules/homebridge-theater-mode/node_modules/node-appletv/dist/lib/browser.js to increase timeout from 5 seconds to 30 seconds