diff --git a/homeassistant/components/ohme/services.py b/homeassistant/components/ohme/services.py index bebfe718095..62307521fd3 100644 --- a/homeassistant/components/ohme/services.py +++ b/homeassistant/components/ohme/services.py @@ -5,7 +5,6 @@ from typing import Final from ohme import OhmeApiClient import voluptuous as vol -from homeassistant.config_entries import ConfigEntryState from homeassistant.core import ( HomeAssistant, ServiceCall, @@ -13,8 +12,7 @@ from homeassistant.core import ( SupportsResponse, callback, ) -from homeassistant.exceptions import ServiceValidationError -from homeassistant.helpers import selector +from homeassistant.helpers import selector, service from .const import DOMAIN from .coordinator import OhmeConfigEntry @@ -48,25 +46,9 @@ SERVICE_SET_PRICE_CAP_SCHEMA: Final = vol.Schema( def __get_client(call: ServiceCall) -> OhmeApiClient: """Get the client from the config entry.""" - entry_id: str = call.data[ATTR_CONFIG_ENTRY] - entry: OhmeConfigEntry | None = call.hass.config_entries.async_get_entry(entry_id) - - if not entry: - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="invalid_config_entry", - translation_placeholders={ - "config_entry": entry_id, - }, - ) - if entry.state != ConfigEntryState.LOADED: - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="unloaded_config_entry", - translation_placeholders={ - "config_entry": entry.title, - }, - ) + entry: OhmeConfigEntry = service.async_get_config_entry( + call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY] + ) return entry.runtime_data.charge_session_coordinator.client diff --git a/homeassistant/components/ohme/strings.json b/homeassistant/components/ohme/strings.json index 4ab9c851082..c30a35d26c5 100644 --- a/homeassistant/components/ohme/strings.json +++ b/homeassistant/components/ohme/strings.json @@ -121,12 +121,6 @@ }, "device_info_failed": { "message": "Unable to get Ohme device information" - }, - "invalid_config_entry": { - "message": "Invalid config entry provided. Got {config_entry}" - }, - "unloaded_config_entry": { - "message": "Invalid config entry provided. {config_entry} is not loaded." } }, "services": { diff --git a/tests/components/ohme/test_services.py b/tests/components/ohme/test_services.py index c228ddcd9a7..466d88ffd93 100644 --- a/tests/components/ohme/test_services.py +++ b/tests/components/ohme/test_services.py @@ -85,9 +85,7 @@ async def test_list_charge_slots_exception( await setup_integration(hass, mock_config_entry) # Test error - with pytest.raises( - ServiceValidationError, match="Invalid config entry provided. Got invalid" - ): + with pytest.raises(ServiceValidationError, match="service_config_entry_not_found"): await hass.services.async_call( DOMAIN, SERVICE_LIST_CHARGE_SLOTS,