Remove deprecated YAML configuration from EZVIZ (#69031)
This commit is contained in:
parent
5280bf2296
commit
388677e03b
5 changed files with 2 additions and 244 deletions
|
@ -7,18 +7,16 @@ from pyezviz.exceptions import HTTPError, InvalidHost, PyEzvizError
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import ffmpeg
|
||||
from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_STREAM, Camera
|
||||
from homeassistant.components.camera import SUPPORT_STREAM, Camera
|
||||
from homeassistant.components.ffmpeg import get_ffmpeg_manager
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_IGNORE,
|
||||
SOURCE_IMPORT,
|
||||
SOURCE_INTEGRATION_DISCOVERY,
|
||||
ConfigEntry,
|
||||
)
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import (
|
||||
ATTR_DIRECTION,
|
||||
|
@ -27,7 +25,6 @@ from .const import (
|
|||
ATTR_SERIAL,
|
||||
ATTR_SPEED,
|
||||
ATTR_TYPE,
|
||||
CONF_CAMERAS,
|
||||
CONF_FFMPEG_ARGUMENTS,
|
||||
DATA_COORDINATOR,
|
||||
DEFAULT_CAMERA_USERNAME,
|
||||
|
@ -47,62 +44,9 @@ from .const import (
|
|||
from .coordinator import EzvizDataUpdateCoordinator
|
||||
from .entity import EzvizEntity
|
||||
|
||||
CAMERA_SCHEMA = vol.Schema(
|
||||
{vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string}
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_CAMERAS, default={}): {cv.string: CAMERA_SCHEMA},
|
||||
}
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: entity_platform.AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up a Ezviz IP Camera from platform config."""
|
||||
_LOGGER.warning(
|
||||
"Loading ezviz via platform config is deprecated, it will be automatically imported. Please remove it afterwards"
|
||||
)
|
||||
|
||||
# Check if entry config exists and skips import if it does.
|
||||
if hass.config_entries.async_entries(DOMAIN):
|
||||
return
|
||||
|
||||
# Check if importing camera account.
|
||||
if CONF_CAMERAS in config:
|
||||
cameras_conf = config[CONF_CAMERAS]
|
||||
for serial, camera in cameras_conf.items():
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
ATTR_SERIAL: serial,
|
||||
CONF_USERNAME: camera[CONF_USERNAME],
|
||||
CONF_PASSWORD: camera[CONF_PASSWORD],
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
# Check if importing main ezviz cloud account.
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=config,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
|
|
|
@ -307,50 +307,6 @@ class EzvizConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
},
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config):
|
||||
"""Handle config import from yaml."""
|
||||
_LOGGER.debug("import config: %s", import_config)
|
||||
|
||||
# Check importing camera.
|
||||
if ATTR_SERIAL in import_config:
|
||||
return await self.async_step_import_camera(import_config)
|
||||
|
||||
# Validate and setup of main ezviz cloud account.
|
||||
try:
|
||||
return await self._validate_and_create_auth(import_config)
|
||||
|
||||
except InvalidURL:
|
||||
_LOGGER.error("Error importing Ezviz platform config: invalid host")
|
||||
return self.async_abort(reason="invalid_host")
|
||||
|
||||
except InvalidHost:
|
||||
_LOGGER.error("Error importing Ezviz platform config: cannot connect")
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
except (AuthTestResultFailed, PyEzvizError):
|
||||
_LOGGER.error("Error importing Ezviz platform config: invalid auth")
|
||||
return self.async_abort(reason="invalid_auth")
|
||||
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception(
|
||||
"Error importing ezviz platform config: unexpected exception"
|
||||
)
|
||||
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
async def async_step_import_camera(self, data):
|
||||
"""Create RTSP auth entry per camera in config."""
|
||||
|
||||
await self.async_set_unique_id(data[ATTR_SERIAL])
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
_LOGGER.debug("Create camera with: %s", data)
|
||||
|
||||
cam_serial = data.pop(ATTR_SERIAL)
|
||||
data[CONF_TYPE] = ATTR_TYPE_CAMERA
|
||||
|
||||
return self.async_create_entry(title=cam_serial, data=data)
|
||||
|
||||
|
||||
class EzvizOptionsFlowHandler(OptionsFlow):
|
||||
"""Handle Ezviz client options."""
|
||||
|
|
|
@ -5,7 +5,6 @@ MANUFACTURER = "Ezviz"
|
|||
|
||||
# Configuration
|
||||
ATTR_SERIAL = "serial"
|
||||
CONF_CAMERAS = "cameras"
|
||||
CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments"
|
||||
ATTR_HOME = "HOME_MODE"
|
||||
ATTR_AWAY = "AWAY_MODE"
|
||||
|
|
|
@ -3,9 +3,7 @@ from unittest.mock import patch
|
|||
|
||||
from homeassistant.components.ezviz.const import (
|
||||
ATTR_SERIAL,
|
||||
ATTR_TYPE_CAMERA,
|
||||
ATTR_TYPE_CLOUD,
|
||||
CONF_CAMERAS,
|
||||
CONF_FFMPEG_ARGUMENTS,
|
||||
DEFAULT_FFMPEG_ARGUMENTS,
|
||||
DEFAULT_TIMEOUT,
|
||||
|
@ -48,37 +46,6 @@ USER_INPUT = {
|
|||
CONF_TYPE: ATTR_TYPE_CLOUD,
|
||||
}
|
||||
|
||||
USER_INPUT_CAMERA_VALIDATE = {
|
||||
ATTR_SERIAL: "C666666",
|
||||
CONF_PASSWORD: "test-password",
|
||||
CONF_USERNAME: "test-username",
|
||||
}
|
||||
|
||||
USER_INPUT_CAMERA = {
|
||||
CONF_PASSWORD: "test-password",
|
||||
CONF_USERNAME: "test-username",
|
||||
CONF_TYPE: ATTR_TYPE_CAMERA,
|
||||
}
|
||||
|
||||
YAML_CONFIG = {
|
||||
CONF_USERNAME: "test-username",
|
||||
CONF_PASSWORD: "test-password",
|
||||
CONF_URL: "apiieu.ezvizlife.com",
|
||||
CONF_CAMERAS: {
|
||||
"C666666": {CONF_USERNAME: "test-username", CONF_PASSWORD: "test-password"}
|
||||
},
|
||||
}
|
||||
|
||||
YAML_INVALID = {
|
||||
"C666666": {CONF_USERNAME: "test-username", CONF_PASSWORD: "test-password"}
|
||||
}
|
||||
|
||||
YAML_CONFIG_CAMERA = {
|
||||
ATTR_SERIAL: "C666666",
|
||||
CONF_USERNAME: "test-username",
|
||||
CONF_PASSWORD: "test-password",
|
||||
}
|
||||
|
||||
DISCOVERY_INFO = {
|
||||
ATTR_SERIAL: "C666666",
|
||||
CONF_USERNAME: None,
|
||||
|
|
|
@ -19,11 +19,7 @@ from homeassistant.components.ezviz.const import (
|
|||
DEFAULT_TIMEOUT,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_IMPORT,
|
||||
SOURCE_INTEGRATION_DISCOVERY,
|
||||
SOURCE_USER,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, SOURCE_USER
|
||||
from homeassistant.const import (
|
||||
CONF_CUSTOMIZE,
|
||||
CONF_IP_ADDRESS,
|
||||
|
@ -42,12 +38,7 @@ from homeassistant.data_entry_flow import (
|
|||
from . import (
|
||||
DISCOVERY_INFO,
|
||||
USER_INPUT,
|
||||
USER_INPUT_CAMERA,
|
||||
USER_INPUT_CAMERA_VALIDATE,
|
||||
USER_INPUT_VALIDATE,
|
||||
YAML_CONFIG,
|
||||
YAML_CONFIG_CAMERA,
|
||||
YAML_INVALID,
|
||||
_patch_async_setup_entry,
|
||||
init_integration,
|
||||
)
|
||||
|
@ -115,66 +106,6 @@ async def test_user_custom_url(hass, ezviz_config_flow):
|
|||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_step_import(hass, ezviz_config_flow):
|
||||
"""Test the config import flow."""
|
||||
|
||||
with _patch_async_setup_entry() as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == USER_INPUT
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_step_import_camera(hass, ezviz_config_flow):
|
||||
"""Test the config import camera flow."""
|
||||
|
||||
with _patch_async_setup_entry() as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG_CAMERA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == USER_INPUT_CAMERA
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_step_import_2nd_form_returns_camera(hass, ezviz_config_flow):
|
||||
"""Test we get the user initiated form."""
|
||||
|
||||
with _patch_async_setup_entry() as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == USER_INPUT
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
with _patch_async_setup_entry() as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=USER_INPUT_CAMERA_VALIDATE
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == USER_INPUT_CAMERA
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_step_import_abort(hass, ezviz_config_flow):
|
||||
"""Test the config import flow with invalid data."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_INVALID
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_step_discovery_abort_if_cloud_account_missing(hass):
|
||||
"""Test discovery and confirm step, abort if cloud account was removed."""
|
||||
|
||||
|
@ -308,45 +239,6 @@ async def test_user_form_exception(hass, ezviz_config_flow):
|
|||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_import_exception(hass, ezviz_config_flow):
|
||||
"""Test we handle unexpected exception on import."""
|
||||
ezviz_config_flow.side_effect = PyEzvizError
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "invalid_auth"
|
||||
|
||||
ezviz_config_flow.side_effect = InvalidURL
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "invalid_host"
|
||||
|
||||
ezviz_config_flow.side_effect = HTTPError
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
ezviz_config_flow.side_effect = Exception
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_discover_exception_step1(
|
||||
hass,
|
||||
ezviz_config_flow,
|
||||
|
|
Loading…
Add table
Reference in a new issue