Remove nextcloud YAML configuration (#93550)
parent
f5cba290ad
commit
171ce747c1
|
@ -1,5 +1,4 @@
|
|||
"""The Nextcloud integration."""
|
||||
import logging
|
||||
|
||||
from nextcloudmonitor import (
|
||||
NextcloudMonitor,
|
||||
|
@ -7,12 +6,10 @@ from nextcloudmonitor import (
|
|||
NextcloudMonitorConnectionError,
|
||||
NextcloudMonitorRequestError,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_URL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
|
@ -21,58 +18,13 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN
|
||||
from .const import DOMAIN
|
||||
from .coordinator import NextcloudDataUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
PLATFORMS = (Platform.SENSOR, Platform.BINARY_SENSOR)
|
||||
|
||||
# Validate user configuration
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_URL): cv.url,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(
|
||||
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
|
||||
): cv.time_period,
|
||||
},
|
||||
)
|
||||
},
|
||||
),
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Nextcloud integration."""
|
||||
if DOMAIN in config:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"deprecated_yaml",
|
||||
breaks_in_ha_version="2023.6.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=config[DOMAIN],
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from nextcloudmonitor import (
|
||||
NextcloudMonitor,
|
||||
NextcloudMonitorAuthorizationError,
|
||||
NextcloudMonitorConnectionError,
|
||||
NextcloudMonitorError,
|
||||
NextcloudMonitorRequestError,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
@ -35,8 +33,6 @@ DATA_SCHEMA_REAUTH = vol.Schema(
|
|||
}
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a Nextcloud config flow."""
|
||||
|
@ -54,25 +50,6 @@ class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
user_input.get(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL),
|
||||
)
|
||||
|
||||
async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult:
|
||||
"""Handle a flow initiated by configuration file."""
|
||||
self._async_abort_entries_match({CONF_URL: user_input.get(CONF_URL)})
|
||||
try:
|
||||
await self.hass.async_add_executor_job(self._try_connect_nc, user_input)
|
||||
except NextcloudMonitorError:
|
||||
_LOGGER.error(
|
||||
"Connection error during import of yaml configuration, import aborted"
|
||||
)
|
||||
return self.async_abort(reason="connection_error_during_import")
|
||||
return await self.async_step_user(
|
||||
{
|
||||
CONF_URL: user_input[CONF_URL],
|
||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
||||
CONF_USERNAME: user_input[CONF_USERNAME],
|
||||
CONF_VERIFY_SSL: DEFAULT_VERIFY_SSL,
|
||||
}
|
||||
)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
|
|
|
@ -28,11 +28,5 @@
|
|||
"connection_error": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml": {
|
||||
"title": "The Nextcloud YAML configuration has been deprecated",
|
||||
"description": "Configuring Nextcloud using YAML has been deprecated.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the `nextcloud` YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ from unittest.mock import Mock, patch
|
|||
from nextcloudmonitor import (
|
||||
NextcloudMonitorAuthorizationError,
|
||||
NextcloudMonitorConnectionError,
|
||||
NextcloudMonitorError,
|
||||
NextcloudMonitorRequestError,
|
||||
)
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.nextcloud import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
@ -131,67 +130,6 @@ async def test_user_already_configured(
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_import(
|
||||
hass: HomeAssistant, mock_nextcloud_monitor: Mock, snapshot: SnapshotAssertion
|
||||
) -> None:
|
||||
"""Test that the import step works."""
|
||||
with patch(
|
||||
"homeassistant.components.nextcloud.config_flow.NextcloudMonitor",
|
||||
return_value=mock_nextcloud_monitor,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=VALID_CONFIG,
|
||||
)
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "nc_url"
|
||||
assert result["data"] == snapshot
|
||||
|
||||
|
||||
async def test_import_already_configured(
|
||||
hass: HomeAssistant, mock_nextcloud_monitor: Mock
|
||||
) -> None:
|
||||
"""Test that import step is aborted when duplicates are added."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="nc_url",
|
||||
unique_id="nc_url",
|
||||
data=VALID_CONFIG,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.nextcloud.config_flow.NextcloudMonitor",
|
||||
return_value=mock_nextcloud_monitor,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=VALID_CONFIG,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_import_connection_error(hass: HomeAssistant) -> None:
|
||||
"""Test that import step is aborted on connection error."""
|
||||
with patch(
|
||||
"homeassistant.components.nextcloud.config_flow.NextcloudMonitor",
|
||||
side_effect=NextcloudMonitorError,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=VALID_CONFIG,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "connection_error_during_import"
|
||||
|
||||
|
||||
async def test_reauth(
|
||||
hass: HomeAssistant, mock_nextcloud_monitor: Mock, snapshot: SnapshotAssertion
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in New Issue