Exemplo n.º 1
0
Arquivo: camera.py Projeto: 2Fake/core
 def perform_wake_device(self) -> None:
     """Basically wakes the camera by querying the device."""
     try:
         self.coordinator.ezviz_client.get_detection_sensibility(
             self._serial)
     except (HTTPError, PyEzvizError) as err:
         raise PyEzvizError("Cannot wake device") from err
Exemplo n.º 2
0
async def test_user_custom_url_exception(hass, ezviz_config_flow):
    """Test we handle unexpected exception."""
    ezviz_config_flow.side_effect = PyEzvizError()
    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER}
    )

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
            CONF_URL: CONF_CUSTOMIZE,
        },
    )

    assert result["type"] == FlowResultType.FORM
    assert result["step_id"] == "user_custom_url"
    assert result["errors"] == {}

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {CONF_URL: "test-user"},
    )

    assert result["type"] == FlowResultType.FORM
    assert result["step_id"] == "user_custom_url"
    assert result["errors"] == {"base": "invalid_auth"}

    ezviz_config_flow.side_effect = InvalidURL

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {CONF_URL: "test-user"},
    )

    assert result["type"] == FlowResultType.FORM
    assert result["step_id"] == "user_custom_url"
    assert result["errors"] == {"base": "invalid_host"}

    ezviz_config_flow.side_effect = HTTPError

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {CONF_URL: "test-user"},
    )

    assert result["type"] == FlowResultType.FORM
    assert result["step_id"] == "user_custom_url"
    assert result["errors"] == {"base": "cannot_connect"}

    ezviz_config_flow.side_effect = Exception

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {CONF_URL: "test-user"},
    )

    assert result["type"] == FlowResultType.ABORT
    assert result["reason"] == "unknown"
Exemplo n.º 3
0
 def perform_set_alarm_detection_sensibility(self, level, type_value):
     """Set camera detection sensibility level service."""
     try:
         self.coordinator.ezviz_client.detection_sensibility(
             self._serial, level, type_value)
     except (HTTPError, PyEzvizError) as err:
         raise PyEzvizError(
             "Cannot set detection sensitivity level") from err
Exemplo n.º 4
0
    async def async_turn_off(self, **kwargs: Any) -> None:
        """Change a device switch on the camera."""
        try:
            update_ok = await self.hass.async_add_executor_job(
                self.coordinator.ezviz_client.switch_status, self._serial,
                self._name, 0)

        except (HTTPError, PyEzvizError) as err:
            raise PyEzvizError(
                f"Failed to turn off switch {self._name}") from err

        if update_ok:
            await self.coordinator.async_request_refresh()
Exemplo n.º 5
0
async def test_async_step_reauth_exception(hass, ezviz_config_flow):
    """Test the reauth step exceptions."""

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_USER})
    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "user"
    assert result["errors"] == {}

    with _patch_async_setup_entry() as mock_setup_entry:
        result = await hass.config_entries.flow.async_configure(
            result["flow_id"],
            USER_INPUT_VALIDATE,
        )
    await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_CREATE_ENTRY
    assert result["title"] == "test-username"
    assert result["data"] == {**API_LOGIN_RETURN_VALIDATE}

    assert len(mock_setup_entry.mock_calls) == 1

    result = await hass.config_entries.flow.async_init(
        DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE)
    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "reauth_confirm"
    assert result["errors"] == {}

    ezviz_config_flow.side_effect = InvalidURL()
    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        },
    )
    await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "reauth_confirm"
    assert result["errors"] == {"base": "invalid_host"}

    ezviz_config_flow.side_effect = InvalidHost()
    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        },
    )
    await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "reauth_confirm"
    assert result["errors"] == {"base": "cannot_connect"}

    ezviz_config_flow.side_effect = EzvizAuthVerificationCode()
    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        },
    )
    await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "reauth_confirm"
    assert result["errors"] == {"base": "mfa_required"}

    ezviz_config_flow.side_effect = PyEzvizError()
    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        },
    )
    await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_FORM
    assert result["step_id"] == "reauth_confirm"
    assert result["errors"] == {"base": "invalid_auth"}

    ezviz_config_flow.side_effect = Exception()
    result = await hass.config_entries.flow.async_configure(
        result["flow_id"],
        {
            CONF_USERNAME: "******",
            CONF_PASSWORD: "******",
        },
    )
    await hass.async_block_till_done()

    assert result["type"] == RESULT_TYPE_ABORT
    assert result["reason"] == "unknown"