mirror of
https://github.com/home-assistant/core.git
synced 2025-05-30 02:37:04 +00:00

* Do not use a persistent connection to MPD In other words, don't rely on the connection management provided by "python-mpd2". Instead of keeping the connection to MPD open, we explicitly connect before and disconnect after each command. There is probably a bit of overhead to this, but as the integration uses a local-polling approach to begin with, no functionality is lost or degraded. This change greatly hardens the MPD integration against both network issues and problems with the daemon itself. All connection-related failure modes have effectively been removed. * Update state retrieval methods Only "async_get_media_image" attempts to connect, all others are either called from there, or from the main "async_update" method (see previous commit) which also attempts to connect. So, this commit mainly revolves around gracefully handling situations where no connection is available when trying to retrieve MPD state. Finally, note the removal of "self._commands". This property is only used at the start of "_async_get_file_image_response" and was thus changed into a local variable. * Update media-player control methods These all need to explicitly connect to MPD as part of their flow. * Correct ruff failure (auto-fixed) * Use "async_timeout.timeout" context manager * Minor changes * Replace "async_timeout" with "asyncio.timeout" * Initialise "self._status" to empty dictionary Used to be initialised as None, which caused "NoneType is not iterable" type of issues in case of an unexpected disconnect (at which point status gets set to None again). Instead of guarding against None everywhere, using an empty dictionary seemed more prudent... Furthermore, more cautiously access its members to prevent potential KeyError-s in similar cases. * Fix livelock in "async_mute_volume()" This method doesn't need a connection; it calls into two other methods that actually connect to MPD – attempting to connect from here resulted in a livelock.