File tree Expand file tree Collapse file tree 3 files changed +44
-4
lines changed
homeassistant/components/apsystems
tests/components/apsystems Expand file tree Collapse file tree 3 files changed +44
-4
lines changed Original file line number Diff line number Diff line change 5
5
from dataclasses import dataclass
6
6
from datetime import timedelta
7
7
8
- from APsystemsEZ1 import APsystemsEZ1M , ReturnAlarmInfo , ReturnOutputData
8
+ from APsystemsEZ1 import (
9
+ APsystemsEZ1M ,
10
+ InverterReturnedError ,
11
+ ReturnAlarmInfo ,
12
+ ReturnOutputData ,
13
+ )
9
14
10
15
from homeassistant .core import HomeAssistant
11
16
from homeassistant .helpers .update_coordinator import DataUpdateCoordinator , UpdateFailed
12
17
13
- from .const import LOGGER
18
+ from .const import DOMAIN , LOGGER
14
19
15
20
16
21
@dataclass
@@ -43,6 +48,11 @@ async def _async_setup(self) -> None:
43
48
self .api .min_power = device_info .minPower
44
49
45
50
async def _async_update_data (self ) -> ApSystemsSensorData :
46
- output_data = await self .api .get_output_data ()
47
- alarm_info = await self .api .get_alarm_info ()
51
+ try :
52
+ output_data = await self .api .get_output_data ()
53
+ alarm_info = await self .api .get_alarm_info ()
54
+ except InverterReturnedError :
55
+ raise UpdateFailed (
56
+ translation_domain = DOMAIN , translation_key = "inverter_error"
57
+ ) from None
48
58
return ApSystemsSensorData (output_data = output_data , alarm_info = alarm_info )
Original file line number Diff line number Diff line change 72
72
"name" : " Inverter status"
73
73
}
74
74
}
75
+ },
76
+ "exceptions" : {
77
+ "inverter_error" : {
78
+ "message" : " Inverter returned an error"
79
+ }
75
80
}
76
81
}
Original file line number Diff line number Diff line change
1
+ """Test the APSystem setup."""
2
+
3
+ from unittest .mock import AsyncMock
4
+
5
+ from APsystemsEZ1 import InverterReturnedError
6
+
7
+ from homeassistant .components .apsystems .const import DOMAIN
8
+ from homeassistant .config_entries import ConfigEntryState
9
+ from homeassistant .core import HomeAssistant
10
+
11
+ from . import setup_integration
12
+
13
+ from tests .common import MockConfigEntry
14
+
15
+
16
+ async def test_update_failed (
17
+ hass : HomeAssistant ,
18
+ mock_apsystems : AsyncMock ,
19
+ mock_config_entry : MockConfigEntry ,
20
+ ) -> None :
21
+ """Test update failed."""
22
+ mock_apsystems .get_output_data .side_effect = InverterReturnedError
23
+ await setup_integration (hass , mock_config_entry )
24
+ entry = hass .config_entries .async_entries (DOMAIN )[0 ]
25
+ assert entry .state is ConfigEntryState .SETUP_RETRY
You can’t perform that action at this time.
0 commit comments