mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Remove YAML support from nut (#45276)
This commit is contained in:
parent
8e0addd216
commit
c621c0fa5d
@ -136,22 +136,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
}
|
}
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
async def async_step_import(self, user_input=None):
|
|
||||||
"""Handle the import."""
|
|
||||||
errors = {}
|
|
||||||
if user_input is not None:
|
|
||||||
if self._host_port_alias_already_configured(user_input):
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
_, errors = await self._async_validate_or_error(user_input)
|
|
||||||
|
|
||||||
if not errors:
|
|
||||||
title = _format_host_port_alias(user_input)
|
|
||||||
return self.async_create_entry(title=title, data=user_input)
|
|
||||||
|
|
||||||
return self.async_show_form(
|
|
||||||
step_id="user", data_schema=_base_schema({}), errors=errors
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle the user input."""
|
"""Handle the user input."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
@ -1,29 +1,11 @@
|
|||||||
"""Provides a sensor to track various status aspects of a UPS."""
|
"""Provides a sensor to track various status aspects of a UPS."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
from homeassistant.const import ATTR_STATE, CONF_RESOURCES, STATE_UNKNOWN
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT
|
|
||||||
from homeassistant.const import (
|
|
||||||
ATTR_STATE,
|
|
||||||
CONF_ALIAS,
|
|
||||||
CONF_HOST,
|
|
||||||
CONF_NAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_PORT,
|
|
||||||
CONF_RESOURCES,
|
|
||||||
CONF_USERNAME,
|
|
||||||
STATE_UNKNOWN,
|
|
||||||
)
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
COORDINATOR,
|
COORDINATOR,
|
||||||
DEFAULT_HOST,
|
|
||||||
DEFAULT_NAME,
|
|
||||||
DEFAULT_PORT,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KEY_STATUS,
|
KEY_STATUS,
|
||||||
KEY_STATUS_DISPLAY,
|
KEY_STATUS_DISPLAY,
|
||||||
@ -44,29 +26,6 @@ from .const import (
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
|
||||||
vol.Optional(CONF_ALIAS): cv.string,
|
|
||||||
vol.Optional(CONF_USERNAME): cv.string,
|
|
||||||
vol.Optional(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Required(CONF_RESOURCES): vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
|
||||||
"""Import the platform into a config entry."""
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up the NUT sensors."""
|
"""Set up the NUT sensors."""
|
||||||
|
|
||||||
|
@ -212,15 +212,41 @@ async def test_form_user_multiple_ups(hass):
|
|||||||
assert len(mock_setup_entry.mock_calls) == 2
|
assert len(mock_setup_entry.mock_calls) == 2
|
||||||
|
|
||||||
|
|
||||||
async def test_form_import(hass):
|
async def test_form_user_one_ups_with_ignored_entry(hass):
|
||||||
"""Test we get the form with import source."""
|
"""Test we can setup a new one when there is an ignored one."""
|
||||||
|
ignored_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE
|
||||||
|
)
|
||||||
|
ignored_entry.add_to_hass(hass)
|
||||||
|
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
mock_pynut = _get_mock_pynutclient(
|
mock_pynut = _get_mock_pynutclient(
|
||||||
list_vars={"battery.voltage": "serial"},
|
list_vars={"battery.voltage": "voltage", "ups.status": "OL"}, list_ups=["ups1"]
|
||||||
list_ups={"ups1": "UPS 1", "ups2": "UPS2"},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.nut.PyNUTClient",
|
||||||
|
return_value=mock_pynut,
|
||||||
|
):
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{
|
||||||
|
"host": "1.1.1.1",
|
||||||
|
"username": "test-username",
|
||||||
|
"password": "test-password",
|
||||||
|
"port": 2222,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result2["step_id"] == "resources"
|
||||||
|
assert result2["type"] == "form"
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.nut.PyNUTClient",
|
"homeassistant.components.nut.PyNUTClient",
|
||||||
return_value=mock_pynut,
|
return_value=mock_pynut,
|
||||||
@ -230,62 +256,25 @@ async def test_form_import(hass):
|
|||||||
"homeassistant.components.nut.async_setup_entry",
|
"homeassistant.components.nut.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
result = await hass.config_entries.flow.async_init(
|
result3 = await hass.config_entries.flow.async_configure(
|
||||||
DOMAIN,
|
result2["flow_id"],
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
{"resources": ["battery.voltage", "ups.status", "ups.status.display"]},
|
||||||
data={
|
|
||||||
"host": "localhost",
|
|
||||||
"port": 123,
|
|
||||||
"name": "name",
|
|
||||||
"resources": ["battery.charge"],
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
assert result3["type"] == "create_entry"
|
||||||
assert result["title"] == "localhost:123"
|
assert result3["title"] == "1.1.1.1:2222"
|
||||||
assert result["data"] == {
|
assert result3["data"] == {
|
||||||
"host": "localhost",
|
"host": "1.1.1.1",
|
||||||
"port": 123,
|
"password": "test-password",
|
||||||
"name": "name",
|
"port": 2222,
|
||||||
"resources": ["battery.charge"],
|
"resources": ["battery.voltage", "ups.status", "ups.status.display"],
|
||||||
|
"username": "test-username",
|
||||||
}
|
}
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_import_dupe(hass):
|
|
||||||
"""Test we get abort on duplicate import."""
|
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
|
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=VALID_CONFIG)
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=VALID_CONFIG
|
|
||||||
)
|
|
||||||
assert result["type"] == "abort"
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_form_import_with_ignored_entry(hass):
|
|
||||||
"""Test we get abort on duplicate import when there is an ignored one."""
|
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
|
|
||||||
entry = MockConfigEntry(domain=DOMAIN, data=VALID_CONFIG)
|
|
||||||
entry.add_to_hass(hass)
|
|
||||||
ignored_entry = MockConfigEntry(
|
|
||||||
domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE
|
|
||||||
)
|
|
||||||
ignored_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=VALID_CONFIG
|
|
||||||
)
|
|
||||||
assert result["type"] == "abort"
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass):
|
async def test_form_cannot_connect(hass):
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user