From af9ee8bc4a2acc69e412c2c6548ca0fba7626f75 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Fri, 26 May 2023 08:41:21 +0200 Subject: [PATCH] Remove obihai YAMl configuration (#93549) --- .../components/obihai/config_flow.py | 27 +--------- homeassistant/components/obihai/sensor.py | 49 ++----------------- homeassistant/components/obihai/strings.json | 6 --- tests/components/obihai/test_config_flow.py | 48 ------------------ 4 files changed, 4 insertions(+), 126 deletions(-) diff --git a/homeassistant/components/obihai/config_flow.py b/homeassistant/components/obihai/config_flow.py index 6216fe0b973..ce5cca6a7a4 100644 --- a/homeassistant/components/obihai/config_flow.py +++ b/homeassistant/components/obihai/config_flow.py @@ -10,7 +10,7 @@ import voluptuous as vol from homeassistant.components import dhcp from homeassistant.config_entries import ConfigFlow -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME +from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult @@ -135,28 +135,3 @@ class ObihaiFlowHandler(ConfigFlow, domain=DOMAIN): ) return await self.async_step_user(user_input=user_input) - - # DEPRECATED - async def async_step_import(self, config: dict[str, Any]) -> FlowResult: - """Handle a flow initialized by importing a config.""" - - try: - _ = await self.hass.async_add_executor_job(gethostbyname, config[CONF_HOST]) - except gaierror: - return self.async_abort(reason="cannot_connect") - - if pyobihai := await async_validate_creds(self.hass, config): - device_mac = await self.hass.async_add_executor_job(pyobihai.get_device_mac) - await self.async_set_unique_id(device_mac) - self._abort_if_unique_id_configured() - - return self.async_create_entry( - title=config.get(CONF_NAME, config[CONF_HOST]), - data={ - CONF_HOST: config[CONF_HOST], - CONF_PASSWORD: config[CONF_PASSWORD], - CONF_USERNAME: config[CONF_USERNAME], - }, - ) - - return self.async_abort(reason="invalid_auth") diff --git a/homeassistant/components/obihai/sensor.py b/homeassistant/components/obihai/sensor.py index 61411b0ce27..b838d0ec92b 100644 --- a/homeassistant/components/obihai/sensor.py +++ b/homeassistant/components/obihai/sensor.py @@ -4,61 +4,18 @@ from __future__ import annotations from datetime import timedelta from pyobihai import PyObihai -import voluptuous as vol -from homeassistant.components.sensor import ( - PLATFORM_SCHEMA, - SensorDeviceClass, - SensorEntity, -) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant -from homeassistant.helpers import issue_registry as ir -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from .connectivity import ObihaiConnection -from .const import DEFAULT_PASSWORD, DEFAULT_USERNAME, DOMAIN, OBIHAI +from .const import OBIHAI SCAN_INTERVAL = timedelta(seconds=5) -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_HOST): cv.string, - vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string, - vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string, - } -) - - -# DEPRECATED -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Obihai sensor platform.""" - ir.async_create_issue( - hass, - DOMAIN, - "manual_migration", - breaks_in_ha_version="2023.6.0", - is_fixable=False, - severity=ir.IssueSeverity.WARNING, - translation_key="manual_migration", - ) - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config, - ) - ) - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback diff --git a/homeassistant/components/obihai/strings.json b/homeassistant/components/obihai/strings.json index 1b91cd60654..823bc2e1b8d 100644 --- a/homeassistant/components/obihai/strings.json +++ b/homeassistant/components/obihai/strings.json @@ -24,11 +24,5 @@ "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } - }, - "issues": { - "manual_migration": { - "title": "Obihai YAML configuration is being removed", - "description": "Configuration of the Obihai platform in YAML is deprecated and will be removed in Home Assistant 2023.6; Your existing configuration has been imported into the UI automatically and can be safely removed from your configuration.yaml file." - } } } diff --git a/tests/components/obihai/test_config_flow.py b/tests/components/obihai/test_config_flow.py index 1743b81a0e9..d9ca52424c2 100644 --- a/tests/components/obihai/test_config_flow.py +++ b/tests/components/obihai/test_config_flow.py @@ -78,54 +78,6 @@ async def test_connect_failure(hass: HomeAssistant, mock_gaierror: Generator) -> assert result["errors"]["base"] == "cannot_connect" -async def test_yaml_import(hass: HomeAssistant) -> None: - """Test we get the YAML imported.""" - - with patch(VALIDATE_AUTH_PATCH, return_value=MockPyObihai()): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=USER_INPUT, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.CREATE_ENTRY - assert "errors" not in result - - -async def test_yaml_import_auth_fail(hass: HomeAssistant) -> None: - """Test the YAML import fails.""" - - with patch(VALIDATE_AUTH_PATCH, return_value=False): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=USER_INPUT, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "invalid_auth" - assert "errors" not in result - - -async def test_yaml_import_connect_fail( - hass: HomeAssistant, mock_gaierror: Generator -) -> None: - """Test the YAML import fails with invalid host.""" - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=USER_INPUT, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "cannot_connect" - assert "errors" not in result - - async def test_dhcp_flow(hass: HomeAssistant) -> None: """Test that DHCP discovery works."""