Merge branch 'dev' into generic_camera_include_settings_in_preview_url
This commit is contained in:
commit
0843eb8032
2 changed files with 20 additions and 16 deletions
|
@ -3,7 +3,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
from typing import Any, Self, cast
|
||||
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
from python_awair import Awair, AwairLocal, AwairLocalDevice
|
||||
|
@ -26,16 +26,17 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
VERSION = 1
|
||||
|
||||
_device: AwairLocalDevice
|
||||
host: str
|
||||
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle zeroconf discovery."""
|
||||
|
||||
host = discovery_info.host
|
||||
LOGGER.debug("Discovered device: %s", host)
|
||||
self.host = discovery_info.host
|
||||
LOGGER.debug("Discovered device: %s", self.host)
|
||||
|
||||
self._device, _ = await self._check_local_connection(host)
|
||||
self._device, _ = await self._check_local_connection(self.host)
|
||||
|
||||
if self._device is not None:
|
||||
await self.async_set_unique_id(self._device.mac_address)
|
||||
|
@ -45,7 +46,6 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
)
|
||||
self.context.update(
|
||||
{
|
||||
"host": host,
|
||||
"title_placeholders": {
|
||||
"model": self._device.model,
|
||||
"device_id": self._device.device_id,
|
||||
|
@ -119,12 +119,16 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
def _get_discovered_entries(self) -> dict[str, str]:
|
||||
"""Get discovered entries."""
|
||||
entries: dict[str, str] = {}
|
||||
for flow in self._async_in_progress():
|
||||
if flow["context"]["source"] == SOURCE_ZEROCONF:
|
||||
info = flow["context"]["title_placeholders"]
|
||||
entries[flow["context"]["host"]] = (
|
||||
f"{info['model']} ({info['device_id']})"
|
||||
)
|
||||
|
||||
flows = cast(
|
||||
set[Self],
|
||||
self.hass.config_entries.flow._handler_progress_index.get(DOMAIN) or set(), # noqa: SLF001
|
||||
)
|
||||
for flow in flows:
|
||||
if flow.source != SOURCE_ZEROCONF:
|
||||
continue
|
||||
info = flow.context["title_placeholders"]
|
||||
entries[flow.host] = f"{info['model']} ({info['device_id']})"
|
||||
return entries
|
||||
|
||||
async def async_step_local(
|
||||
|
|
|
@ -92,9 +92,9 @@ async def test_form(
|
|||
assert result1["type"] is FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
client = await hass_client()
|
||||
preview_id = result1["flow_id"]
|
||||
preview_url = result1["description_placeholders"]["preview_url"]
|
||||
# Check the preview image works.
|
||||
resp = await client.get(f"/api/generic/preview_flow_image/{preview_id}?t=1")
|
||||
resp = await client.get(preview_url)
|
||||
assert resp.status == HTTPStatus.OK
|
||||
assert await resp.read() == fakeimgbytes_png
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
|
@ -118,7 +118,7 @@ async def test_form(
|
|||
|
||||
await hass.async_block_till_done()
|
||||
# Check that the preview image is disabled after.
|
||||
resp = await client.get(f"/api/generic/preview_flow_image/{preview_id}")
|
||||
resp = await client.get(preview_url)
|
||||
assert resp.status == HTTPStatus.NOT_FOUND
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
@ -212,10 +212,10 @@ async def test_form_still_preview_cam_off(
|
|||
)
|
||||
assert result1["type"] is FlowResultType.FORM
|
||||
assert result1["step_id"] == "user_confirm_still"
|
||||
preview_id = result1["flow_id"]
|
||||
preview_url = result1["description_placeholders"]["preview_url"]
|
||||
# Try to view the image, should be unavailable.
|
||||
client = await hass_client()
|
||||
resp = await client.get(f"/api/generic/preview_flow_image/{preview_id}?t=1")
|
||||
resp = await client.get(preview_url)
|
||||
assert resp.status == HTTPStatus.SERVICE_UNAVAILABLE
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue