File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
homeassistant/components/miele Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5- import asyncio . timeouts
5+ import asyncio
66from collections .abc import Callable
77from dataclasses import dataclass
88from datetime import timedelta
99import logging
1010
11+ from aiohttp import ClientResponseError
1112from pymiele import MieleAction , MieleAPI , MieleDevice
1213
1314from homeassistant .config_entries import ConfigEntry
@@ -66,7 +67,22 @@ async def _async_update_data(self) -> MieleCoordinatorData:
6667 self .devices = devices
6768 actions = {}
6869 for device_id in devices :
69- actions_json = await self .api .get_actions (device_id )
70+ try :
71+ actions_json = await self .api .get_actions (device_id )
72+ except ClientResponseError as err :
73+ _LOGGER .debug (
74+ "Error fetching actions for device %s: Status: %s, Message: %s" ,
75+ device_id ,
76+ err .status ,
77+ err .message ,
78+ )
79+ actions_json = {}
80+ except TimeoutError :
81+ _LOGGER .debug (
82+ "Timeout fetching actions for device %s" ,
83+ device_id ,
84+ )
85+ actions_json = {}
7086 actions [device_id ] = MieleAction (actions_json )
7187 return MieleCoordinatorData (devices = devices , actions = actions )
7288
Original file line number Diff line number Diff line change 55import time
66from unittest .mock import MagicMock
77
8- from aiohttp import ClientConnectionError
8+ from aiohttp import ClientConnectionError , ClientResponseError
99from freezegun .api import FrozenDateTimeFactory
1010from pymiele import OAUTH2_TOKEN
1111import pytest
@@ -210,3 +210,29 @@ async def test_setup_all_platforms(
210210 # Check a sample sensor for each new device
211211 assert hass .states .get ("sensor.dishwasher" ).state == "in_use"
212212 assert hass .states .get ("sensor.oven_temperature_2" ).state == "175.0"
213+
214+
215+ @pytest .mark .parametrize (
216+ "side_effect" ,
217+ [
218+ ClientResponseError ("test" , "Test" ),
219+ TimeoutError ,
220+ ],
221+ ids = [
222+ "ClientResponseError" ,
223+ "TimeoutError" ,
224+ ],
225+ )
226+ async def test_load_entry_with_action_error (
227+ hass : HomeAssistant ,
228+ mock_miele_client : MagicMock ,
229+ mock_config_entry : MockConfigEntry ,
230+ side_effect : Exception ,
231+ ) -> None :
232+ """Test load with error from actions endpoint."""
233+ mock_miele_client .get_actions .side_effect = side_effect
234+ await setup_integration (hass , mock_config_entry )
235+ entry = mock_config_entry
236+
237+ assert entry .state is ConfigEntryState .LOADED
238+ assert mock_miele_client .get_actions .call_count == 5
You can’t perform that action at this time.
0 commit comments