-
Notifications
You must be signed in to change notification settings - Fork 34
fix KeyError when stream_status is called on a group #83
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
Open
Links2004
wants to merge
6
commits into
happyleavesaoc:master
Choose a base branch
from
Links2004:fix_keyError_on_group_stream_status
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+127
−11
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49272fa
fix KeyError when stream_status is called on a group
Links2004 315c44a
force synchronize if stream is missing
Links2004 759e5d6
Update snapcast/control/server.py
Links2004 223f732
better callback handling
Links2004 99558b9
add found check
Links2004 11a4087
do not force update in stream func
Links2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,6 +272,8 @@ def group(self, group_identifier): | |
|
|
||
| def stream(self, stream_identifier): | ||
| """Get a stream.""" | ||
| if stream_identifier not in self._streams: | ||
| raise KeyError(f'Stream "{stream_identifier}" not found') | ||
| return self._streams[stream_identifier] | ||
|
|
||
| def client(self, client_identifier): | ||
|
|
@@ -373,6 +375,20 @@ def _on_group_name_changed(self, data): | |
| def _on_group_stream_changed(self, data): | ||
| """Handle group stream change.""" | ||
| group = self._groups.get(data.get('id')) | ||
| stream_id = data.get('stream_id', None) | ||
|
|
||
| if stream_id not in self._streams: | ||
| def update_callback(found): | ||
| self._on_update_callback_func() | ||
| if not found: | ||
| return | ||
| group.update_stream(data) | ||
| for client_id in group.clients: | ||
| self._clients.get(client_id).callback() | ||
|
|
||
| self._synchronize_if_stream_missing(stream_id, update_callback) | ||
| return | ||
|
|
||
| group.update_stream(data) | ||
| for client_id in group.clients: | ||
| self._clients.get(client_id).callback() | ||
|
|
@@ -442,11 +458,24 @@ def _on_stream_update(self, data): | |
| if data.get('stream', {}).get('uri', {}).get('query', {}).get('codec') == 'null': | ||
| _LOGGER.debug('stream %s is input-only, ignore', data.get('id')) | ||
| else: | ||
| _LOGGER.info('stream %s not found, synchronize', data.get('id')) | ||
|
|
||
| async def async_sync(): | ||
| self.synchronize((await self.status())[0]) | ||
| asyncio.ensure_future(async_sync()) | ||
| self._synchronize_if_stream_missing(data.get('id'), self._on_update_callback_func) | ||
|
|
||
| def _synchronize_if_stream_missing(self, stream_id, callback=None): | ||
| """Ensure stream exists, otherwise synchronize.""" | ||
| if stream_id is None: | ||
| return | ||
| if stream_id not in self._streams: | ||
| _LOGGER.info('stream "%s" not found, synchronize', stream_id) | ||
|
|
||
| async def async_sync(): | ||
| self.synchronize((await self.status())[0]) | ||
Links2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| found = stream_id in self._streams | ||
| if not found: | ||
| _LOGGER.warning('stream "%s" still not found after synchronization', stream_id) | ||
| if callback and callable(callback): | ||
| callback(found, stream_id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test this? Maybe with homeassistant? It will call |
||
|
|
||
| asyncio.ensure_future(async_sync()) | ||
|
|
||
| def set_on_update_callback(self, func): | ||
| """Set on update callback function.""" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proceed only if stream exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did updated the code and added a callback handler to
_synchronize_if_stream_missing.