python-snapcast icon indicating copy to clipboard operation
python-snapcast copied to clipboard

fix KeyError when stream_status is called on a group

Open Links2004 opened this issue 2 months ago • 2 comments

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_status property in snapcast/control/group.py to catch KeyError exceptions 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_status in tests/test_group.py to verify that stream_status returns "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

Links2004 avatar Dec 14 '25 09:12 Links2004