mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Remove yaml support from Synology DSM (#53197)
This commit is contained in:
parent
d4589894fe
commit
1b478ba02e
@ -21,12 +21,10 @@ from synology_dsm.exceptions import (
|
|||||||
SynologyDSMLoginFailedException,
|
SynologyDSMLoginFailedException,
|
||||||
SynologyDSMRequestException,
|
SynologyDSMRequestException,
|
||||||
)
|
)
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
CONF_DISKS,
|
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_MAC,
|
CONF_MAC,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
@ -46,7 +44,6 @@ from homeassistant.helpers.device_registry import (
|
|||||||
async_get_registry as get_dev_reg,
|
async_get_registry as get_dev_reg,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
@ -56,12 +53,10 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
from .const import (
|
from .const import (
|
||||||
CONF_DEVICE_TOKEN,
|
CONF_DEVICE_TOKEN,
|
||||||
CONF_SERIAL,
|
CONF_SERIAL,
|
||||||
CONF_VOLUMES,
|
|
||||||
COORDINATOR_CAMERAS,
|
COORDINATOR_CAMERAS,
|
||||||
COORDINATOR_CENTRAL,
|
COORDINATOR_CENTRAL,
|
||||||
COORDINATOR_SWITCHES,
|
COORDINATOR_SWITCHES,
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
DEFAULT_USE_SSL,
|
|
||||||
DEFAULT_VERIFY_SSL,
|
DEFAULT_VERIFY_SSL,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
ENTITY_CLASS,
|
ENTITY_CLASS,
|
||||||
@ -83,26 +78,8 @@ from .const import (
|
|||||||
EntityInfo,
|
EntityInfo,
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
{
|
|
||||||
vol.Required(CONF_HOST): cv.string,
|
|
||||||
vol.Optional(CONF_PORT): cv.port,
|
|
||||||
vol.Optional(CONF_SSL, default=DEFAULT_USE_SSL): cv.boolean,
|
|
||||||
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Optional(CONF_DISKS): cv.ensure_list,
|
|
||||||
vol.Optional(CONF_VOLUMES): cv.ensure_list,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
|
||||||
vol.All(
|
|
||||||
cv.deprecated(DOMAIN),
|
|
||||||
{DOMAIN: vol.Schema(vol.All(cv.ensure_list, [CONFIG_SCHEMA]))},
|
|
||||||
),
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Synology"
|
ATTRIBUTION = "Data provided by Synology"
|
||||||
|
|
||||||
@ -110,25 +87,6 @@ ATTRIBUTION = "Data provided by Synology"
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
||||||
"""Set up Synology DSM sensors from legacy config file."""
|
|
||||||
|
|
||||||
conf = config.get(DOMAIN)
|
|
||||||
if conf is None:
|
|
||||||
return True
|
|
||||||
|
|
||||||
for dsm_conf in conf:
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=dsm_conf,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry( # noqa: C901
|
async def async_setup_entry( # noqa: C901
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
@ -227,12 +227,6 @@ class SynologyDSMFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self.context["title_placeholders"] = self.discovered_conf
|
self.context["title_placeholders"] = self.discovered_conf
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
async def async_step_import(
|
|
||||||
self, user_input: dict[str, Any] | None = None
|
|
||||||
) -> FlowResult:
|
|
||||||
"""Import a config entry."""
|
|
||||||
return await self.async_step_user(user_input)
|
|
||||||
|
|
||||||
async def async_step_link(self, user_input: dict[str, Any]) -> FlowResult:
|
async def async_step_link(self, user_input: dict[str, Any]) -> FlowResult:
|
||||||
"""Link a config entry from discovery."""
|
"""Link a config entry from discovery."""
|
||||||
return await self.async_step_user(user_input)
|
return await self.async_step_user(user_input)
|
||||||
|
@ -23,7 +23,7 @@ from homeassistant.components.synology_dsm.const import (
|
|||||||
DEFAULT_VERIFY_SSL,
|
DEFAULT_VERIFY_SSL,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_DISKS,
|
CONF_DISKS,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -41,7 +41,6 @@ from homeassistant.core import HomeAssistant
|
|||||||
from .consts import (
|
from .consts import (
|
||||||
DEVICE_TOKEN,
|
DEVICE_TOKEN,
|
||||||
HOST,
|
HOST,
|
||||||
HOST_2,
|
|
||||||
MACS,
|
MACS,
|
||||||
PASSWORD,
|
PASSWORD,
|
||||||
PORT,
|
PORT,
|
||||||
@ -256,59 +255,6 @@ async def test_user_vdsm(hass: HomeAssistant, service_vdsm: MagicMock):
|
|||||||
assert result["data"].get(CONF_VOLUMES) is None
|
assert result["data"].get(CONF_VOLUMES) is None
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass: HomeAssistant, service: MagicMock):
|
|
||||||
"""Test import step."""
|
|
||||||
# import with minimum setup
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
|
||||||
)
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["result"].unique_id == SERIAL
|
|
||||||
assert result["title"] == HOST
|
|
||||||
assert result["data"][CONF_HOST] == HOST
|
|
||||||
assert result["data"][CONF_PORT] == DEFAULT_PORT_SSL
|
|
||||||
assert result["data"][CONF_SSL] == DEFAULT_USE_SSL
|
|
||||||
assert result["data"][CONF_VERIFY_SSL] == DEFAULT_VERIFY_SSL
|
|
||||||
assert result["data"][CONF_USERNAME] == USERNAME
|
|
||||||
assert result["data"][CONF_PASSWORD] == PASSWORD
|
|
||||||
assert result["data"][CONF_MAC] == MACS
|
|
||||||
assert result["data"].get("device_token") is None
|
|
||||||
assert result["data"].get(CONF_DISKS) is None
|
|
||||||
assert result["data"].get(CONF_VOLUMES) is None
|
|
||||||
|
|
||||||
service.return_value.information.serial = SERIAL_2
|
|
||||||
# import with all
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_HOST: HOST_2,
|
|
||||||
CONF_PORT: PORT,
|
|
||||||
CONF_SSL: USE_SSL,
|
|
||||||
CONF_VERIFY_SSL: VERIFY_SSL,
|
|
||||||
CONF_USERNAME: USERNAME,
|
|
||||||
CONF_PASSWORD: PASSWORD,
|
|
||||||
CONF_DISKS: ["sda", "sdb", "sdc"],
|
|
||||||
CONF_VOLUMES: ["volume_1"],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["result"].unique_id == SERIAL_2
|
|
||||||
assert result["title"] == HOST_2
|
|
||||||
assert result["data"][CONF_HOST] == HOST_2
|
|
||||||
assert result["data"][CONF_PORT] == PORT
|
|
||||||
assert result["data"][CONF_SSL] == USE_SSL
|
|
||||||
assert result["data"][CONF_VERIFY_SSL] == VERIFY_SSL
|
|
||||||
assert result["data"][CONF_USERNAME] == USERNAME
|
|
||||||
assert result["data"][CONF_PASSWORD] == PASSWORD
|
|
||||||
assert result["data"][CONF_MAC] == MACS
|
|
||||||
assert result["data"].get("device_token") is None
|
|
||||||
assert result["data"][CONF_DISKS] == ["sda", "sdb", "sdc"]
|
|
||||||
assert result["data"][CONF_VOLUMES] == ["volume_1"]
|
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_already_setup(hass: HomeAssistant, service: MagicMock):
|
async def test_abort_if_already_setup(hass: HomeAssistant, service: MagicMock):
|
||||||
"""Test we abort if the account is already setup."""
|
"""Test we abort if the account is already setup."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
@ -317,15 +263,6 @@ async def test_abort_if_already_setup(hass: HomeAssistant, service: MagicMock):
|
|||||||
unique_id=SERIAL,
|
unique_id=SERIAL,
|
||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
|
||||||
# Should fail, same HOST:PORT (import)
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
|
||||||
)
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
# Should fail, same HOST:PORT (flow)
|
# Should fail, same HOST:PORT (flow)
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user