From fdc2a83e6cf00e2af60a1045c0dc67660031bec3 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 29 Sep 2026 12:47:16 +0200 Subject: [PATCH] Handle Yoto status request errors (#183570) --- homeassistant/components/yoto/coordinator.py | 5 ++++- tests/components/yoto/test_init.py | 23 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/yoto/coordinator.py b/homeassistant/components/yoto/coordinator.py index 99ef978aed18..bf279d719c14 100644 --- a/homeassistant/components/yoto/coordinator.py +++ b/homeassistant/components/yoto/coordinator.py @@ -179,7 +179,10 @@ class YotoDataUpdateCoordinator(DataUpdateCoordinator[dict[str, YotoPlayer]]): if not self.client.is_mqtt_connected: return for device_id in list(self.client.players): - await self.client.request_player_status(device_id) + try: + await self.client.request_player_status(device_id) + except YotoError as err: + LOGGER.debug("Status request for %s failed: %s", device_id, err) def _mqtt_event(self, _player: YotoPlayer) -> None: """Handle a real-time update pushed by the Yoto MQTT broker.""" diff --git a/tests/components/yoto/test_init.py b/tests/components/yoto/test_init.py index 5f4f31eb8297..71e49e9e9fad 100644 --- a/tests/components/yoto/test_init.py +++ b/tests/components/yoto/test_init.py @@ -1,5 +1,6 @@ """Tests for the Yoto integration setup.""" +import logging from unittest.mock import MagicMock, Mock, patch import aiohttp @@ -100,6 +101,28 @@ async def test_status_push_tick( mock_yoto_client.request_player_status.assert_called_once_with("player-test") +async def test_status_push_tick_error( + hass: HomeAssistant, + mock_yoto_client: MagicMock, + mock_config_entry: MockConfigEntry, + freezer: FrozenDateTimeFactory, + caplog: pytest.LogCaptureFixture, +) -> None: + """A failed status request is logged and the timer keeps running.""" + caplog.set_level(logging.DEBUG) + mock_yoto_client.is_mqtt_connected = True + await setup_integration(hass, mock_config_entry) + mock_yoto_client.request_player_status.side_effect = YotoError("timed out") + + for _ in range(2): + freezer.tick(STATUS_PUSH_INTERVAL) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + assert mock_yoto_client.request_player_status.call_count == 2 + assert "Status request for player-test failed: timed out" in caplog.text + + async def test_status_push_skipped_when_mqtt_disconnected( hass: HomeAssistant, mock_yoto_client: MagicMock,