Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Stream already recording issue #136458

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions homeassistant/components/stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,10 @@ async def async_record(
if not self.hass.config.is_allowed_path(video_path):
raise HomeAssistantError(f"Can't write {video_path}, no access to path!")

# Stop existing recording if one is active
await self.stop_recording()

# Add recorder
if recorder := self.outputs().get(RECORDER_PROVIDER):
assert isinstance(recorder, RecorderOutput)
raise HomeAssistantError(
f"Stream already recording to {recorder.video_path}!"
)
recorder = cast(
RecorderOutput, self.add_provider(RECORDER_PROVIDER, timeout=duration)
)
Expand All @@ -587,7 +585,17 @@ async def async_record(
recorder.prepend(list(hls.get_segments())[-num_segments - 1 : -1])

await recorder.async_record()


async def stop_recording(self) -> None:
"""Stop the current recording if one is in progress."""
existing_recorder = self.outputs().get(RECORDER_PROVIDER)
if not existing_recorder:
self._logger.info("No active recording to stop.")
return

await self.remove_provider(existing_recorder)
self._logger.debug("Stopped the current recording.")

async def async_get_image(
self,
width: int | None = None,
Expand Down