mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Store generic camera flow data in flow handler attributes (#127405)
This commit is contained in:
parent
14c2778558
commit
2b50f65c49
@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
from errno import EHOSTUNREACH, EIO
|
from errno import EHOSTUNREACH, EIO
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any, cast
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from httpx import HTTPStatusError, RequestError, TimeoutException
|
from httpx import HTTPStatusError, RequestError, TimeoutException
|
||||||
@ -47,7 +47,6 @@ from homeassistant.const import (
|
|||||||
HTTP_DIGEST_AUTHENTICATION,
|
HTTP_DIGEST_AUTHENTICATION,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import UnknownFlow
|
|
||||||
from homeassistant.exceptions import HomeAssistantError, TemplateError
|
from homeassistant.exceptions import HomeAssistantError, TemplateError
|
||||||
from homeassistant.helpers import config_validation as cv, template as template_helper
|
from homeassistant.helpers import config_validation as cv, template as template_helper
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
@ -316,6 +315,7 @@ class GenericIPCamConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize Generic ConfigFlow."""
|
"""Initialize Generic ConfigFlow."""
|
||||||
|
self.preview_cam: dict[str, Any] = {}
|
||||||
self.user_input: dict[str, Any] = {}
|
self.user_input: dict[str, Any] = {}
|
||||||
self.title = ""
|
self.title = ""
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ class GenericIPCamConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
title=self.title, data={}, options=self.user_input
|
title=self.title, data={}, options=self.user_input
|
||||||
)
|
)
|
||||||
# temporary preview for user to check the image
|
# temporary preview for user to check the image
|
||||||
self.context["preview_cam"] = user_input
|
self.preview_cam = user_input
|
||||||
return await self.async_step_user_confirm_still()
|
return await self.async_step_user_confirm_still()
|
||||||
elif self.user_input:
|
elif self.user_input:
|
||||||
user_input = self.user_input
|
user_input = self.user_input
|
||||||
@ -412,6 +412,7 @@ class GenericOptionsFlowHandler(OptionsFlow):
|
|||||||
def __init__(self, config_entry: ConfigEntry) -> None:
|
def __init__(self, config_entry: ConfigEntry) -> None:
|
||||||
"""Initialize Generic IP Camera options flow."""
|
"""Initialize Generic IP Camera options flow."""
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
|
self.preview_cam: dict[str, Any] = {}
|
||||||
self.user_input: dict[str, Any] = {}
|
self.user_input: dict[str, Any] = {}
|
||||||
|
|
||||||
async def async_step_init(
|
async def async_step_init(
|
||||||
@ -443,7 +444,7 @@ class GenericOptionsFlowHandler(OptionsFlow):
|
|||||||
}
|
}
|
||||||
self.user_input = data
|
self.user_input = data
|
||||||
# temporary preview for user to check the image
|
# temporary preview for user to check the image
|
||||||
self.context["preview_cam"] = data
|
self.preview_cam = data
|
||||||
return await self.async_step_confirm_still()
|
return await self.async_step_confirm_still()
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
@ -494,15 +495,17 @@ class CameraImagePreview(HomeAssistantView):
|
|||||||
async def get(self, request: web.Request, flow_id: str) -> web.Response:
|
async def get(self, request: web.Request, flow_id: str) -> web.Response:
|
||||||
"""Start a GET request."""
|
"""Start a GET request."""
|
||||||
_LOGGER.debug("processing GET request for flow_id=%s", flow_id)
|
_LOGGER.debug("processing GET request for flow_id=%s", flow_id)
|
||||||
try:
|
flow = cast(
|
||||||
flow = self.hass.config_entries.flow.async_get(flow_id)
|
GenericIPCamConfigFlow,
|
||||||
except UnknownFlow:
|
self.hass.config_entries.flow._progress.get(flow_id), # noqa: SLF001
|
||||||
try:
|
) or cast(
|
||||||
flow = self.hass.config_entries.options.async_get(flow_id)
|
GenericOptionsFlowHandler,
|
||||||
except UnknownFlow as exc:
|
self.hass.config_entries.options._progress.get(flow_id), # noqa: SLF001
|
||||||
_LOGGER.warning("Unknown flow while getting image preview")
|
)
|
||||||
raise web.HTTPNotFound from exc
|
if not flow:
|
||||||
user_input = flow["context"]["preview_cam"]
|
_LOGGER.warning("Unknown flow while getting image preview")
|
||||||
|
raise web.HTTPNotFound
|
||||||
|
user_input = flow.preview_cam
|
||||||
camera = GenericCamera(self.hass, user_input, flow_id, "preview")
|
camera = GenericCamera(self.hass, user_input, flow_id, "preview")
|
||||||
if not camera.is_on:
|
if not camera.is_on:
|
||||||
_LOGGER.debug("Camera is off")
|
_LOGGER.debug("Camera is off")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user