mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Cleanup netgear platform schema (#63873)
* Cleanup netgear platform schema * Cleanup config_flow * Cleanup tests * Cleanup CONF_APS constant * Cleanup tests (take 2) Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
bb765803dc
commit
0793445c40
@ -119,10 +119,6 @@ class NetgearFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
description_placeholders=self.placeholders,
|
||||
)
|
||||
|
||||
async def async_step_import(self, user_input=None):
|
||||
"""Import a config entry."""
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||
"""Initialize flow from ssdp."""
|
||||
updated_data = {}
|
||||
|
@ -3,25 +3,10 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import (
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
SOURCE_TYPE_ROUTER,
|
||||
)
|
||||
from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER
|
||||
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICES,
|
||||
CONF_EXCLUDE,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DEVICE_ICONS
|
||||
@ -29,21 +14,6 @@ from .router import NetgearDeviceEntity, NetgearRouter, async_setup_netgear_entr
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_APS = "accesspoints"
|
||||
|
||||
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_SSL): cv.boolean,
|
||||
vol.Optional(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_PORT): cv.port,
|
||||
vol.Optional(CONF_DEVICES, default=[]): vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(CONF_EXCLUDE, default=[]): vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(CONF_APS, default=[]): vol.All(cv.ensure_list, [cv.string]),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -1,13 +1,13 @@
|
||||
"""Tests for the Netgear config flow."""
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from pynetgear import DEFAULT_HOST, DEFAULT_PORT, DEFAULT_USER
|
||||
from pynetgear import DEFAULT_USER
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components import ssdp
|
||||
from homeassistant.components.netgear.const import CONF_CONSIDER_HOME, DOMAIN, PORT_80
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_SSDP, SOURCE_USER
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
@ -102,72 +102,6 @@ async def test_user(hass, service):
|
||||
assert result["data"][CONF_PASSWORD] == PASSWORD
|
||||
|
||||
|
||||
async def test_import_required(hass, service):
|
||||
"""Test import step, with required config only."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_PASSWORD: PASSWORD}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["result"].unique_id == SERIAL
|
||||
assert result["title"] == TITLE
|
||||
assert result["data"].get(CONF_HOST) == DEFAULT_HOST
|
||||
assert result["data"].get(CONF_PORT) == DEFAULT_PORT
|
||||
assert result["data"].get(CONF_SSL) is False
|
||||
assert result["data"].get(CONF_USERNAME) == DEFAULT_USER
|
||||
assert result["data"][CONF_PASSWORD] == PASSWORD
|
||||
|
||||
|
||||
async def test_import_required_login_failed(hass, service_failed):
|
||||
"""Test import step, with required config only, while wrong password or connection issue."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_PASSWORD: PASSWORD}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "config"}
|
||||
|
||||
|
||||
async def test_import_all(hass, service):
|
||||
"""Test import step, with all config provided."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: SSL,
|
||||
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"] == TITLE
|
||||
assert result["data"].get(CONF_HOST) == HOST
|
||||
assert result["data"].get(CONF_PORT) == PORT
|
||||
assert result["data"].get(CONF_SSL) == SSL
|
||||
assert result["data"].get(CONF_USERNAME) == USERNAME
|
||||
assert result["data"][CONF_PASSWORD] == PASSWORD
|
||||
|
||||
|
||||
async def test_import_all_connection_failed(hass, service_failed):
|
||||
"""Test import step, with all config provided, while wrong host."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: SSL,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "config"}
|
||||
|
||||
|
||||
async def test_abort_if_already_setup(hass, service):
|
||||
"""Test we abort if the router is already setup."""
|
||||
MockConfigEntry(
|
||||
@ -176,15 +110,6 @@ async def test_abort_if_already_setup(hass, service):
|
||||
unique_id=SERIAL,
|
||||
).add_to_hass(hass)
|
||||
|
||||
# Should fail, same SERIAL (import)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
# Should fail, same SERIAL (flow)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
|
Loading…
x
Reference in New Issue
Block a user