mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Use enums instead of deprecated constants (#81591)
This commit is contained in:
parent
0311063c44
commit
9a747bafa3
@ -9,7 +9,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
||||
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform as ep
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
@ -175,7 +175,7 @@ class EightUserSensor(EightSleepBaseEntity, SensorEntity):
|
||||
if self._sensor == "bed_temperature":
|
||||
self._attr_icon = "mdi:thermometer"
|
||||
self._attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
self._attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||
elif self._sensor in ("current_sleep", "last_sleep", "current_sleep_fitness"):
|
||||
self._attr_native_unit_of_measurement = "Score"
|
||||
|
||||
@ -272,7 +272,7 @@ class EightRoomSensor(EightSleepBaseEntity, SensorEntity):
|
||||
|
||||
_attr_icon = "mdi:thermometer"
|
||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -26,13 +26,11 @@ from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
IRRADIATION_BTUS_PER_HOUR_SQUARE_FOOT,
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
PERCENTAGE,
|
||||
PRESSURE_HPA,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfLength,
|
||||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -103,20 +101,20 @@ SENSOR_TYPES = (
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_FEELS_LIKE,
|
||||
name="Feels Like",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_DEW_POINT,
|
||||
name="Dew Point",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
# Data comes in as hPa
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_PRESSURE_SURFACE_LEVEL,
|
||||
name="Pressure (Surface Level)",
|
||||
native_unit_of_measurement=PRESSURE_HPA,
|
||||
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||
device_class=SensorDeviceClass.PRESSURE,
|
||||
),
|
||||
# Data comes in as W/m^2, convert to BTUs/(hr * ft^2) for imperial
|
||||
@ -132,20 +130,24 @@ SENSOR_TYPES = (
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_CLOUD_BASE,
|
||||
name="Cloud Base",
|
||||
unit_imperial=LENGTH_MILES,
|
||||
unit_metric=LENGTH_KILOMETERS,
|
||||
unit_imperial=UnitOfLength.MILES,
|
||||
unit_metric=UnitOfLength.KILOMETERS,
|
||||
imperial_conversion=lambda val: DistanceConverter.convert(
|
||||
val, LENGTH_KILOMETERS, LENGTH_MILES
|
||||
val,
|
||||
UnitOfLength.KILOMETERS,
|
||||
UnitOfLength.MILES,
|
||||
),
|
||||
),
|
||||
# Data comes in as km, convert to miles for imperial
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_CLOUD_CEILING,
|
||||
name="Cloud Ceiling",
|
||||
unit_imperial=LENGTH_MILES,
|
||||
unit_metric=LENGTH_KILOMETERS,
|
||||
unit_imperial=UnitOfLength.MILES,
|
||||
unit_metric=UnitOfLength.KILOMETERS,
|
||||
imperial_conversion=lambda val: DistanceConverter.convert(
|
||||
val, LENGTH_KILOMETERS, LENGTH_MILES
|
||||
val,
|
||||
UnitOfLength.KILOMETERS,
|
||||
UnitOfLength.MILES,
|
||||
),
|
||||
),
|
||||
TomorrowioSensorEntityDescription(
|
||||
@ -157,10 +159,10 @@ SENSOR_TYPES = (
|
||||
TomorrowioSensorEntityDescription(
|
||||
key=TMRW_ATTR_WIND_GUST,
|
||||
name="Wind Gust",
|
||||
unit_imperial=SPEED_MILES_PER_HOUR,
|
||||
unit_metric=SPEED_METERS_PER_SECOND,
|
||||
unit_imperial=UnitOfSpeed.MILES_PER_HOUR,
|
||||
unit_metric=UnitOfSpeed.METERS_PER_SECOND,
|
||||
imperial_conversion=lambda val: SpeedConverter.convert(
|
||||
val, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR
|
||||
val, UnitOfSpeed.METERS_PER_SECOND, UnitOfSpeed.MILES_PER_HOUR
|
||||
),
|
||||
),
|
||||
TomorrowioSensorEntityDescription(
|
||||
|
@ -21,11 +21,10 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_NAME,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILLIMETERS,
|
||||
PRESSURE_HPA,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfLength,
|
||||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -74,11 +73,11 @@ async def async_setup_entry(
|
||||
class TomorrowioWeatherEntity(TomorrowioEntity, WeatherEntity):
|
||||
"""Entity that talks to Tomorrow.io v4 API to retrieve weather data."""
|
||||
|
||||
_attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
||||
_attr_native_pressure_unit = PRESSURE_HPA
|
||||
_attr_native_temperature_unit = TEMP_CELSIUS
|
||||
_attr_native_visibility_unit = LENGTH_KILOMETERS
|
||||
_attr_native_wind_speed_unit = SPEED_METERS_PER_SECOND
|
||||
_attr_native_precipitation_unit = UnitOfLength.MILLIMETERS
|
||||
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_attr_native_visibility_unit = UnitOfLength.KILOMETERS
|
||||
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -34,12 +34,7 @@ from homeassistant.components.climate import (
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
PRECISION_TENTHS,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -260,8 +255,8 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity):
|
||||
and self._unit_value.metadata.unit
|
||||
and "f" in self._unit_value.metadata.unit.lower()
|
||||
):
|
||||
return TEMP_FAHRENHEIT
|
||||
return TEMP_CELSIUS
|
||||
return UnitOfTemperature.FAHRENHEIT
|
||||
return UnitOfTemperature.CELSIUS
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
@ -398,7 +393,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity):
|
||||
def min_temp(self) -> float:
|
||||
"""Return the minimum temperature."""
|
||||
min_temp = DEFAULT_MIN_TEMP
|
||||
base_unit = TEMP_CELSIUS
|
||||
base_unit: str = UnitOfTemperature.CELSIUS
|
||||
try:
|
||||
temp = self._setpoint_value_or_raise(self._current_mode_setpoint_enums[0])
|
||||
if temp.metadata.min:
|
||||
@ -414,7 +409,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity):
|
||||
def max_temp(self) -> float:
|
||||
"""Return the maximum temperature."""
|
||||
max_temp = DEFAULT_MAX_TEMP
|
||||
base_unit = TEMP_CELSIUS
|
||||
base_unit: str = UnitOfTemperature.CELSIUS
|
||||
try:
|
||||
temp = self._setpoint_value_or_raise(self._current_mode_setpoint_enums[0])
|
||||
if temp.metadata.max:
|
||||
|
@ -96,35 +96,24 @@ from homeassistant.const import (
|
||||
ELECTRIC_CURRENT_MILLIAMPERE,
|
||||
ELECTRIC_POTENTIAL_MILLIVOLT,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
FREQUENCY_HERTZ,
|
||||
FREQUENCY_KILOHERTZ,
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER,
|
||||
LENGTH_CENTIMETERS,
|
||||
LENGTH_FEET,
|
||||
LENGTH_METERS,
|
||||
LIGHT_LUX,
|
||||
MASS_KILOGRAMS,
|
||||
MASS_POUNDS,
|
||||
PERCENTAGE,
|
||||
POWER_BTU_PER_HOUR,
|
||||
POWER_WATT,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_MMHG,
|
||||
PRESSURE_PSI,
|
||||
SIGNAL_STRENGTH_DECIBELS,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
TIME_SECONDS,
|
||||
VOLUME_CUBIC_FEET,
|
||||
VOLUME_CUBIC_METERS,
|
||||
VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE,
|
||||
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
|
||||
VOLUME_GALLONS,
|
||||
VOLUME_LITERS,
|
||||
UnitOfEnergy,
|
||||
UnitOfLength,
|
||||
UnitOfMass,
|
||||
UnitOfPower,
|
||||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolume,
|
||||
UnitOfVolumetricFlux,
|
||||
)
|
||||
|
||||
@ -173,21 +162,21 @@ MULTILEVEL_SENSOR_DEVICE_CLASS_MAP: dict[str, set[MultilevelSensorType]] = {
|
||||
|
||||
METER_UNIT_MAP: dict[str, set[MeterScaleType]] = {
|
||||
ELECTRIC_CURRENT_AMPERE: METER_UNIT_AMPERE,
|
||||
VOLUME_CUBIC_FEET: UNIT_CUBIC_FEET,
|
||||
VOLUME_CUBIC_METERS: METER_UNIT_CUBIC_METER,
|
||||
VOLUME_GALLONS: UNIT_US_GALLON,
|
||||
ENERGY_KILO_WATT_HOUR: UNIT_KILOWATT_HOUR,
|
||||
UnitOfVolume.CUBIC_FEET: UNIT_CUBIC_FEET,
|
||||
UnitOfVolume.CUBIC_METERS: METER_UNIT_CUBIC_METER,
|
||||
UnitOfVolume.GALLONS: UNIT_US_GALLON,
|
||||
UnitOfEnergy.KILO_WATT_HOUR: UNIT_KILOWATT_HOUR,
|
||||
ELECTRIC_POTENTIAL_VOLT: METER_UNIT_VOLT,
|
||||
POWER_WATT: METER_UNIT_WATT,
|
||||
UnitOfPower.WATT: METER_UNIT_WATT,
|
||||
}
|
||||
|
||||
MULTILEVEL_SENSOR_UNIT_MAP: dict[str, set[MultilevelSensorScaleType]] = {
|
||||
ELECTRIC_CURRENT_AMPERE: SENSOR_UNIT_AMPERE,
|
||||
POWER_BTU_PER_HOUR: UNIT_BTU_H,
|
||||
TEMP_CELSIUS: UNIT_CELSIUS,
|
||||
LENGTH_CENTIMETERS: UNIT_CENTIMETER,
|
||||
UnitOfPower.BTU_PER_HOUR: UNIT_BTU_H,
|
||||
UnitOfTemperature.CELSIUS: UNIT_CELSIUS,
|
||||
UnitOfLength.CENTIMETERS: UNIT_CENTIMETER,
|
||||
VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE: UNIT_CUBIC_FEET_PER_MINUTE,
|
||||
VOLUME_CUBIC_METERS: SENSOR_UNIT_CUBIC_METER,
|
||||
UnitOfVolume.CUBIC_METERS: SENSOR_UNIT_CUBIC_METER,
|
||||
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR: UNIT_CUBIC_METER_PER_HOUR,
|
||||
SIGNAL_STRENGTH_DECIBELS: UNIT_DECIBEL,
|
||||
DEGREE: UNIT_DEGREES,
|
||||
@ -195,31 +184,31 @@ MULTILEVEL_SENSOR_UNIT_MAP: dict[str, set[MultilevelSensorScaleType]] = {
|
||||
*UNIT_DENSITY,
|
||||
*UNIT_MICROGRAM_PER_CUBIC_METER,
|
||||
},
|
||||
TEMP_FAHRENHEIT: UNIT_FAHRENHEIT,
|
||||
LENGTH_FEET: UNIT_FEET,
|
||||
VOLUME_GALLONS: UNIT_GALLONS,
|
||||
UnitOfTemperature.FAHRENHEIT: UNIT_FAHRENHEIT,
|
||||
UnitOfLength.FEET: UNIT_FEET,
|
||||
UnitOfVolume.GALLONS: UNIT_GALLONS,
|
||||
FREQUENCY_HERTZ: UNIT_HERTZ,
|
||||
PRESSURE_INHG: UNIT_INCHES_OF_MERCURY,
|
||||
UnitOfPressure.INHG: UNIT_INCHES_OF_MERCURY,
|
||||
UnitOfVolumetricFlux.INCHES_PER_HOUR: UNIT_INCHES_PER_HOUR,
|
||||
MASS_KILOGRAMS: UNIT_KILOGRAM,
|
||||
UnitOfMass.KILOGRAMS: UNIT_KILOGRAM,
|
||||
FREQUENCY_KILOHERTZ: UNIT_KILOHERTZ,
|
||||
VOLUME_LITERS: UNIT_LITER,
|
||||
UnitOfVolume.LITERS: UNIT_LITER,
|
||||
LIGHT_LUX: UNIT_LUX,
|
||||
LENGTH_METERS: UNIT_METER,
|
||||
UnitOfLength.METERS: UNIT_METER,
|
||||
ELECTRIC_CURRENT_MILLIAMPERE: UNIT_MILLIAMPERE,
|
||||
UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR: UNIT_MILLIMETER_HOUR,
|
||||
ELECTRIC_POTENTIAL_MILLIVOLT: UNIT_MILLIVOLT,
|
||||
SPEED_MILES_PER_HOUR: UNIT_MPH,
|
||||
SPEED_METERS_PER_SECOND: UNIT_M_S,
|
||||
UnitOfSpeed.MILES_PER_HOUR: UNIT_MPH,
|
||||
UnitOfSpeed.METERS_PER_SECOND: UNIT_M_S,
|
||||
CONCENTRATION_PARTS_PER_MILLION: UNIT_PARTS_MILLION,
|
||||
PERCENTAGE: {*UNIT_PERCENTAGE_VALUE, *UNIT_RSSI},
|
||||
MASS_POUNDS: UNIT_POUNDS,
|
||||
PRESSURE_PSI: UNIT_POUND_PER_SQUARE_INCH,
|
||||
UnitOfMass.POUNDS: UNIT_POUNDS,
|
||||
UnitOfPressure.PSI: UNIT_POUND_PER_SQUARE_INCH,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT: UNIT_POWER_LEVEL,
|
||||
TIME_SECONDS: UNIT_SECOND,
|
||||
PRESSURE_MMHG: UNIT_SYSTOLIC,
|
||||
UnitOfPressure.MMHG: UNIT_SYSTOLIC,
|
||||
ELECTRIC_POTENTIAL_VOLT: SENSOR_UNIT_VOLT,
|
||||
POWER_WATT: SENSOR_UNIT_WATT,
|
||||
UnitOfPower.WATT: SENSOR_UNIT_WATT,
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER: UNIT_WATT_PER_SQUARE_METER,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user