mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use identity checks for sensor device class enums (#106383)
This commit is contained in:
parent
3016dbc2bd
commit
50f64e053e
@ -511,7 +511,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
if (
|
if (
|
||||||
native_unit_of_measurement
|
native_unit_of_measurement
|
||||||
in {UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT}
|
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
|
return self.hass.config.units.temperature_unit
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Received a datetime
|
# Received a datetime
|
||||||
if device_class == SensorDeviceClass.TIMESTAMP:
|
if device_class is SensorDeviceClass.TIMESTAMP:
|
||||||
try:
|
try:
|
||||||
# We cast the value, to avoid using isinstance, but satisfy
|
# We cast the value, to avoid using isinstance, but satisfy
|
||||||
# typechecking. The errors are guarded in this try.
|
# typechecking. The errors are guarded in this try.
|
||||||
@ -594,7 +594,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
) from err
|
) from err
|
||||||
|
|
||||||
# Received a date value
|
# Received a date value
|
||||||
if device_class == SensorDeviceClass.DATE:
|
if device_class is SensorDeviceClass.DATE:
|
||||||
try:
|
try:
|
||||||
# We cast the value, to avoid using isinstance, but satisfy
|
# We cast the value, to avoid using isinstance, but satisfy
|
||||||
# typechecking. The errors are guarded in this try.
|
# typechecking. The errors are guarded in this try.
|
||||||
@ -609,8 +609,8 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
# Enum checks
|
# Enum checks
|
||||||
if (
|
if (
|
||||||
options := self.options
|
options := self.options
|
||||||
) is not None or device_class == SensorDeviceClass.ENUM:
|
) is not None or device_class is SensorDeviceClass.ENUM:
|
||||||
if device_class != SensorDeviceClass.ENUM:
|
if device_class is not 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:
|
||||||
reason = f"has device class '{device_class}' instead of 'enum'"
|
reason = f"has device class '{device_class}' instead of 'enum'"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user