Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'zoneGroupShortName') #209

Closed
jsiegenthaler opened this issue Nov 27, 2023 · 5 comments
Labels

Comments

@jsiegenthaler
Copy link

Issue

TypeError: Cannot read properties of undefined (reading 'zoneGroupShortName')

Error was thrown when the Sonos device was turned off at the mains and thus unreachable

Log Messages

[26/11/2023, 18:58:03] [Sonos] Office Sonos: Active: set to 0
[26/11/2023, 18:58:03] [Sonos] Office Sonos: Status Fault: set to 1
[26/11/2023, 18:58:03] [Sonos] Input 1: Configured Name: set to "n/a" (from "Input 1")
[26/11/2023, 18:58:03] [Sonos] n/a: Name: set to "n/a" (from "Input 1")
[26/11/2023, 18:58:03] [Sonos] error: RINCON_5CAAFDCF9FB401400: [192.168.0.162]: TypeError: Cannot read properties of undefined (reading 'zoneGroupShortName')
    at Tv.updateGroupInputSource (/var/lib/homebridge/node_modules/homebridge-zp/lib/ZpService.js:1199:43)
    at Tv.favouritesUpdated (/var/lib/homebridge/node_modules/homebridge-zp/lib/ZpService.js:1136:10)
    at new Tv (/var/lib/homebridge/node_modules/homebridge-zp/lib/ZpService.js:1097:10)
    at new Tv (/var/lib/homebridge/node_modules/homebridge-zp/lib/ZpAccessory.js:343:22)
    at ZpPlatform.logTopology (/var/lib/homebridge/node_modules/homebridge-zp/lib/ZpPlatform.js:473:41)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
[26/11/2023, 18:58:03] [Sonos] Office Sonos: Status Fault: set to 0 (from 1)

Debug Files

@ebaauw ebaauw added the bug label Nov 27, 2023
@ebaauw
Copy link
Owner

ebaauw commented Nov 27, 2023

Does the error happing after restarting Homebridge, or while Homebridge was running (for a longer time)? Was the speaker turned off during Homebridge startup, or was Homebridge restarted after the speaker was turned off?

@jsiegenthaler
Copy link
Author

The sequence of events was like this:

  1. Two of my Sonos speakers went off line.
  2. Debugging showed they were not visible in the Sonos app (app could not connect) and not visible on mDNS (using the iOS Discovery app).
  3. I power cycled the speakers which made no difference and then noted that Homebridge-zp was having issues and logging the unhandled error that I reported.
  4. At that stage Homebridge had been running for a few hours as I had restarted it earlier in the day.
  5. I left the issue untouched overnight.
  6. Today I rebooted my main router and that cleared the issue, the Sonos speakers came back online.
  7. I then (foolishly?) also truncated my Homebridge logs.

Unfortunately due to log truncation I don't have any logs from yesterday (unless they get archived automatically somewhere...)

I note the error thrown was on ZpService.js:1199:43
configuredName = 'Join ' + zpClient.zoneGroupShortName
Clearly, the object zpClient was undefined and thus the zoneGroupShortName property could not be read.
You could add some robustness in your code by something like:
const zpClient = this.platform.zpClients[platformCoordinatorId] || ''
So even though the property might not exist, at least the object is defined.
Of course, the best solution will be the one you decide on, not the one I propose :)

@ebaauw
Copy link
Owner

ebaauw commented Nov 27, 2023

not visible on mDNS (using the iOS Discovery app).

Sonos uses UPnP for discovery. mDNS is used for Airplay 2, but Sonos themselves don't use it. Older zone players that don't support AirPlay won't show on mDNS.

UPDATE: Damn, I see _sonos._tcp mDNS announcements in Discovery, that I hadn't noticed before. Need to see if Homebridge ZP can use these instead of/in addition to the UPnP announcements.

You could add some robustness in your code by something like:

I'll address the TypeError for sure, but that's more like a workaround. It looks like the platform coordinator went missing, and consequently, Homebridge ZP didn't create a ZpClient for it on restart. I think for a structural solution, I need to clear the platform coordinator, if it's no longer available. Not the kind of use cases that are easy to test, unfortunately.

@jsiegenthaler
Copy link
Author

Thanks for the feedback.
Indeed, you need to make _sonos._tcp. your friend :)

If I can ever reproduce the situation, I'll let you know. In the meantime, good luck!

ebaauw added a commit that referenced this issue Dec 11, 2023
Monitor mDNS advertisements for `_sonos._tcp.`, see #209.
ebaauw added a commit that referenced this issue Dec 11, 2023
Handle mDNS advertisements for `_sonos._tcp.`, see #209.
ebaauw added a commit that referenced this issue Dec 11, 2023
Bug fix: TypeError when platform coordinator zone player goes missing, see #209.
@ebaauw
Copy link
Owner

ebaauw commented Dec 11, 2023

In v1.4.40.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants