Remove deprecated YAML configuration from Epson (#55045)
parent
03bda6ed15
commit
f72bf2145b
|
@ -25,30 +25,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_import(self, import_config):
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
for entry in self._async_current_entries(include_ignore=True):
|
||||
if import_config[CONF_HOST] == entry.data[CONF_HOST]:
|
||||
return self.async_abort(reason="already_configured")
|
||||
try:
|
||||
projector = await validate_projector(
|
||||
hass=self.hass,
|
||||
host=import_config[CONF_HOST],
|
||||
check_power=True,
|
||||
check_powered_on=False,
|
||||
)
|
||||
except CannotConnect:
|
||||
_LOGGER.warning("Cannot connect to projector")
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
|
||||
serial_no = await projector.get_serial_number()
|
||||
await self.async_set_unique_id(serial_no)
|
||||
self._abort_if_unique_id_configured()
|
||||
import_config.pop(CONF_PORT, None)
|
||||
return self.async_create_entry(
|
||||
title=import_config.pop(CONF_NAME), data=import_config
|
||||
)
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle the initial step."""
|
||||
errors = {}
|
||||
|
|
|
@ -4,5 +4,4 @@ DOMAIN = "epson"
|
|||
SERVICE_SELECT_CMODE = "select_cmode"
|
||||
|
||||
ATTR_CMODE = "cmode"
|
||||
DEFAULT_NAME = "EPSON Projector"
|
||||
HTTP = "http"
|
||||
|
|
|
@ -26,7 +26,7 @@ from epson_projector.const import (
|
|||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
|
||||
from homeassistant.components.media_player import MediaPlayerEntity
|
||||
from homeassistant.components.media_player.const import (
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PREVIOUS_TRACK,
|
||||
|
@ -36,13 +36,12 @@ from homeassistant.components.media_player.const import (
|
|||
SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
|
||||
|
||||
from .const import ATTR_CMODE, DEFAULT_NAME, DOMAIN, SERVICE_SELECT_CMODE
|
||||
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -56,14 +55,6 @@ SUPPORT_EPSON = (
|
|||
| SUPPORT_PREVIOUS_TRACK
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PORT, default=80): cv.port,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Epson projector from a config entry."""
|
||||
|
@ -85,19 +76,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Epson projector."""
|
||||
_LOGGER.warning(
|
||||
"Loading Espon projector via platform setup is deprecated; "
|
||||
"Please remove it from your configuration"
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class EpsonProjectorMediaPlayer(MediaPlayerEntity):
|
||||
"""Representation of Epson Projector Device."""
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ from homeassistant import config_entries, setup
|
|||
from homeassistant.components.epson.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, STATE_UNAVAILABLE
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_form(hass):
|
||||
"""Test we get the form."""
|
||||
|
@ -75,70 +73,3 @@ async def test_form_powered_off(hass):
|
|||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "powered_off"}
|
||||
|
||||
|
||||
async def test_import(hass):
|
||||
"""Test config.yaml import."""
|
||||
with patch(
|
||||
"homeassistant.components.epson.Projector.get_power",
|
||||
return_value="01",
|
||||
), patch(
|
||||
"homeassistant.components.epson.Projector.get_property",
|
||||
return_value="04",
|
||||
), patch(
|
||||
"homeassistant.components.epson.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_HOST: "1.1.1.1", CONF_NAME: "test-epson"},
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "test-epson"
|
||||
assert result["data"] == {CONF_HOST: "1.1.1.1"}
|
||||
|
||||
|
||||
async def test_already_imported(hass):
|
||||
"""Test config.yaml imported twice."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
source=config_entries.SOURCE_IMPORT,
|
||||
unique_id="bla",
|
||||
title="test-epson",
|
||||
data={CONF_HOST: "1.1.1.1"},
|
||||
).add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.epson.Projector.get_power",
|
||||
return_value="01",
|
||||
), patch(
|
||||
"homeassistant.components.epson.Projector.get_property",
|
||||
return_value="04",
|
||||
), patch(
|
||||
"homeassistant.components.epson.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_HOST: "1.1.1.1", CONF_NAME: "test-epson"},
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_import_cannot_connect(hass):
|
||||
"""Test we handle cannot connect error."""
|
||||
with patch(
|
||||
"homeassistant.components.epson.Projector.get_power",
|
||||
return_value=STATE_UNAVAILABLE,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_HOST: "1.1.1.1", CONF_NAME: "test-epson"},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
|
Loading…
Reference in New Issue