Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated yaml import from OTP integration #134196

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions homeassistant/components/otp/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ async def async_step_user(
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(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
Expand Down
49 changes: 5 additions & 44 deletions homeassistant/components/otp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,20 @@
import time

import pyotp
import voluptuous as vol

from homeassistant.components.sensor import (
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
SensorEntity,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, CONF_TOKEN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
from homeassistant.helpers.typing import StateType

from .const import DEFAULT_NAME, DOMAIN
from .const import DOMAIN

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(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
Expand Down
16 changes: 1 addition & 15 deletions tests/components/otp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import pytest

from homeassistant.components.otp.const import DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import CONF_NAME, CONF_PLATFORM, CONF_TOKEN
from homeassistant.helpers.typing import ConfigType
from homeassistant.const import CONF_NAME, CONF_TOKEN

from tests.common import MockConfigEntry

Expand Down Expand Up @@ -51,15 +49,3 @@ def mock_otp_config_entry() -> MockConfigEntry:
},
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",
}
}
18 changes: 1 addition & 17 deletions tests/components/otp/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

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.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
Expand Down Expand Up @@ -97,22 +97,6 @@ async def test_errors_and_recover(
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")
async def test_generate_new_token(
hass: HomeAssistant, mock_setup_entry: AsyncMock
Expand Down
20 changes: 1 addition & 19 deletions tests/components/otp/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import pytest
from syrupy.assertion import SnapshotAssertion

from homeassistant.components.otp.const import DOMAIN
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 homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry

Expand All @@ -26,16 +21,3 @@ async def test_setup(
await hass.async_block_till_done()

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