diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 3de47db80d1..f6b909231ca 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -6,6 +6,7 @@ from contextlib import suppress from datetime import timedelta import hashlib import logging +import os from random import SystemRandom from aiohttp import web @@ -660,6 +661,8 @@ async def async_handle_snapshot_service(camera, service): def _write_image(to_file, image_data): """Executor helper to write image.""" + if not os.path.exists(os.path.dirname(to_file)): + os.makedirs(os.path.dirname(to_file), exist_ok=True) with open(to_file, "wb") as img_file: img_file.write(image_data) diff --git a/homeassistant/components/stream/recorder.py b/homeassistant/components/stream/recorder.py index 0a93ea0bc92..82b146cc51f 100644 --- a/homeassistant/components/stream/recorder.py +++ b/homeassistant/components/stream/recorder.py @@ -1,5 +1,5 @@ """Provide functionality to record stream.""" - +import os import threading from typing import List @@ -17,6 +17,9 @@ def async_setup_recorder(hass): def recorder_save_worker(file_out: str, segments: List[Segment], container_format: str): """Handle saving stream.""" + if not os.path.exists(os.path.dirname(file_out)): + os.makedirs(os.path.dirname(file_out), exist_ok=True) + first_pts = {"video": None, "audio": None} output = av.open(file_out, "w", format=container_format) output_v = None diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index 564dd7377b1..0e73d9e871b 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -328,6 +328,8 @@ class TensorFlowImageProcessor(ImageProcessingEntity): for path in paths: _LOGGER.info("Saving results image to %s", path) + if not os.path.exists(os.path.dirname(path)): + os.makedirs(os.path.dirname(path), exist_ok=True) img.save(path) def process_image(self, image):