Add unique_id to One-Time Password (OTP) (#120050)

This commit is contained in:
Mr. Bubbles 2024-06-21 10:28:52 +02:00 committed by GitHub
parent 53d3475b1d
commit 4515eedea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,7 +60,8 @@ async def async_setup_entry(
"""Set up the OTP sensor."""
async_add_entities(
[TOTPSensor(entry.data[CONF_NAME], entry.data[CONF_TOKEN])], True
[TOTPSensor(entry.data[CONF_NAME], entry.data[CONF_TOKEN], entry.entry_id)],
True,
)
@ -73,9 +74,10 @@ class TOTPSensor(SensorEntity):
_attr_native_value: StateType = None
_next_expiration: float | None = None
def __init__(self, name: str, token: str) -> None:
def __init__(self, name: str, token: str, entry_id: str) -> None:
"""Initialize the sensor."""
self._attr_name = name
self._attr_unique_id = entry_id
self._otp = pyotp.TOTP(token)
async def async_added_to_hass(self) -> None: