From 4515eedea90a35ccdcb90caae62661a4ae365e82 Mon Sep 17 00:00:00 2001 From: "Mr. Bubbles" Date: Fri, 21 Jun 2024 10:28:52 +0200 Subject: [PATCH] Add unique_id to One-Time Password (OTP) (#120050) --- homeassistant/components/otp/sensor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/otp/sensor.py b/homeassistant/components/otp/sensor.py index e612b03f66c..0c87afb86b7 100644 --- a/homeassistant/components/otp/sensor.py +++ b/homeassistant/components/otp/sensor.py @@ -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: