diff --git a/homeassistant/components/indevolt/coordinator.py b/homeassistant/components/indevolt/coordinator.py index 12381aa519afbf..f6f2a18cb4a7a1 100644 --- a/homeassistant/components/indevolt/coordinator.py +++ b/homeassistant/components/indevolt/coordinator.py @@ -33,14 +33,6 @@ type IndevoltConfigEntry = ConfigEntry[IndevoltCoordinator] -class DeviceTimeoutError(HomeAssistantError): - """Raised when device push times out.""" - - -class DeviceConnectionError(HomeAssistantError): - """Raised when device push fails due to connection issues.""" - - class IndevoltCoordinator(DataUpdateCoordinator[dict[str, Any]]): """Coordinator for fetching and pushing data to indevolt devices.""" @@ -96,12 +88,7 @@ async def _async_update_data(self) -> dict[str, Any]: async def async_push_data(self, sensor_key: str, value: Any) -> bool: """Push/write data values to given key on the device.""" - try: - return await self.api.set_data(sensor_key, value) - except TimeoutError as err: - raise DeviceTimeoutError(f"Device push timed out: {err}") from err - except (ClientError, OSError) as err: - raise DeviceConnectionError(f"Device push failed: {err}") from err + return await self.api.set_data(sensor_key, value) async def async_switch_energy_mode( self, target_mode: IndevoltEnergyMode, refresh: bool = True @@ -125,15 +112,9 @@ async def async_switch_energy_mode( # Switch energy mode if required if current_mode != target_mode: - try: - success = await self.async_push_data( - IndevoltConfig.WRITE_ENERGY_MODE, target_mode - ) - except (DeviceTimeoutError, DeviceConnectionError) as err: - raise HomeAssistantError( - translation_domain=DOMAIN, - translation_key="failed_to_switch_energy_mode", - ) from err + success = await self.async_push_data( + IndevoltConfig.WRITE_ENERGY_MODE, target_mode + ) if not success: raise HomeAssistantError( diff --git a/homeassistant/components/indevolt/number.py b/homeassistant/components/indevolt/number.py index 5458245f6d9b7b..bd4ef3ba12f874 100644 --- a/homeassistant/components/indevolt/number.py +++ b/homeassistant/components/indevolt/number.py @@ -17,6 +17,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import IndevoltConfigEntry +from .const import DOMAIN from .coordinator import IndevoltCoordinator from .entity import IndevoltEntity @@ -138,4 +139,8 @@ async def async_set_native_value(self, value: float) -> None: await self.coordinator.async_request_refresh() else: - raise HomeAssistantError(f"Failed to set value {int_value} for {self.name}") + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="write_error", + translation_placeholders={"name": str(self.name)}, + ) diff --git a/homeassistant/components/indevolt/quality_scale.yaml b/homeassistant/components/indevolt/quality_scale.yaml index 9d45f8097b02a7..f93e6679f3cd14 100644 --- a/homeassistant/components/indevolt/quality_scale.yaml +++ b/homeassistant/components/indevolt/quality_scale.yaml @@ -60,7 +60,7 @@ rules: entity-device-class: done entity-disabled-by-default: done entity-translations: done - exception-translations: todo + exception-translations: done icon-translations: done reconfiguration-flow: done repair-issues: @@ -69,6 +69,7 @@ rules: stale-devices: status: exempt comment: Integration represents a single device, not a hub with multiple devices + # Platinum async-dependency: done inject-websession: done diff --git a/homeassistant/components/indevolt/select.py b/homeassistant/components/indevolt/select.py index 31b6f09b9d3771..2d4b0fab634b4e 100644 --- a/homeassistant/components/indevolt/select.py +++ b/homeassistant/components/indevolt/select.py @@ -11,6 +11,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import IndevoltConfigEntry +from .const import DOMAIN from .coordinator import IndevoltCoordinator from .entity import IndevoltEntity @@ -108,4 +109,8 @@ async def async_select_option(self, option: str) -> None: await self.coordinator.async_request_refresh() else: - raise HomeAssistantError(f"Failed to set option {option} for {self.name}") + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="write_error", + translation_placeholders={"name": str(self.name)}, + ) diff --git a/homeassistant/components/indevolt/strings.json b/homeassistant/components/indevolt/strings.json index 83bba1627af132..8788333d938d05 100644 --- a/homeassistant/components/indevolt/strings.json +++ b/homeassistant/components/indevolt/strings.json @@ -354,6 +354,9 @@ }, "soc_below_minimum": { "message": "Target SOC ({target}%) is below the device minimum ({minimum_soc}%)" + }, + "write_error": { + "message": "Cannot update value for {name}" } }, "services": { diff --git a/homeassistant/components/indevolt/switch.py b/homeassistant/components/indevolt/switch.py index 203f8ba419552d..e08f22f3609b38 100644 --- a/homeassistant/components/indevolt/switch.py +++ b/homeassistant/components/indevolt/switch.py @@ -15,6 +15,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import IndevoltConfigEntry +from .const import DOMAIN from .coordinator import IndevoltCoordinator from .entity import IndevoltEntity @@ -128,4 +129,8 @@ async def _async_toggle(self, value: int) -> None: await self.coordinator.async_request_refresh() else: - raise HomeAssistantError(f"Failed to set value {value} for {self.name}") + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="write_error", + translation_placeholders={"name": str(self.name)}, + ) diff --git a/tests/components/indevolt/test_number.py b/tests/components/indevolt/test_number.py index abfa5c8f7f22c1..15d3971b2770f2 100644 --- a/tests/components/indevolt/test_number.py +++ b/tests/components/indevolt/test_number.py @@ -111,10 +111,7 @@ async def test_number_set_value_error( with patch("homeassistant.components.indevolt.PLATFORMS", [Platform.NUMBER]): await setup_integration(hass, mock_config_entry) - # Mock set_data to raise an error - mock_indevolt.set_data.side_effect = HomeAssistantError( - "Device communication failed" - ) + mock_indevolt.set_data.return_value = False # Attempt to set value with pytest.raises(HomeAssistantError): diff --git a/tests/components/indevolt/test_select.py b/tests/components/indevolt/test_select.py index cf875bd73ddffe..2360990ed8dcf2 100644 --- a/tests/components/indevolt/test_select.py +++ b/tests/components/indevolt/test_select.py @@ -92,10 +92,7 @@ async def test_select_set_option_error( with patch("homeassistant.components.indevolt.PLATFORMS", [Platform.SELECT]): await setup_integration(hass, mock_config_entry) - # Mock set_data to raise an error - mock_indevolt.set_data.side_effect = HomeAssistantError( - "Device communication failed" - ) + mock_indevolt.set_data.return_value = False # Attempt to change option with pytest.raises(HomeAssistantError): diff --git a/tests/components/indevolt/test_services.py b/tests/components/indevolt/test_services.py index d943fabc838041..6a6f2409ee2544 100644 --- a/tests/components/indevolt/test_services.py +++ b/tests/components/indevolt/test_services.py @@ -375,7 +375,7 @@ async def test_single_device_execution_failure( await setup_integration(hass, mock_config_entry) # Simulate an API push failure - mock_indevolt.set_data.side_effect = OSError("Device push failed") + mock_indevolt.set_data.return_value = False # Mock call to start charging with pytest.raises(HomeAssistantError) as exc_info: @@ -409,7 +409,7 @@ async def test_multi_device_execution_failure( await setup_integration(hass, alt_mock_config_entry) # Simulate an API push failure (triggers for both coordinators) - mock_indevolt.set_data.side_effect = OSError("Device push failed") + mock_indevolt.set_data.return_value = False # Mock call to start charging both devices with pytest.raises(HomeAssistantError) as exc_info: diff --git a/tests/components/indevolt/test_switch.py b/tests/components/indevolt/test_switch.py index 577d897ae5c64b..1184a03ce7a072 100644 --- a/tests/components/indevolt/test_switch.py +++ b/tests/components/indevolt/test_switch.py @@ -167,10 +167,7 @@ async def test_switch_set_value_error( with patch("homeassistant.components.indevolt.PLATFORMS", [Platform.SWITCH]): await setup_integration(hass, mock_config_entry) - # Mock set_data to raise an error - mock_indevolt.set_data.side_effect = HomeAssistantError( - "Device communication failed" - ) + mock_indevolt.set_data.return_value = False # Attempt to switch on with pytest.raises(HomeAssistantError):