Remove YAML configuration import from Sony Bravia TV (#52141)
This commit is contained in:
parent
74db49fae4
commit
ff8b96c65d
3 changed files with 4 additions and 174 deletions
|
@ -1,6 +1,5 @@
|
|||
"""Adds config flow for Bravia TV integration."""
|
||||
import ipaddress
|
||||
import logging
|
||||
import re
|
||||
|
||||
from bravia_tv import BraviaRC
|
||||
|
@ -22,8 +21,6 @@ from .const import (
|
|||
NICKNAME,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def host_valid(host):
|
||||
"""Return True if hostname or IP address is valid."""
|
||||
|
@ -75,27 +72,6 @@ class BraviaTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Bravia TV options callback."""
|
||||
return BraviaTVOptionsFlowHandler(config_entry)
|
||||
|
||||
async def async_step_import(self, user_input=None):
|
||||
"""Handle configuration by yaml file."""
|
||||
self.host = user_input[CONF_HOST]
|
||||
self.braviarc = BraviaRC(self.host)
|
||||
|
||||
try:
|
||||
await self.init_device(user_input[CONF_PIN])
|
||||
except CannotConnect:
|
||||
_LOGGER.error("Import aborted, cannot connect to %s", self.host)
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except NoIPControl:
|
||||
_LOGGER.error("IP Control is disabled in the TV settings")
|
||||
return self.async_abort(reason="no_ip_control")
|
||||
except ModelNotSupported:
|
||||
_LOGGER.error("Import aborted, your TV is not supported")
|
||||
return self.async_abort(reason="unsupported_model")
|
||||
|
||||
user_input[CONF_MAC] = self.mac
|
||||
|
||||
return self.async_create_entry(title=self.title, data=user_input)
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle the initial step."""
|
||||
errors = {}
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
"""Support for interface with a Bravia TV."""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
DEVICE_CLASS_TV,
|
||||
PLATFORM_SCHEMA,
|
||||
MediaPlayerEntity,
|
||||
)
|
||||
from homeassistant.components.media_player import DEVICE_CLASS_TV, MediaPlayerEntity
|
||||
from homeassistant.components.media_player.const import (
|
||||
SUPPORT_NEXT_TRACK,
|
||||
SUPPORT_PAUSE,
|
||||
|
@ -21,22 +13,10 @@ from homeassistant.components.media_player.const import (
|
|||
SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PIN,
|
||||
STATE_OFF,
|
||||
STATE_PAUSED,
|
||||
STATE_PLAYING,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import STATE_OFF, STATE_PAUSED, STATE_PLAYING
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.json import load_json
|
||||
|
||||
from .const import ATTR_MANUFACTURER, BRAVIA_CONFIG_FILE, DEFAULT_NAME, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .const import ATTR_MANUFACTURER, DEFAULT_NAME, DOMAIN
|
||||
|
||||
SUPPORT_BRAVIA = (
|
||||
SUPPORT_PAUSE
|
||||
|
@ -52,43 +32,6 @@ SUPPORT_BRAVIA = (
|
|||
| SUPPORT_STOP
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Bravia TV platform."""
|
||||
host = config[CONF_HOST]
|
||||
|
||||
bravia_config_file_path = hass.config.path(BRAVIA_CONFIG_FILE)
|
||||
bravia_config = await hass.async_add_executor_job(
|
||||
load_json, bravia_config_file_path
|
||||
)
|
||||
if not bravia_config:
|
||||
_LOGGER.error(
|
||||
"Configuration import failed, there is no bravia.conf file in the configuration folder"
|
||||
)
|
||||
return
|
||||
|
||||
while bravia_config:
|
||||
# Import a configured TV
|
||||
host_ip, host_config = bravia_config.popitem()
|
||||
if host_ip == host:
|
||||
pin = host_config[CONF_PIN]
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_HOST: host, CONF_PIN: pin},
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up Bravia TV Media Player from a config_entry."""
|
||||
|
|
|
@ -5,7 +5,7 @@ from bravia_tv.braviarc import NoIPControl
|
|||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.braviatv.const import CONF_IGNORED_SOURCES, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PIN
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
@ -31,9 +31,6 @@ BRAVIA_SOURCE_LIST = {
|
|||
"AV/Component": "extInput:component?port=1",
|
||||
}
|
||||
|
||||
IMPORT_CONFIG_HOSTNAME = {CONF_HOST: "bravia-host", CONF_PIN: "1234"}
|
||||
IMPORT_CONFIG_IP = {CONF_HOST: "10.10.10.12", CONF_PIN: "1234"}
|
||||
|
||||
|
||||
async def test_show_form(hass):
|
||||
"""Test that the form is served with no input."""
|
||||
|
@ -45,92 +42,6 @@ async def test_show_form(hass):
|
|||
assert result["step_id"] == SOURCE_USER
|
||||
|
||||
|
||||
async def test_import(hass):
|
||||
"""Test that the import works."""
|
||||
with patch("bravia_tv.BraviaRC.connect", return_value=True), patch(
|
||||
"bravia_tv.BraviaRC.is_connected", return_value=True
|
||||
), patch(
|
||||
"bravia_tv.BraviaRC.get_system_info", return_value=BRAVIA_SYSTEM_INFO
|
||||
), patch(
|
||||
"homeassistant.components.braviatv.async_setup_entry", return_value=True
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=IMPORT_CONFIG_HOSTNAME
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["result"].unique_id == "very_unique_string"
|
||||
assert result["title"] == "TV-Model"
|
||||
assert result["data"] == {
|
||||
CONF_HOST: "bravia-host",
|
||||
CONF_PIN: "1234",
|
||||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
}
|
||||
|
||||
|
||||
async def test_import_cannot_connect(hass):
|
||||
"""Test that errors are shown when cannot connect to the host during import."""
|
||||
with patch("bravia_tv.BraviaRC.connect", return_value=True), patch(
|
||||
"bravia_tv.BraviaRC.is_connected", return_value=False
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=IMPORT_CONFIG_HOSTNAME
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_import_model_unsupported(hass):
|
||||
"""Test that errors are shown when the TV is not supported during import."""
|
||||
with patch("bravia_tv.BraviaRC.connect", return_value=True), patch(
|
||||
"bravia_tv.BraviaRC.is_connected", return_value=True
|
||||
), patch("bravia_tv.BraviaRC.get_system_info", return_value={}):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=IMPORT_CONFIG_IP
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "unsupported_model"
|
||||
|
||||
|
||||
async def test_import_no_ip_control(hass):
|
||||
"""Test that errors are shown when IP Control is disabled on the TV during import."""
|
||||
with patch("bravia_tv.BraviaRC.connect", side_effect=NoIPControl("No IP Control")):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=IMPORT_CONFIG_IP
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "no_ip_control"
|
||||
|
||||
|
||||
async def test_import_duplicate_error(hass):
|
||||
"""Test that errors are shown when duplicates are added during import."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="very_unique_string",
|
||||
data={
|
||||
CONF_HOST: "bravia-host",
|
||||
CONF_PIN: "1234",
|
||||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
},
|
||||
title="TV-Model",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch("bravia_tv.BraviaRC.connect", return_value=True), patch(
|
||||
"bravia_tv.BraviaRC.is_connected", return_value=True
|
||||
), patch("bravia_tv.BraviaRC.get_system_info", return_value=BRAVIA_SYSTEM_INFO):
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=IMPORT_CONFIG_HOSTNAME
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_user_invalid_host(hass):
|
||||
"""Test that errors are shown when the host is invalid."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
|
Loading…
Add table
Reference in a new issue