Use UnitOfMass in integrations (#83930)

This commit is contained in:
epenet 2022-12-14 16:37:11 +01:00 committed by GitHub
parent c0a7934828
commit ae9506d0bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View file

@ -16,7 +16,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import MASS_POUNDS, PERCENTAGE
from homeassistant.const import PERCENTAGE, UnitOfMass
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -140,7 +140,7 @@ ROBOT_SENSOR_MAP: dict[type[Robot], list[RobotSensorEntityDescription]] = {
RobotSensorEntityDescription[LitterRobot4](
key="pet_weight",
name="Pet weight",
native_unit_of_measurement=MASS_POUNDS,
native_unit_of_measurement=UnitOfMass.POUNDS,
device_class=SensorDeviceClass.WEIGHT,
state_class=SensorStateClass.MEASUREMENT,
),

View file

@ -6,10 +6,10 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
ELECTRIC_POTENTIAL_MILLIVOLT,
MASS_GRAMS,
PERCENTAGE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfMass,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant
@ -174,7 +174,7 @@ class OmniLogicSaltLevelSensor(OmnilogicSensor):
if self._unit_type == "Metric":
salt_return = round(int(salt_return) / 1000, 2)
unit_of_measurement = f"{MASS_GRAMS}/{UnitOfVolume.LITERS}"
unit_of_measurement = f"{UnitOfMass.GRAMS}/{UnitOfVolume.LITERS}"
self._unit = unit_of_measurement

View file

@ -24,7 +24,6 @@ from homeassistant.const import (
ENERGY_KILO_WATT_HOUR,
LENGTH_CENTIMETERS,
LIGHT_LUX,
MASS_KILOGRAMS,
PERCENTAGE,
PRESSURE_HPA,
SIGNAL_STRENGTH_DECIBELS,
@ -37,6 +36,7 @@ from homeassistant.const import (
TEMP_KELVIN,
UnitOfApparentPower,
UnitOfFrequency,
UnitOfMass,
UnitOfPower,
)
from homeassistant.core import HomeAssistant, callback
@ -219,7 +219,7 @@ SENSOR_UNIT_MAP = {
hc.FREQUENCY_HERTZ: UnitOfFrequency.HERTZ,
hc.LENGTH_CENTIMETERS: LENGTH_CENTIMETERS,
hc.LIGHT_LUX: LIGHT_LUX,
hc.MASS_KILOGRAMS: MASS_KILOGRAMS,
hc.MASS_KILOGRAMS: UnitOfMass.KILOGRAMS,
hc.PERCENTAGE: PERCENTAGE,
hc.POWER_WATT: UnitOfPower.WATT,
hc.PRESSURE_HPA: PRESSURE_HPA,

View file

@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, MASS_POUNDS, PERCENTAGE
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, PERCENTAGE, UnitOfMass
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
@ -37,7 +37,7 @@ REALTIME_EMISSIONS_SENSOR_DESCRIPTIONS = (
key=SENSOR_TYPE_REALTIME_EMISSIONS_MOER,
name="Marginal operating emissions rate",
icon="mdi:blur",
native_unit_of_measurement=f"{MASS_POUNDS} CO2/MWh",
native_unit_of_measurement=f"{UnitOfMass.POUNDS} CO2/MWh",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(