diff --git a/homeassistant/components/easyenergy/services.py b/homeassistant/components/easyenergy/services.py index f8d03d3b460..1ae7d5c5b5a 100644 --- a/homeassistant/components/easyenergy/services.py +++ b/homeassistant/components/easyenergy/services.py @@ -10,7 +10,6 @@ from typing import Final from easyenergy import Electricity, Gas, VatOption import voluptuous as vol -from homeassistant.config_entries import ConfigEntryState from homeassistant.core import ( HomeAssistant, ServiceCall, @@ -19,7 +18,7 @@ from homeassistant.core import ( callback, ) from homeassistant.exceptions import ServiceValidationError -from homeassistant.helpers import selector +from homeassistant.helpers import selector, service from homeassistant.util import dt as dt_util from .const import DOMAIN @@ -88,28 +87,9 @@ def __serialize_prices(prices: list[dict[str, float | datetime]]) -> ServiceResp def __get_coordinator(call: ServiceCall) -> EasyEnergyDataUpdateCoordinator: """Get the coordinator from the entry.""" - entry_id: str = call.data[ATTR_CONFIG_ENTRY] - entry: EasyEnergyConfigEntry | None = call.hass.config_entries.async_get_entry( - entry_id + entry: EasyEnergyConfigEntry = service.async_get_config_entry( + call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY] ) - - 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, - }, - ) - return entry.runtime_data diff --git a/homeassistant/components/easyenergy/strings.json b/homeassistant/components/easyenergy/strings.json index 648f4500079..b82b6e8744b 100644 --- a/homeassistant/components/easyenergy/strings.json +++ b/homeassistant/components/easyenergy/strings.json @@ -44,14 +44,8 @@ } }, "exceptions": { - "invalid_config_entry": { - "message": "Invalid config entry provided. Got {config_entry}" - }, "invalid_date": { "message": "Invalid date provided. Got {date}" - }, - "unloaded_config_entry": { - "message": "Invalid config entry provided. {config_entry} is not loaded." } }, "services": { diff --git a/tests/components/easyenergy/test_services.py b/tests/components/easyenergy/test_services.py index 603768237f1..81c6fe57823 100644 --- a/tests/components/easyenergy/test_services.py +++ b/tests/components/easyenergy/test_services.py @@ -108,7 +108,7 @@ def config_entry_data( {"config_entry": "incorrect entry"}, {"incl_vat": True}, ServiceValidationError, - "Invalid config entry.+", + "service_config_entry_not_found", ), ( {"config_entry": True},