Add device classes to bloomsky (#84054)

This commit is contained in:
epenet 2022-12-15 17:36:10 +01:00 committed by GitHub
parent b0b3b36392
commit dcea8a6ced
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,12 +11,10 @@ from homeassistant.components.sensor import (
from homeassistant.const import ( from homeassistant.const import (
AREA_SQUARE_METERS, AREA_SQUARE_METERS,
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
ELECTRIC_POTENTIAL_MILLIVOLT,
PERCENTAGE, PERCENTAGE,
PRESSURE_INHG, UnitOfElectricPotential,
PRESSURE_MBAR, UnitOfPressure,
TEMP_CELSIUS, UnitOfTemperature,
TEMP_FAHRENHEIT,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -37,25 +35,28 @@ SENSOR_TYPES = [
# Sensor units - these do not currently align with the API documentation # Sensor units - these do not currently align with the API documentation
SENSOR_UNITS_IMPERIAL = { SENSOR_UNITS_IMPERIAL = {
"Temperature": TEMP_FAHRENHEIT, "Temperature": UnitOfTemperature.FAHRENHEIT,
"Humidity": PERCENTAGE, "Humidity": PERCENTAGE,
"Pressure": PRESSURE_INHG, "Pressure": UnitOfPressure.INHG,
"Luminance": f"cd/{AREA_SQUARE_METERS}", "Luminance": f"cd/{AREA_SQUARE_METERS}",
"Voltage": ELECTRIC_POTENTIAL_MILLIVOLT, "Voltage": UnitOfElectricPotential.MILLIVOLT,
} }
# Metric units # Metric units
SENSOR_UNITS_METRIC = { SENSOR_UNITS_METRIC = {
"Temperature": TEMP_CELSIUS, "Temperature": UnitOfTemperature.CELSIUS,
"Humidity": PERCENTAGE, "Humidity": PERCENTAGE,
"Pressure": PRESSURE_MBAR, "Pressure": UnitOfPressure.MBAR,
"Luminance": f"cd/{AREA_SQUARE_METERS}", "Luminance": f"cd/{AREA_SQUARE_METERS}",
"Voltage": ELECTRIC_POTENTIAL_MILLIVOLT, "Voltage": UnitOfElectricPotential.MILLIVOLT,
} }
# Device class # Device class
SENSOR_DEVICE_CLASS = { SENSOR_DEVICE_CLASS = {
"Temperature": SensorDeviceClass.TEMPERATURE, "Temperature": SensorDeviceClass.TEMPERATURE,
"Humidity": SensorDeviceClass.HUMIDITY,
"Pressure": SensorDeviceClass.PRESSURE,
"Voltage": SensorDeviceClass.VOLTAGE,
} }
# Which sensors to format numerically # Which sensors to format numerically
@ -108,7 +109,7 @@ class BloomSkySensor(SensorEntity):
) )
@property @property
def device_class(self): def device_class(self) -> SensorDeviceClass | None:
"""Return the class of this device, from component DEVICE_CLASSES.""" """Return the class of this device, from component DEVICE_CLASSES."""
return SENSOR_DEVICE_CLASS.get(self._sensor_name) return SENSOR_DEVICE_CLASS.get(self._sensor_name)