Add agent_dvr integration (#32711)

* initial

* add missing fixture

* fix mocks

* fix mocks 2

* update coverage

* fix broken sync between agent and integration

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* updates for review

* add back in should poll again

* revert motion detection enabled flag in state attributes

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/agent_dvr/camera.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* add is_streaming

* fix is_streaming bug, remove mp4 stream

* cleanup

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
authored and GitHub committed 2020-05-08 09:49:47 -05:00
1 parent 3a0d5126ae
commit 1be41b9de8
18 files changed
+641

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
"""Tests for the agent_dvr component."""
from homeassistant.components.agent_dvr.const import DOMAIN, SERVER_URL
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
async def init_integration(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, skip_setup: bool = False,
) -> MockConfigEntry:
"""Set up the Agent DVR integration in Home Assistant."""
aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getStatus",
text=load_fixture("agent_dvr/status.json"),
headers={"Content-Type": "application/json"},
)
aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getObjects",
text=load_fixture("agent_dvr/objects.json"),
headers={"Content-Type": "application/json"},
)
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="c0715bba-c2d0-48ef-9e3e-bc81c9ea4447",
data={
CONF_HOST: "example.local",
CONF_PORT: 8090,
SERVER_URL: "http://example.local:8090/",
},
)
entry.add_to_hass(hass)
if not skip_setup:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry
@@ -0,0 +1,90 @@
"""Tests for the Agent DVR config flow."""
from homeassistant import data_entry_flow
from homeassistant.components.agent_dvr import config_flow
from homeassistant.components.agent_dvr.const import SERVER_URL
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from . import init_integration
from tests.common import load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
async def test_show_user_form(hass: HomeAssistant) -> None:
"""Test that the user set up form is served."""
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN, context={"source": SOURCE_USER},
)
assert result["step_id"] == "user"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
async def test_user_device_exists_abort(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test we abort flow if Agent device already configured."""
await init_integration(hass, aioclient_mock)
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "example.local", CONF_PORT: 8090},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
async def test_connection_error(hass: HomeAssistant, aioclient_mock) -> None:
"""Test we show user form on Agent connection error."""
aioclient_mock.get("http://example.local:8090/command.cgi?cmd=getStatus", text="")
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "example.local", CONF_PORT: 8090},
)
assert result["errors"] == {"base": "device_unavailable"}
assert result["step_id"] == "user"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
async def test_full_user_flow_implementation(
hass: HomeAssistant, aioclient_mock
) -> None:
"""Test the full manual user flow from start to finish."""
aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getStatus",
text=load_fixture("agent_dvr/status.json"),
headers={"Content-Type": "application/json"},
)
aioclient_mock.get(
"http://example.local:8090/command.cgi?cmd=getObjects",
text=load_fixture("agent_dvr/objects.json"),
headers={"Content-Type": "application/json"},
)
result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN, context={"source": SOURCE_USER},
)
assert result["step_id"] == "user"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_HOST: "example.local", CONF_PORT: 8090}
)
assert result["data"][CONF_HOST] == "example.local"
assert result["data"][CONF_PORT] == 8090
assert result["data"][SERVER_URL] == "http://example.local:8090/"
assert result["title"] == "DESKTOP"
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
entries = hass.config_entries.async_entries(config_flow.DOMAIN)
assert entries[0].unique_id == "c0715bba-c2d0-48ef-9e3e-bc81c9ea4447"