Improve Linkplay device unavailability detection (#138457)

* Dampen reachability changes

Retry a few times before declaring player is unavailable

* Fix ruff-format complaint

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>

* Fix ruff-format complaint

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>

* Fix ruff-format complaint

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>

* Fix duplicated change

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>

---------

Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
This commit is contained in:
Trevor Warwick 2025-03-02 20:26:54 +00:00 committed by GitHub
parent 14e66ffef4
commit 23644a60ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -125,6 +125,8 @@ SERVICE_PLAY_PRESET_SCHEMA = cv.make_entity_service_schema(
}
)
RETRY_POLL_MAXIMUM = 3
async def async_setup_entry(
hass: HomeAssistant,
@ -156,6 +158,7 @@ class LinkPlayMediaPlayerEntity(LinkPlayBaseEntity, MediaPlayerEntity):
super().__init__(bridge)
self._attr_unique_id = bridge.device.uuid
self._retry_count = 0
self._attr_source_list = [
SOURCE_MAP[playing_mode] for playing_mode in bridge.device.playmode_support
@ -166,9 +169,12 @@ class LinkPlayMediaPlayerEntity(LinkPlayBaseEntity, MediaPlayerEntity):
"""Update the state of the media player."""
try:
await self._bridge.player.update_status()
self._retry_count = 0
self._update_properties()
except LinkPlayRequestException:
self._attr_available = False
self._retry_count += 1
if self._retry_count >= RETRY_POLL_MAXIMUM:
self._attr_available = False
@exception_wrap
async def async_select_source(self, source: str) -> None: