SongPal: do not crash if active_source is not (yet) available - fixes #20343#20344
SongPal: do not crash if active_source is not (yet) available - fixes #20343#20344rytilahti merged 3 commits intohome-assistant:devfrom Censored3:songpal-active_source-fix
Conversation
|
With this implemented, source is populated after a while... Maybe it's a timing issue |
|
I thought that this shoulnd't ever happen edit: stacktrace in the linked bug report, so ignore my questions. |
| def source(self): | ||
| """Return currently active source.""" | ||
| return self._active_source.title | ||
| return getattr(self._active_source, 'title', None) |
There was a problem hiding this comment.
Could you add a single-line comment here describing the necessity of using getattr instead of regular attribute access here, then it's okay to merge.
There was a problem hiding this comment.
Sure - here you go. Is this comment sufficient?
There was a problem hiding this comment.
That's good, thanks! I changed the title to be a bit more descriptive :-)
|
Great, happy to help. Thx btw for adding active source reading; really something I was missing! |
|
Glad to hear someone else besides me is using the platform :-) But wasn't that feature always there? Or do you mean the push-based, immediate updates? I think the problem itself may be caused partially by that codepath (if the device responds no active source during the initialization, the variable will get updated first after a source changed notification is received from the device). |
|
Ah well I vaguely remember something about it being there, but at least wasn't working for my devices... Maybe the updated python-songpal dep took care of it. I'm happy either way ;-) |
…ome-assistant#20343 (home-assistant#20344) * SongPal: error handling if active_source can't be detected * sonpal: Add comment to the use of getattr() for property source * songpal: make comment single-line
…ome-assistant#20343 (home-assistant#20344) * SongPal: error handling if active_source can't be detected * sonpal: Add comment to the use of getattr() for property source * songpal: make comment single-line
Description:
Related issue (if applicable): fixes #20343
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: