Use UnitOfTemperature in integrations (p-s) (#84308)
This commit is contained in:
parent
d60fe7e7cd
commit
ba043c9ebb
24 changed files with 93 additions and 86 deletions
|
@ -18,7 +18,7 @@ from homeassistant.const import (
|
|||
STATE_PROBLEM,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -138,7 +138,7 @@ class Plant(Entity):
|
|||
"min": CONF_MIN_BATTERY_LEVEL,
|
||||
},
|
||||
READING_TEMPERATURE: {
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||
"min": CONF_MIN_TEMPERATURE,
|
||||
"max": CONF_MAX_TEMPERATURE,
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.components.number import (
|
|||
NumberMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -51,7 +51,7 @@ NUMBER_TYPES = (
|
|||
native_max_value_key="upper_bound",
|
||||
native_min_value_key="lower_bound",
|
||||
native_step_key="resolution",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
native_value_key="setpoint",
|
||||
),
|
||||
)
|
||||
|
|
|
@ -10,10 +10,10 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfPressure,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -28,7 +28,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="setpoint",
|
||||
name="Setpoint",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
|
@ -36,7 +36,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="setpoint_high",
|
||||
name="Cooling setpoint",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
|
@ -44,7 +44,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="setpoint_low",
|
||||
name="Heating setpoint",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
|
@ -52,7 +52,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="temperature",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -60,7 +60,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="intended_boiler_temperature",
|
||||
name="Intended boiler temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -68,7 +68,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="temperature_difference",
|
||||
name="Temperature difference",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -76,14 +76,14 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="outdoor_temperature",
|
||||
name="Outdoor temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="outdoor_air_temperature",
|
||||
name="Outdoor air temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -91,7 +91,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="water_temperature",
|
||||
name="Water temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -99,7 +99,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="return_temperature",
|
||||
name="Return temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -295,7 +295,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="dhw_temperature",
|
||||
name="DHW temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -303,7 +303,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="domestic_hot_water_setpoint",
|
||||
name="DHW setpoint",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -311,7 +311,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="maximum_boiler_temperature",
|
||||
name="Maximum boiler temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
|
|
@ -31,8 +31,7 @@ from homeassistant.const import (
|
|||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entityfilter, state as state_helper
|
||||
|
@ -347,9 +346,12 @@ class PrometheusMetrics:
|
|||
|
||||
with suppress(ValueError):
|
||||
value = self.state_as_number(state)
|
||||
if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT:
|
||||
if (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== UnitOfTemperature.FAHRENHEIT
|
||||
):
|
||||
value = TemperatureConverter.convert(
|
||||
value, TEMP_FAHRENHEIT, TEMP_CELSIUS
|
||||
value, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS
|
||||
)
|
||||
metric.labels(**self._labels(state)).set(value)
|
||||
|
||||
|
@ -395,8 +397,10 @@ class PrometheusMetrics:
|
|||
|
||||
def _handle_climate_temp(self, state, attr, metric_name, metric_description):
|
||||
if temp := state.attributes.get(attr):
|
||||
if self._climate_units == TEMP_FAHRENHEIT:
|
||||
temp = TemperatureConverter.convert(temp, TEMP_FAHRENHEIT, TEMP_CELSIUS)
|
||||
if self._climate_units == UnitOfTemperature.FAHRENHEIT:
|
||||
temp = TemperatureConverter.convert(
|
||||
temp, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS
|
||||
)
|
||||
metric = self._metric(
|
||||
metric_name,
|
||||
self.prometheus_cli.Gauge,
|
||||
|
@ -508,9 +512,12 @@ class PrometheusMetrics:
|
|||
|
||||
try:
|
||||
value = self.state_as_number(state)
|
||||
if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT:
|
||||
if (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== UnitOfTemperature.FAHRENHEIT
|
||||
):
|
||||
value = TemperatureConverter.convert(
|
||||
value, TEMP_FAHRENHEIT, TEMP_CELSIUS
|
||||
value, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS
|
||||
)
|
||||
_metric.labels(**self._labels(state)).set(value)
|
||||
except ValueError:
|
||||
|
@ -559,8 +566,8 @@ class PrometheusMetrics:
|
|||
return
|
||||
|
||||
units = {
|
||||
TEMP_CELSIUS: "celsius",
|
||||
TEMP_FAHRENHEIT: "celsius", # F should go into C metric
|
||||
UnitOfTemperature.CELSIUS: "celsius",
|
||||
UnitOfTemperature.FAHRENHEIT: "celsius", # F should go into C metric
|
||||
PERCENTAGE: "percent",
|
||||
}
|
||||
default = unit.replace("/", "_per_")
|
||||
|
|
|
@ -15,7 +15,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
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.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
@ -66,7 +66,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = {
|
|||
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||
key="printer.telemetry.temp-bed",
|
||||
name="Heatbed",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: cast(float, data["telemetry"]["temp-bed"]),
|
||||
|
@ -75,7 +75,7 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = {
|
|||
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||
key="printer.telemetry.temp-nozzle",
|
||||
name="Nozzle Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: cast(float, data["telemetry"]["temp-nozzle"]),
|
||||
|
|
|
@ -14,10 +14,10 @@ from homeassistant.components.sensor import (
|
|||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -85,7 +85,7 @@ SENSORS: tuple[PVOutputSensorEntityDescription, ...] = (
|
|||
PVOutputSensorEntityDescription(
|
||||
key="temperature",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda status: status.temperature,
|
||||
|
|
|
@ -28,8 +28,8 @@ from homeassistant.const import (
|
|||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfPressure,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -109,7 +109,7 @@ SENSOR_DESCRIPTIONS = {
|
|||
): SensorEntityDescription(
|
||||
key=f"{QingpingSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ from homeassistant.const import (
|
|||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfDataRate,
|
||||
UnitOfInformation,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -74,7 +74,7 @@ _SYSTEM_MON_COND: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="system_temp",
|
||||
name="System Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
)
|
||||
|
@ -82,7 +82,7 @@ _CPU_MON_COND: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="cpu_temp",
|
||||
name="CPU Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
|
@ -144,7 +144,7 @@ _DRIVE_MON_COND: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="drive_temp",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
)
|
||||
|
|
|
@ -32,9 +32,9 @@ from homeassistant.components.sensor import (
|
|||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS,
|
||||
UnitOfDataRate,
|
||||
UnitOfInformation,
|
||||
UnitOfTemperature,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -117,7 +117,7 @@ SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = (
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
key=QSD_SYSTEM_SENSOR,
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
subkey=QSD_TEMP,
|
||||
),
|
||||
|
|
|
@ -24,10 +24,10 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfEnergy,
|
||||
UnitOfLength,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
UnitOfTime,
|
||||
UnitOfVolume,
|
||||
)
|
||||
|
@ -266,7 +266,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = (
|
|||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_class=RenaultSensor[KamereonVehicleBatteryStatusData],
|
||||
name="Battery temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
RenaultSensorEntityDescription(
|
||||
|
@ -324,7 +324,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = (
|
|||
data_key="externalTemperature",
|
||||
entity_class=RenaultSensor[KamereonVehicleHvacStatusData],
|
||||
name="Outside temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
RenaultSensorEntityDescription(
|
||||
|
|
|
@ -17,7 +17,7 @@ from homeassistant.const import (
|
|||
CONF_PORT,
|
||||
CONF_SENSORS,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -142,21 +142,21 @@ SENSOR_TYPES: dict[str, RepetierSensorEntityDescription] = {
|
|||
"bed_temperature": RepetierSensorEntityDescription(
|
||||
key="bed_temperature",
|
||||
type="temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
name="_bed_",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
"extruder_temperature": RepetierSensorEntityDescription(
|
||||
key="extruder_temperature",
|
||||
type="temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
name="_extruder_",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
"chamber_temperature": RepetierSensorEntityDescription(
|
||||
key="chamber_temperature",
|
||||
type="temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
name="_chamber_",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
|
|
|
@ -21,8 +21,8 @@ from homeassistant.const import (
|
|||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -311,7 +311,7 @@ class SensiboMotionSensor(SensiboMotionBaseEntity, SensorEntity):
|
|||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Add native unit of measurement."""
|
||||
if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE:
|
||||
return TEMP_CELSIUS
|
||||
return UnitOfTemperature.CELSIUS
|
||||
return self.entity_description.native_unit_of_measurement
|
||||
|
||||
@property
|
||||
|
@ -345,7 +345,7 @@ class SensiboDeviceSensor(SensiboDeviceBaseEntity, SensorEntity):
|
|||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Add native unit of measurement."""
|
||||
if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE:
|
||||
return TEMP_CELSIUS
|
||||
return UnitOfTemperature.CELSIUS
|
||||
return self.entity_description.native_unit_of_measurement
|
||||
|
||||
@property
|
||||
|
|
|
@ -25,8 +25,8 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -67,7 +67,7 @@ SENSOR_DESCRIPTIONS = {
|
|||
): SensorEntityDescription(
|
||||
key=f"{SensorProSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
(
|
||||
|
|
|
@ -22,8 +22,8 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfPressure,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -35,7 +35,7 @@ SENSOR_DESCRIPTIONS = {
|
|||
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
||||
key=f"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
(DeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription(
|
||||
|
|
|
@ -20,11 +20,11 @@ from homeassistant.const import (
|
|||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -79,7 +79,7 @@ SENSORS: Final = {
|
|||
("device", "deviceTemp"): BlockSensorDescription(
|
||||
key="device|deviceTemp",
|
||||
name="Device Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda value: round(value, 1),
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -221,7 +221,7 @@ SENSORS: Final = {
|
|||
("sensor", "temp"): BlockSensorDescription(
|
||||
key="sensor|temp",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda value: round(value, 1),
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -230,7 +230,7 @@ SENSORS: Final = {
|
|||
("sensor", "extTemp"): BlockSensorDescription(
|
||||
key="sensor|extTemp",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda value: round(value, 1),
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -345,7 +345,7 @@ RPC_SENSORS: Final = {
|
|||
key="switch",
|
||||
sub_key="temperature",
|
||||
name="Device Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda status, _: round(status["tC"], 1),
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
@ -357,7 +357,7 @@ RPC_SENSORS: Final = {
|
|||
key="temperature",
|
||||
sub_key="tC",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda status, _: round(status, 1),
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TEMP_FAHRENHEIT
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -42,7 +42,7 @@ class SimplisafeFreezeSensor(SimpliSafeEntity, SensorEntity):
|
|||
"""Define a SimpliSafe freeze sensor entity."""
|
||||
|
||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT
|
||||
_attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT
|
||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||
|
||||
def __init__(
|
||||
|
|
|
@ -21,7 +21,7 @@ from homeassistant.const import (
|
|||
EVENT_HOMEASSISTANT_STOP,
|
||||
PERCENTAGE,
|
||||
STATE_UNKNOWN,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -105,7 +105,7 @@ class SkybeaconTemp(SensorEntity):
|
|||
"""Representation of a Skybeacon temperature sensor."""
|
||||
|
||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||
|
||||
def __init__(self, name, mon):
|
||||
"""Initialize a sensor."""
|
||||
|
|
|
@ -7,7 +7,7 @@ import logging
|
|||
from pysmarty import Smarty
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.const import UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -78,7 +78,7 @@ class SupplyAirTemperatureSensor(SmartySensor):
|
|||
super().__init__(
|
||||
name=f"{name} Supply Air Temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
smarty=smarty,
|
||||
)
|
||||
|
||||
|
@ -96,7 +96,7 @@ class ExtractAirTemperatureSensor(SmartySensor):
|
|||
super().__init__(
|
||||
name=f"{name} Extract Air Temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
smarty=smarty,
|
||||
)
|
||||
|
||||
|
@ -114,7 +114,7 @@ class OutdoorAirTemperatureSensor(SmartySensor):
|
|||
super().__init__(
|
||||
name=f"{name} Outdoor Air Temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
smarty=smarty,
|
||||
)
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfFrequency,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -40,7 +40,7 @@ SENSOR_DESCRIPTIONS: dict[tuple[Units, bool], SensorEntityDescription] = {
|
|||
(Units.C, False): SensorEntityDescription(
|
||||
key=f"{Units.C}_{False}",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
(Units.KWH, False): SensorEntityDescription(
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UnitOfTime
|
||||
from homeassistant.const import UnitOfTemperature, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -25,8 +25,8 @@ _KEY_MINUTES_REMAIN = "minutes_remain"
|
|||
_KEY_TEMP = "temp"
|
||||
|
||||
UNIT_MAPPINGS = {
|
||||
"C": TEMP_CELSIUS,
|
||||
"F": TEMP_FAHRENHEIT,
|
||||
"C": UnitOfTemperature.CELSIUS,
|
||||
"F": UnitOfTemperature.FAHRENHEIT,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -69,7 +69,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
|
|||
"temperature": SensorEntityDescription(
|
||||
key="temperature",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
|
|
|
@ -19,9 +19,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import (
|
||||
CONF_DISKS,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfDataRate,
|
||||
UnitOfInformation,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -223,7 +223,7 @@ STORAGE_VOL_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
|
|||
api_key=SynoStorage.API_KEY,
|
||||
key="volume_disk_temp_avg",
|
||||
name="Average Disk Temp",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
|
@ -231,7 +231,7 @@ STORAGE_VOL_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
|
|||
api_key=SynoStorage.API_KEY,
|
||||
key="volume_disk_temp_max",
|
||||
name="Maximum Disk Temp",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
|
@ -257,7 +257,7 @@ STORAGE_DISK_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
|
|||
api_key=SynoStorage.API_KEY,
|
||||
key="disk_temp",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
|
@ -269,7 +269,7 @@ INFORMATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
|
|||
api_key=SynoDSMInformation.API_KEY,
|
||||
key="temperature",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
|
|
|
@ -17,11 +17,11 @@ from homeassistant.const import (
|
|||
CONF_PORT,
|
||||
PERCENTAGE,
|
||||
REVOLUTIONS_PER_MINUTE,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfFrequency,
|
||||
UnitOfInformation,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -147,7 +147,7 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
|
|||
entity_registry_enabled_default=False,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda data: data.cpu.temperature,
|
||||
),
|
||||
SystemBridgeSensorEntityDescription(
|
||||
|
@ -474,7 +474,7 @@ async def async_setup_entry(
|
|||
entity_registry_enabled_default=False,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
value=lambda data, k=gpu["key"]: getattr(
|
||||
data.gpu, f"{k}_temperature"
|
||||
),
|
||||
|
|
|
@ -29,9 +29,9 @@ from homeassistant.const import (
|
|||
PERCENTAGE,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfDataRate,
|
||||
UnitOfInformation,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -218,7 +218,7 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
|
|||
"processor_temperature": SysMonitorSensorEntityDescription(
|
||||
key="processor_temperature",
|
||||
name="Processor temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
|
|
Loading…
Add table
Reference in a new issue