diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 69a99e3ac8e..9965fae9d59 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -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'"