init home-assistant
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Tests for the Android IP Webcam integration."""
|
||||
@@ -0,0 +1,27 @@
|
||||
"""Fixtures for tests."""
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import CONTENT_TYPE_JSON
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def aioclient_mock_fixture(aioclient_mock: AiohttpClientMocker) -> None:
|
||||
"""Fixture to provide a aioclient mocker."""
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/status.json?show_avail=1",
|
||||
text=load_fixture("android_ip_webcam/status_data.json"),
|
||||
status=HTTPStatus.OK,
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/sensors.json",
|
||||
text=load_fixture("android_ip_webcam/sensor_data.json"),
|
||||
status=HTTPStatus.OK,
|
||||
headers={"Content-Type": CONTENT_TYPE_JSON},
|
||||
)
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"light": {
|
||||
"unit": "lx",
|
||||
"data": [
|
||||
[1659602753873, [708.0]],
|
||||
[1659602773708, [991.0]]
|
||||
]
|
||||
},
|
||||
"proximity": { "unit": "cm", "data": [[1659602773709, [5.0]]] },
|
||||
"motion": {
|
||||
"unit": "",
|
||||
"data": [
|
||||
[1659602752922, [8.0]],
|
||||
[1659602773709, [12.0]]
|
||||
]
|
||||
},
|
||||
"motion_active": { "unit": "", "data": [[1659602773710, [0.0]]] },
|
||||
"battery_voltage": {
|
||||
"unit": "V",
|
||||
"data": [
|
||||
[1659602769351, [4.077]],
|
||||
[1659602771352, [4.077]],
|
||||
[1659602773353, [4.077]]
|
||||
]
|
||||
},
|
||||
"battery_level": {
|
||||
"unit": "%",
|
||||
"data": [
|
||||
[1659602769351, [87.0]],
|
||||
[1659602771352, [87.0]],
|
||||
[1659602773353, [87.0]]
|
||||
]
|
||||
},
|
||||
"battery_temp": {
|
||||
"unit": "℃",
|
||||
"data": [
|
||||
[1659602769351, [33.9]],
|
||||
[1659602771352, [33.9]],
|
||||
[1659602773353, [33.9]]
|
||||
]
|
||||
},
|
||||
"sound": {
|
||||
"unit": "dB",
|
||||
"data": [
|
||||
[1659602768710, [181.0]],
|
||||
[1659602769200, [191.0]],
|
||||
[1659602769690, [186.0]],
|
||||
[1659602770181, [186.0]],
|
||||
[1659602770670, [188.0]],
|
||||
[1659602771145, [192.0]],
|
||||
[1659602771635, [192.0]],
|
||||
[1659602772125, [179.0]],
|
||||
[1659602772615, [186.0]],
|
||||
[1659602773261, [178.0]]
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"video_connections": 0,
|
||||
"audio_connections": 0,
|
||||
"video_status": { "result": "status", "enabled": "True", "mode": "none" },
|
||||
"curvals": {
|
||||
"orientation": "landscape",
|
||||
"idle": "off",
|
||||
"audio_only": "off",
|
||||
"overlay": "off",
|
||||
"quality": "49",
|
||||
"focus_homing": "off",
|
||||
"ip_address": "192.168.3.88",
|
||||
"motion_limit": "250",
|
||||
"adet_limit": "200",
|
||||
"night_vision": "off",
|
||||
"night_vision_average": "2",
|
||||
"night_vision_gain": "1.0",
|
||||
" ": "off",
|
||||
"motion_detect": "on",
|
||||
"motion_display": "off",
|
||||
"video_chunk_len": "60",
|
||||
"gps_active": "off",
|
||||
"video_size": "1920x1080",
|
||||
"mirror_flip": "none",
|
||||
"ffc": "off",
|
||||
"rtsp_video_formats": "",
|
||||
"rtsp_audio_formats": "",
|
||||
"video_connections": "0",
|
||||
"audio_connections": "0",
|
||||
"ivideon_streaming": "off",
|
||||
"zoom": "100",
|
||||
"crop_x": "50",
|
||||
"crop_y": "50",
|
||||
"coloreffect": "none",
|
||||
"scenemode": "auto",
|
||||
"focusmode": "continuous-video",
|
||||
"whitebalance": "auto",
|
||||
"flashmode": "off",
|
||||
"antibanding": "off",
|
||||
"torch": "off",
|
||||
"focus_distance": "0.0",
|
||||
"focal_length": "4.25",
|
||||
"aperture": "1.7",
|
||||
"filter_density": "0.0",
|
||||
"exposure_ns": "9384",
|
||||
"frame_duration": "33333333",
|
||||
"iso": "100",
|
||||
"manual_sensor": "off",
|
||||
"photo_size": "1920x1080",
|
||||
"photo_rotation": "-1"
|
||||
},
|
||||
"idle": ["on", "off"],
|
||||
"audio_only": ["on", "off"],
|
||||
"overlay": ["on", "off"],
|
||||
"focus_homing": ["on", "off"],
|
||||
"night_vision": ["on", "off"],
|
||||
"motion_detect": ["on", "off"],
|
||||
"motion_display": ["on", "off"],
|
||||
"gps_active": ["on", "off"],
|
||||
"ffc": ["on", "off"],
|
||||
"torch": ["on", "off"]
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
"""Test the Android IP Webcam config flow."""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.android_ip_webcam.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .test_init import MOCK_CONFIG_DATA
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant, aioclient_mock_fixture) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.android_ip_webcam.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"host": "1.1.1.1",
|
||||
"port": 8080,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "1.1.1.1"
|
||||
assert result2["data"] == {
|
||||
"host": "1.1.1.1",
|
||||
"port": 8080,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_device_already_configured(
|
||||
hass: HomeAssistant, aioclient_mock_fixture
|
||||
) -> None:
|
||||
"""Test aborting if the device is already configured."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"host": "1.1.1.1",
|
||||
"port": 8080,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] is FlowResultType.ABORT
|
||||
assert result2["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_form_invalid_auth(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test we handle invalid auth error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/status.json?show_avail=1",
|
||||
exc=aiohttp.ClientResponseError(Mock(), (), status=401),
|
||||
)
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"host": "1.1.1.1", "port": 8080, "username": "user", "password": "wrong-pass"},
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"username": "invalid_auth", "password": "invalid_auth"}
|
||||
|
||||
|
||||
async def test_form_cannot_connect(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test we handle cannot connect error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/status.json?show_avail=1",
|
||||
exc=aiohttp.ClientError,
|
||||
)
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"host": "1.1.1.1",
|
||||
},
|
||||
)
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
@@ -0,0 +1,81 @@
|
||||
"""Tests for the Android IP Webcam integration."""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant.components.android_ip_webcam.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
MOCK_CONFIG_DATA = {
|
||||
"name": "IP Webcam",
|
||||
"host": "1.1.1.1",
|
||||
"port": 8080,
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
}
|
||||
|
||||
|
||||
async def test_successful_config_entry(
|
||||
hass: HomeAssistant, aioclient_mock_fixture
|
||||
) -> None:
|
||||
"""Test settings up integration from config entry."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_setup_failed_connection_error(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test integration failed due to connection error."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/status.json?show_avail=1",
|
||||
exc=aiohttp.ClientError,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_setup_failed_invalid_auth(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test integration failed due to invalid auth."""
|
||||
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
aioclient_mock.get(
|
||||
"http://1.1.1.1:8080/status.json?show_avail=1",
|
||||
exc=aiohttp.ClientResponseError(Mock(), (), status=401),
|
||||
)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_unload_entry(hass: HomeAssistant, aioclient_mock_fixture) -> None:
|
||||
"""Test removing integration."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
Reference in New Issue
Block a user