From 90984c34a97d7b32fe3c3e7a91bab43b9f3d95ac Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 21 May 2023 07:42:19 -0500 Subject: [PATCH] Fix double call to options in sensor state (#93311) --- homeassistant/components/sensor/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index d0fdc8a0886..9b0a3b5e3d4 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -548,7 +548,9 @@ class SensorEntity(Entity): ) from err # Enum checks - if device_class == SensorDeviceClass.ENUM or self.options is not None: + if ( + options := self.options + ) is not None or device_class == SensorDeviceClass.ENUM: if device_class != SensorDeviceClass.ENUM: reason = "is missing the enum device class" if device_class is not None: @@ -557,7 +559,7 @@ class SensorEntity(Entity): f"Sensor {self.entity_id} is providing enum options, but {reason}" ) - if (options := self.options) and value not in options: + if options and value not in options: raise ValueError( f"Sensor {self.entity_id} provides state value '{value}', " "which is not in the list of options provided"