Remove deprecated yaml config from Awair (#68572)
parent
df6cc94b25
commit
bcfd9eeff2
|
@ -17,23 +17,6 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_import(self, conf: dict):
|
||||
"""Import a configuration from config.yaml."""
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="already_setup")
|
||||
|
||||
user, error = await self._check_connection(conf[CONF_ACCESS_TOKEN])
|
||||
if error is not None:
|
||||
return self.async_abort(reason=error)
|
||||
|
||||
await self.async_set_unique_id(user.email)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(
|
||||
title=f"{user.email} ({user.user_id})",
|
||||
data={CONF_ACCESS_TOKEN: conf[CONF_ACCESS_TOKEN]},
|
||||
)
|
||||
|
||||
async def async_step_user(self, user_input: dict | None = None):
|
||||
"""Handle a flow initialized by the user."""
|
||||
errors = {}
|
||||
|
|
|
@ -3,22 +3,14 @@ from __future__ import annotations
|
|||
|
||||
from python_awair.air_data import AirData
|
||||
from python_awair.devices import AwairDevice
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_CONNECTIONS,
|
||||
ATTR_NAME,
|
||||
CONF_ACCESS_TOKEN,
|
||||
)
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_CONNECTIONS, ATTR_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import AwairDataUpdateCoordinator, AwairResult
|
||||
|
@ -31,37 +23,12 @@ from .const import (
|
|||
ATTRIBUTION,
|
||||
DOMAIN,
|
||||
DUST_ALIASES,
|
||||
LOGGER,
|
||||
SENSOR_TYPE_SCORE,
|
||||
SENSOR_TYPES,
|
||||
SENSOR_TYPES_DUST,
|
||||
AwairSensorEntityDescription,
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{vol.Required(CONF_ACCESS_TOKEN): cv.string},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Import Awair configuration from YAML."""
|
||||
LOGGER.warning(
|
||||
"Loading Awair 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,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -6,7 +6,7 @@ from python_awair.exceptions import AuthError, AwairError
|
|||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.awair.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
|
||||
from .const import CONFIG, DEVICES_FIXTURE, NO_DEVICES_FIXTURE, UNIQUE_ID, USER_FIXTURE
|
||||
|
@ -82,64 +82,6 @@ async def test_no_devices_error(hass):
|
|||
assert result["reason"] == "no_devices_found"
|
||||
|
||||
|
||||
async def test_import(hass):
|
||||
"""Test config.yaml import."""
|
||||
|
||||
with patch(
|
||||
"python_awair.AwairClient.query", side_effect=[USER_FIXTURE, DEVICES_FIXTURE]
|
||||
), patch(
|
||||
"homeassistant.components.awair.sensor.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_ACCESS_TOKEN: CONFIG[CONF_ACCESS_TOKEN]},
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "foo@bar.com (32406)"
|
||||
assert result["data"][CONF_ACCESS_TOKEN] == CONFIG[CONF_ACCESS_TOKEN]
|
||||
assert result["result"].unique_id == UNIQUE_ID
|
||||
|
||||
|
||||
async def test_import_aborts_on_api_error(hass):
|
||||
"""Test config.yaml imports on api error."""
|
||||
|
||||
with patch("python_awair.AwairClient.query", side_effect=AwairError()):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_ACCESS_TOKEN: CONFIG[CONF_ACCESS_TOKEN]},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_import_aborts_if_configured(hass):
|
||||
"""Test config import doesn't re-import unnecessarily."""
|
||||
|
||||
with patch(
|
||||
"python_awair.AwairClient.query", side_effect=[USER_FIXTURE, DEVICES_FIXTURE]
|
||||
), patch(
|
||||
"homeassistant.components.awair.sensor.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
MockConfigEntry(domain=DOMAIN, unique_id=UNIQUE_ID, data=CONFIG).add_to_hass(
|
||||
hass
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_ACCESS_TOKEN: CONFIG[CONF_ACCESS_TOKEN]},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_setup"
|
||||
|
||||
|
||||
async def test_reauth(hass):
|
||||
"""Test reauth flow."""
|
||||
with patch(
|
||||
|
|
Loading…
Reference in New Issue