Use identity checks for sensor device class enums (#106383)

pull/105955/head
J. Nick Koston 2023-12-25 08:35:44 -10:00 committed by GitHub
parent 3016dbc2bd
commit 50f64e053e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -511,7 +511,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
if (
native_unit_of_measurement
in {UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT}
and self.device_class == SensorDeviceClass.TEMPERATURE
and self.device_class is SensorDeviceClass.TEMPERATURE
):
return self.hass.config.units.temperature_unit
@ -572,7 +572,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
return None
# Received a datetime
if device_class == SensorDeviceClass.TIMESTAMP:
if device_class is SensorDeviceClass.TIMESTAMP:
try:
# We cast the value, to avoid using isinstance, but satisfy
# typechecking. The errors are guarded in this try.
@ -594,7 +594,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
) from err
# Received a date value
if device_class == SensorDeviceClass.DATE:
if device_class is SensorDeviceClass.DATE:
try:
# We cast the value, to avoid using isinstance, but satisfy
# typechecking. The errors are guarded in this try.
@ -609,8 +609,8 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
# Enum checks
if (
options := self.options
) is not None or device_class == SensorDeviceClass.ENUM:
if device_class != SensorDeviceClass.ENUM:
) is not None or device_class is SensorDeviceClass.ENUM:
if device_class is not SensorDeviceClass.ENUM:
reason = "is missing the enum device class"
if device_class is not None:
reason = f"has device class '{device_class}' instead of 'enum'"