From e37cd6fea01e3bc422ad0f959221d6e22ae9be25 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 6 Oct 2026 15:09:54 +0200 Subject: [PATCH] Move local_file service registration to services module (#184465) Co-authored-by: Claude Opus 5.5 --- .../components/local_file/__init__.py | 12 ++++++++++ homeassistant/components/local_file/camera.py | 13 ---------- .../components/local_file/services.py | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 homeassistant/components/local_file/services.py diff --git a/homeassistant/components/local_file/__init__.py b/homeassistant/components/local_file/__init__.py index 183c8b7ee82e..ca6ca1e57f61 100644 --- a/homeassistant/components/local_file/__init__.py +++ b/homeassistant/components/local_file/__init__.py @@ -4,13 +4,25 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_FILE_PATH, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryError +from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.typing import ConfigType from .const import DOMAIN +from .services import async_setup_services from .util import check_file_path_access PLATFORMS = [Platform.CAMERA] +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) + + +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: + """Set up the Local file integration.""" + async_setup_services(hass) + return True + + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Local file from a config entry.""" file_path: str = entry.options[CONF_FILE_PATH] diff --git a/homeassistant/components/local_file/camera.py b/homeassistant/components/local_file/camera.py index 831e7f7b275b..1e5dacd3443c 100644 --- a/homeassistant/components/local_file/camera.py +++ b/homeassistant/components/local_file/camera.py @@ -4,17 +4,13 @@ import logging import mimetypes from typing import override -import probatio - from homeassistant.components.camera import Camera from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_FILE_PATH, CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.exceptions import ServiceValidationError -from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .const import SERVICE_UPDATE_FILE_PATH from .util import check_file_path_access _LOGGER = logging.getLogger(__name__) @@ -27,15 +23,6 @@ async def async_setup_entry( ) -> None: """Set up the Camera for local file from a config entry.""" - platform = entity_platform.async_get_current_platform() - platform.async_register_entity_service( - SERVICE_UPDATE_FILE_PATH, - { - probatio.Required(CONF_FILE_PATH): cv.string, - }, - "update_file_path", - ) - async_add_entities( [ LocalFile( diff --git a/homeassistant/components/local_file/services.py b/homeassistant/components/local_file/services.py new file mode 100644 index 000000000000..f4186dc1b691 --- /dev/null +++ b/homeassistant/components/local_file/services.py @@ -0,0 +1,24 @@ +"""Services for the Local file integration.""" + +import probatio + +from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN +from homeassistant.const import CONF_FILE_PATH +from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers import config_validation as cv, service + +from .const import DOMAIN, SERVICE_UPDATE_FILE_PATH + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Local file integration.""" + + service.async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_UPDATE_FILE_PATH, + entity_domain=CAMERA_DOMAIN, + schema={probatio.Required(CONF_FILE_PATH): cv.string}, + func="update_file_path", + )