1 """Camera that loads a picture from a local file."""
3 from __future__
import annotations
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as CAMERA_PLATFORM_SCHEMA,
19 config_validation
as cv,
27 from .const
import DEFAULT_NAME, DOMAIN, SERVICE_UPDATE_FILE_PATH
28 from .util
import check_file_path_access
30 _LOGGER = logging.getLogger(__name__)
32 PLATFORM_SCHEMA = CAMERA_PLATFORM_SCHEMA.extend(
34 vol.Required(CONF_FILE_PATH): cv.string,
35 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
43 async_add_entities: AddEntitiesCallback,
45 """Set up the Camera for local file from a config entry."""
47 platform = entity_platform.async_get_current_platform()
48 platform.async_register_entity_service(
49 SERVICE_UPDATE_FILE_PATH,
51 vol.Required(CONF_FILE_PATH): cv.string,
59 entry.options[CONF_NAME],
60 entry.options[CONF_FILE_PATH],
70 async_add_entities: AddEntitiesCallback,
71 discovery_info: DiscoveryInfoType |
None =
None,
73 """Set up the Camera that works with local files."""
74 file_path: str = config[CONF_FILE_PATH]
75 file_path_slug =
slugify(file_path)
77 if not await hass.async_add_executor_job(check_file_path_access, file_path):
78 ir.async_create_issue(
81 f
"no_access_path_{file_path_slug}",
82 breaks_in_ha_version=
"2025.5.0",
84 learn_more_url=
"https://www.home-assistant.io/integrations/local_file/",
85 severity=ir.IssueSeverity.WARNING,
86 translation_key=
"no_access_path",
87 translation_placeholders={
88 "file_path": file_path_slug,
93 ir.async_create_issue(
96 f
"deprecated_yaml_{DOMAIN}",
97 breaks_in_ha_version=
"2025.5.0",
100 learn_more_url=
"https://www.home-assistant.io/integrations/local_file/",
101 severity=ir.IssueSeverity.WARNING,
102 translation_key=
"deprecated_yaml",
103 translation_placeholders={
105 "integration_title":
"Local file",
109 hass.async_create_task(
110 hass.config_entries.flow.async_init(
112 context={
"source": SOURCE_IMPORT},
119 """Representation of a local file camera."""
121 def __init__(self, name: str, file_path: str, unique_id: str) ->
None:
122 """Initialize Local File Camera component."""
128 content, _ = mimetypes.guess_type(file_path)
129 if content
is not None:
133 self, width: int |
None =
None, height: int |
None =
None
135 """Return image response."""
139 except FileNotFoundError:
141 "Could not read camera %s image from file: %s",
148 """Update the file_path."""
149 if not await self.
hasshass.async_add_executor_job(
150 check_file_path_access, file_path
158 """Return the camera state attributes."""
159 return {
"file_path": self.
_file_path_file_path}
dict[str, str] extra_state_attributes(self)
bytes|None camera_image(self, int|None width=None, int|None height=None)
None __init__(self, str name, str file_path, str unique_id)
None update_file_path(self, str file_path)
None schedule_update_ha_state(self, bool force_refresh=False)
str|UndefinedType|None name(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
None open(self, **Any kwargs)