Fix double call to options in sensor state (#93311)

This commit is contained in:
J. Nick Koston 2023-05-21 07:42:19 -05:00 committed by GitHub
parent 780f9bcdc0
commit 90984c34a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -548,7 +548,9 @@ class SensorEntity(Entity):
) from err ) from err
# Enum checks # 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: if device_class != SensorDeviceClass.ENUM:
reason = "is missing the enum device class" reason = "is missing the enum device class"
if device_class is not None: if device_class is not None:
@ -557,7 +559,7 @@ class SensorEntity(Entity):
f"Sensor {self.entity_id} is providing enum options, but {reason}" 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( raise ValueError(
f"Sensor {self.entity_id} provides state value '{value}', " f"Sensor {self.entity_id} provides state value '{value}', "
"which is not in the list of options provided" "which is not in the list of options provided"