Remove temperature conversion - bme280 (#55162)
This commit is contained in:
parent
81a6bec818
commit
cb556fe98e
2 changed files with 4 additions and 14 deletions
|
@ -6,6 +6,7 @@ from homeassistant.const import (
|
|||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
|
||||
# Common
|
||||
|
@ -26,7 +27,7 @@ SENSOR_TEMP = "temperature"
|
|||
SENSOR_HUMID = "humidity"
|
||||
SENSOR_PRESS = "pressure"
|
||||
SENSOR_TYPES = {
|
||||
SENSOR_TEMP: ["Temperature", None, DEVICE_CLASS_TEMPERATURE],
|
||||
SENSOR_TEMP: ["Temperature", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE],
|
||||
SENSOR_HUMID: ["Humidity", PERCENTAGE, DEVICE_CLASS_HUMIDITY],
|
||||
SENSOR_PRESS: ["Pressure", "mb", DEVICE_CLASS_PRESSURE],
|
||||
}
|
||||
|
|
|
@ -7,18 +7,12 @@ from i2csense.bme280 import BME280 as BME280_i2c # pylint: disable=import-error
|
|||
import smbus
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorEntity
|
||||
from homeassistant.const import (
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_SCAN_INTERVAL
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
UpdateFailed,
|
||||
)
|
||||
from homeassistant.util.temperature import celsius_to_fahrenheit
|
||||
|
||||
from .const import (
|
||||
CONF_DELTA_TEMP,
|
||||
|
@ -47,7 +41,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
"""Set up the BME280 sensor."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit
|
||||
sensor_conf = discovery_info[SENSOR_DOMAIN]
|
||||
name = sensor_conf[CONF_NAME]
|
||||
scan_interval = max(sensor_conf[CONF_SCAN_INTERVAL], MIN_TIME_BETWEEN_UPDATES)
|
||||
|
@ -110,7 +103,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
entities.append(
|
||||
BME280Sensor(
|
||||
condition,
|
||||
SENSOR_TYPES[condition][1],
|
||||
name,
|
||||
coordinator,
|
||||
)
|
||||
|
@ -121,11 +113,10 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
class BME280Sensor(CoordinatorEntity, SensorEntity):
|
||||
"""Implementation of the BME280 sensor."""
|
||||
|
||||
def __init__(self, sensor_type, temp_unit, name, coordinator):
|
||||
def __init__(self, sensor_type, name, coordinator):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_name = f"{name} {SENSOR_TYPES[sensor_type][0]}"
|
||||
self.temp_unit = temp_unit
|
||||
self.type = sensor_type
|
||||
self._attr_native_unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
||||
self._attr_device_class = SENSOR_TYPES[sensor_type][2]
|
||||
|
@ -135,8 +126,6 @@ class BME280Sensor(CoordinatorEntity, SensorEntity):
|
|||
"""Return the state of the sensor."""
|
||||
if self.type == SENSOR_TEMP:
|
||||
temperature = round(self.coordinator.data.temperature, 1)
|
||||
if self.temp_unit == TEMP_FAHRENHEIT:
|
||||
temperature = round(celsius_to_fahrenheit(temperature), 1)
|
||||
state = temperature
|
||||
elif self.type == SENSOR_HUMID:
|
||||
state = round(self.coordinator.data.humidity, 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue