python-snapcast
python-snapcast copied to clipboard
fix KeyError when stream_status is called on a group
This pull request improves error handling in the stream_status property of the Snapgroup class and adds a corresponding unit test to ensure robustness when a requested stream is missing from the server.
Error handling improvements:
- Modified the
stream_statusproperty insnapcast/control/group.pyto catchKeyErrorexceptions and return"unknown"if the stream ID is not found, preventing unhandled exceptions.
"unknown" matches a valid state of the snapcast server API:
https://github.com/snapcast/snapcast/blob/801c02eaa432e6715fd69a2b5d857d276c0e8c39/server/streamreader/properties.hpp#L62
Testing enhancements:
- Added a new test case
test_bad_stream_statusintests/test_group.pyto verify thatstream_statusreturns"unknown"when the stream ID does not exist on the server, ensuring the new error handling logic works as expected.
Related to: https://github.com/home-assistant/core/issues/157636