mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 21:19:16 +00:00
Remove deprecated yaml import from OTP integration (#134196)
This commit is contained in:
parent
af97bf1c5f
commit
df38c1b1d7
@ -82,17 +82,6 @@ class TOTPConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
|
||||||
"""Import config from yaml."""
|
|
||||||
|
|
||||||
await self.async_set_unique_id(import_data[CONF_TOKEN])
|
|
||||||
self._abort_if_unique_id_configured()
|
|
||||||
|
|
||||||
return self.async_create_entry(
|
|
||||||
title=import_data.get(CONF_NAME, DEFAULT_NAME),
|
|
||||||
data=import_data,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_step_confirm(
|
async def async_step_confirm(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
|
@ -5,59 +5,20 @@ from __future__ import annotations
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import pyotp
|
import pyotp
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import SensorEntity
|
||||||
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
|
from homeassistant.config_entries import ConfigEntry
|
||||||
SensorEntity,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_TOKEN
|
from homeassistant.const import CONF_NAME, CONF_TOKEN
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
|
||||||
|
|
||||||
from .const import DEFAULT_NAME, DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
TIME_STEP = 30 # Default time step assumed by Google Authenticator
|
TIME_STEP = 30 # Default time step assumed by Google Authenticator
|
||||||
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_TOKEN): cv.string,
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the OTP sensor."""
|
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
HOMEASSISTANT_DOMAIN,
|
|
||||||
f"deprecated_yaml_{DOMAIN}",
|
|
||||||
is_fixable=False,
|
|
||||||
breaks_in_ha_version="2025.1.0",
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key="deprecated_yaml",
|
|
||||||
translation_placeholders={
|
|
||||||
"domain": DOMAIN,
|
|
||||||
"integration_title": "One-Time Password (OTP)",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -6,9 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.otp.const import DOMAIN
|
from homeassistant.components.otp.const import DOMAIN
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.const import CONF_NAME, CONF_TOKEN
|
||||||
from homeassistant.const import CONF_NAME, CONF_PLATFORM, CONF_TOKEN
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -51,15 +49,3 @@ def mock_otp_config_entry() -> MockConfigEntry:
|
|||||||
},
|
},
|
||||||
unique_id="2FX5FBSYRE6VEC2FSHBQCRKO2GNDVZ52",
|
unique_id="2FX5FBSYRE6VEC2FSHBQCRKO2GNDVZ52",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="otp_yaml_config")
|
|
||||||
def mock_otp_yaml_config() -> ConfigType:
|
|
||||||
"""Mock otp configuration entry."""
|
|
||||||
return {
|
|
||||||
SENSOR_DOMAIN: {
|
|
||||||
CONF_PLATFORM: "otp",
|
|
||||||
CONF_TOKEN: "2FX5FBSYRE6VEC2FSHBQCRKO2GNDVZ52",
|
|
||||||
CONF_NAME: "OTP Sensor",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.otp.const import CONF_NEW_TOKEN, DOMAIN
|
from homeassistant.components.otp.const import CONF_NEW_TOKEN, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_CODE, CONF_NAME, CONF_TOKEN
|
from homeassistant.const import CONF_CODE, CONF_NAME, CONF_TOKEN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -97,22 +97,6 @@ async def test_errors_and_recover(
|
|||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_pyotp", "mock_setup_entry")
|
|
||||||
async def test_flow_import(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that we can import a YAML config."""
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=TEST_DATA_RESULT,
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == "OTP Sensor"
|
|
||||||
assert result["data"] == TEST_DATA_RESULT
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_pyotp")
|
@pytest.mark.usefixtures("mock_pyotp")
|
||||||
async def test_generate_new_token(
|
async def test_generate_new_token(
|
||||||
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
hass: HomeAssistant, mock_setup_entry: AsyncMock
|
||||||
|
@ -3,12 +3,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.otp.const import DOMAIN
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
|
||||||
from homeassistant.helpers import issue_registry as ir
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -26,16 +21,3 @@ async def test_setup(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("sensor.otp_sensor") == snapshot
|
assert hass.states.get("sensor.otp_sensor") == snapshot
|
||||||
|
|
||||||
|
|
||||||
async def test_deprecated_yaml_issue(
|
|
||||||
hass: HomeAssistant, issue_registry: ir.IssueRegistry, otp_yaml_config: ConfigType
|
|
||||||
) -> None:
|
|
||||||
"""Test an issue is created when attempting setup from yaml config."""
|
|
||||||
|
|
||||||
assert await async_setup_component(hass, SENSOR_DOMAIN, otp_yaml_config)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert issue_registry.async_get_issue(
|
|
||||||
domain=HOMEASSISTANT_DOMAIN, issue_id=f"deprecated_yaml_{DOMAIN}"
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user