1 """Support for One-Time Password (OTP)."""
3 from __future__
import annotations
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
23 from .const
import DEFAULT_NAME, DOMAIN
28 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
30 vol.Required(CONF_TOKEN): cv.string,
31 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
39 async_add_entities: AddEntitiesCallback,
40 discovery_info: DiscoveryInfoType |
None =
None,
42 """Set up the OTP sensor."""
46 f
"deprecated_yaml_{DOMAIN}",
48 breaks_in_ha_version=
"2025.1.0",
49 severity=IssueSeverity.WARNING,
50 translation_key=
"deprecated_yaml",
51 translation_placeholders={
53 "integration_title":
"One-Time Password (OTP)",
56 await hass.config_entries.flow.async_init(
57 DOMAIN, context={
"source": SOURCE_IMPORT}, data=config
62 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
64 """Set up the OTP sensor."""
67 [
TOTPSensor(entry.data[CONF_NAME], entry.data[CONF_TOKEN], entry.entry_id)],
74 """Representation of a TOTP sensor."""
76 _attr_translation_key =
"token"
77 _attr_should_poll =
False
78 _attr_native_value: StateType =
None
79 _next_expiration: float |
None =
None
80 _attr_has_entity_name =
True
83 def __init__(self, name: str, token: str, entry_id: str) ->
None:
84 """Initialize the sensor."""
86 self.
_otp_otp = pyotp.TOTP(token)
90 entry_type=DeviceEntryType.SERVICE,
91 identifiers={(DOMAIN, entry_id)},
95 """Handle when an entity is about to be added to Home Assistant."""
None __init__(self, str name, str token, str entry_id)
None async_added_to_hass(self)
None async_write_ha_state(self)
DeviceInfo|None device_info(self)
None async_create_issue(HomeAssistant hass, str entry_id)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
datetime now(HomeAssistant hass)