RandomMetalhead / homebridge-teufel

This is a plugin to connect Raumfeld/Teufel hardware to Apple's Homekit via the Homebridge system.
GNU General Public License v3.0
11 stars 5 forks source link

Cannot read property '0' of undefined #11

Closed SebKranz closed 5 years ago

SebKranz commented 5 years ago

Hey, I'm getting the following error:

[10/4/2019, 12:19:00 PM] TypeError: Cannot read property '0' of undefined
    at TeufelPlatform.addAccessory (/homebridge/node_modules/homebridge-teufel/index.js:57:51)
    at Raumkernel.<anonymous> (/homebridge/node_modules/homebridge-teufel/index.js:48:22)
    at Raumkernel.emit (events.js:198:13)
    at Raumkernel.onZoneConfigurationChanged (/homebridge/node_modules/homebridge-teufel/node_modules/node-raumkernel/lib/lib.raumkernel.js:235:14
    at ZoneManager.<anonymous> (/homebridge/node_modules/homebridge-teufel/node_modules/node-raumkernel/lib/lib.raumkernel.js:106:124)
    at ZoneManager.emit (events.js:198:13)
    at /homebridge/node_modules/homebridge-teufel/node_modules/node-raumkernel/lib/lib.manager.zoneManager.js:134:22
    at Parser.<anonymous> (/homebridge/node_modules/homebridge-teufel/node_modules/xml2js/lib/parser.js:306:18)
    at Parser.emit (events.js:198:13)
    at SAXParser.onclosetag (/homebridge/node_modules/homebridge-teufel/node_modules/xml2js/lib/parser.js:264:26)
    at emit (/homebridge/node_modules/homebridge-teufel/node_modules/sax/lib/sax.js:639:35)
    at emitNode (/homebridge/node_modules/homebridge-teufel/node_modules/sax/lib/sax.js:644:5)
    at closeTag (/homebridge/node_modules/homebridge-teufel/node_modules/sax/lib/sax.js:903:7)
    at SAXParser.write (/homebridge/node_modules/homebridge-teufel/node_modules/sax/lib/sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (/homebridge/node_modules/homebridge-teufel/node_modules/xml2js/lib/parser.js:325:31)
    at Parser.parseString (/homebridge/node_modules/homebridge-teufel/node_modules/xml2js/lib/parser.js:5:59)
error: uncaughtException: Cannot read property '0' of undefined date=Fri Oct 04 2019 12:19:20 GMT+0000 (Coordinated Universal Time), pid=2832, uid=1000, gid=1000, cwd=/run/s6/services/homebridge, execPath=/usr/local/bin/node, version=v10.16.3, argv=[/usr/local/bin/node, /usr/local/bin/homebridge, -U, /homebridge, -P, /homebridge/node_modules, -C], rss=50663424, heapTotal=33116160, heapUsed=15576584, external=62743, loadavg=[0.96044921875, 1.17626953125, 1.1826171875], uptime=4384

I also attempted to run the plugin inside a completely fresh docker-homebridge container, but got the same result.

I own a single Raumefeld One M.

RandomMetalhead commented 5 years ago

Hi, have you configured a room in your Teufel app? Teufel App -> Settings -> Rooms and Devices

SebKranz commented 5 years ago

Yes, I have.

As far as I'm aware, a room is automatically created when adding a new speaker. Deleting that room also deletes the speaker.

Here's my zone configuration object:

[10/6/2019, 12:31:32 PM] [Teufel] { zoneConfig: { '$': { numRooms: '0', spotifyMode: 'singleRoom' } } }

After looking at the code, I suppose the failed zone-discovery is an issue with Raumkernel itself.

However, It would be good if the plugin gracefully recovered from such an error instead of breaking homebridge.

SebKranz commented 5 years ago

The issue fixed itself after I reset my Raumfeld system for the fourth time. I guess the only way to have reliably working speakers is to not buy Raumfeld :)

As for the homebridge crash, I think something like this should fix it:

self.raumkernel.on("zoneConfigurationChanged", function (zoneConfiguration) {
    // ...
    if (!zoneConfiguration.zoneConfig.numRooms) {
        log("No raumfeld-zones found")
        return
    }
    // ...
});
RandomMetalhead commented 5 years ago

Agreed on the fix, I will incoporate it next weekend. Sad that I couldn´t help you. Have you played a little bit around with the zone config (maybe renaming zone or creating a second empty room)? My configuration is working very good for a long time now and I am quite satisfied with my Raumfeld setup.

SebKranz commented 5 years ago

Still, thanks for your time.

Yes, I gave my speaker a slightly different name. I cant really do any changes once the setup is done, because I only have one speaker and therefore the app won't allow me to make any changes to the zone configuration.

The reason I'm actually unhappy with Raumfeld, is because they killed AirPlay-support a few years ago. These older versions also don't have Bluetooth, so now, the only useful way for me to play music is via line in.

Thanks to your plugin, I can at least turn it on without having to walk up to it.

stephenglancy commented 5 years ago

I ran into this same issue.

I am not sure I fully understand what a "zone" actually is. I do not see the word "zone" mentioned anywhere in the Raumfeld app. There are only "rooms". This doesn't really make sense to me because one might have multiple Raumfeld devices in a single room. It would be much simpler if the nomenclature was "device" and "group".

When I ran a tool called pyfeld (https://github.com/scjurgen/pyfeld), I could see my two stereos (Raumfeld L and Raumfeld One M) listed under rooms. When I tried to list the zones, it was blank. After messing around for a while (not sure what I did exactly), a single zone did end up showing up called "unassigned rooms". I have also noticed that if I put Spotify on "multiroom mode" and zone is created whose name is concatenation of the two room names. Still though, homebridge was crashing on startup with this same stack trace.

I want to be able to use Homekit to turn on and off each device individually so a shared zone won't work for me. Luckily, I was able to use pyfeld to create two new separate zones using the createzone command. After doing that, this crash stop happening and I now have two switches in the HomeKit app, one for each room.

stephenglancy commented 5 years ago

Actually, the second zone isn't working, but I forgot you had mentioned in the README that you assume only 1 zone so that is to be expected.

RandomMetalhead commented 5 years ago

Zones are virtual containers for rooms. You can set Zones in the Raumfeld app

I work with only 1 static virtual zone in Homebridge. Otherwise zones would change rapidly and you could not create a automation with your zones, because everytime you create a new zone in Raumfeld App, a new device in Homekit would be created and the old one getting lost in the automation.

I have added the code from @SebKranz to fix the nullpointer. As I don´t see this problem with my setup, it´s hard to reproduce and fix the issue itself. As SebKranz metioned, it seems to be a problem in Raumserver itself.

Code you maybe try the new version and if you see an error, post the Stack?

RandomMetalhead commented 5 years ago

FYI: The plugin was based on devices instead of rooms, but that did not made sense. I assume notbody want to hear different music in the same room. So I changed the "switches" to room based, instead of device based.