diff --git a/homeassistant/components/file/__init__.py b/homeassistant/components/file/__init__.py index 8f49fb097756..53417cc25dd0 100644 --- a/homeassistant/components/file/__init__.py +++ b/homeassistant/components/file/__init__.py @@ -11,7 +11,7 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.typing import ConfigType from .const import DOMAIN -from .services import async_register_services +from .services import async_setup_services PLATFORMS = [Platform.NOTIFY, Platform.SENSOR] @@ -20,7 +20,7 @@ CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the file component.""" - async_register_services(hass) + async_setup_services(hass) return True diff --git a/homeassistant/components/file/services.py b/homeassistant/components/file/services.py index 3db7bb2c922d..0cd4aaf9324d 100644 --- a/homeassistant/components/file/services.py +++ b/homeassistant/components/file/services.py @@ -6,29 +6,29 @@ import json import voluptuous as vol import yaml -from homeassistant.core import HomeAssistant, ServiceCall, SupportsResponse +from homeassistant.core import HomeAssistant, ServiceCall, SupportsResponse, callback from homeassistant.exceptions import HomeAssistantError, ServiceValidationError from homeassistant.helpers import config_validation as cv from .const import ATTR_FILE_ENCODING, ATTR_FILE_NAME, DOMAIN, SERVICE_READ_FILE -def async_register_services(hass: HomeAssistant) -> None: +@callback +def async_setup_services(hass: HomeAssistant) -> None: """Register services for File integration.""" - if not hass.services.has_service(DOMAIN, SERVICE_READ_FILE): - hass.services.async_register( - DOMAIN, - SERVICE_READ_FILE, - read_file, - schema=vol.Schema( - { - vol.Required(ATTR_FILE_NAME): cv.string, - vol.Required(ATTR_FILE_ENCODING): cv.string, - } - ), - supports_response=SupportsResponse.ONLY, - ) + hass.services.async_register( + DOMAIN, + SERVICE_READ_FILE, + read_file, + schema=vol.Schema( + { + vol.Required(ATTR_FILE_NAME): cv.string, + vol.Required(ATTR_FILE_ENCODING): cv.string, + } + ), + supports_response=SupportsResponse.ONLY, + ) ENCODING_LOADERS: dict[str, tuple[Callable, type[Exception]]] = {