Add config flow to One-Time Password (OTP) integration (#118493)
This commit is contained in:
parent
60ba80a28d
commit
1eb8b5a27c
14 changed files with 393 additions and 7 deletions
|
@ -8,13 +8,15 @@ import pyotp
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
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
|
||||
|
||||
DEFAULT_NAME = "OTP Sensor"
|
||||
from .const import DEFAULT_NAME, DOMAIN
|
||||
|
||||
TIME_STEP = 30 # Default time step assumed by Google Authenticator
|
||||
|
||||
|
@ -34,10 +36,32 @@ async def async_setup_platform(
|
|||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the OTP sensor."""
|
||||
name = config[CONF_NAME]
|
||||
token = config[CONF_TOKEN]
|
||||
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_add_entities([TOTPSensor(name, token)], True)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the OTP sensor."""
|
||||
|
||||
async_add_entities(
|
||||
[TOTPSensor(entry.data[CONF_NAME], entry.data[CONF_TOKEN])], True
|
||||
)
|
||||
|
||||
|
||||
# Only TOTP supported at the moment, HOTP might be added later
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue