Skip to content

Commit

Permalink
Remove obihai YAMl configuration (#93549)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed May 26, 2023
1 parent 1f467fc commit af9ee8b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 127 deletions.
27 changes: 1 addition & 26 deletions homeassistant/components/obihai/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

Expand Down Expand Up @@ -135,28 +135,3 @@ async def async_step_dhcp_confirm(
)

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")
51 changes: 4 additions & 47 deletions homeassistant/components/obihai/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,18 @@
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
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/obihai/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
}
48 changes: 0 additions & 48 deletions tests/components/obihai/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down

0 comments on commit af9ee8b

Please sign in to comment.