Use identity checks for sensor device class enums (#106383)
parent
3016dbc2bd
commit
50f64e053e
|
@ -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'"
|
||||
|
|
Loading…
Reference in New Issue