Remove obihai YAMl configuration (#93549)

This commit is contained in:
G Johansson 2023-05-26 08:41:21 +02:00 committed by GitHub
parent 1f467fcc6a
commit af9ee8bc4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 126 deletions

View file

@ -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")

View file

@ -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

View file

@ -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."
}
}
}

View file

@ -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."""