mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove temperature conversion - dht (#55161)
This commit is contained in:
parent
2927dcd809
commit
81a6bec818
@ -15,11 +15,10 @@ from homeassistant.const import (
|
|||||||
DEVICE_CLASS_HUMIDITY,
|
DEVICE_CLASS_HUMIDITY,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
from homeassistant.util.temperature import celsius_to_fahrenheit
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
|||||||
SENSOR_TEMPERATURE = "temperature"
|
SENSOR_TEMPERATURE = "temperature"
|
||||||
SENSOR_HUMIDITY = "humidity"
|
SENSOR_HUMIDITY = "humidity"
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
SENSOR_TEMPERATURE: ["Temperature", None, DEVICE_CLASS_TEMPERATURE],
|
SENSOR_TEMPERATURE: ["Temperature", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE],
|
||||||
SENSOR_HUMIDITY: ["Humidity", PERCENTAGE, DEVICE_CLASS_HUMIDITY],
|
SENSOR_HUMIDITY: ["Humidity", PERCENTAGE, DEVICE_CLASS_HUMIDITY],
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +68,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the DHT sensor."""
|
"""Set up the DHT sensor."""
|
||||||
SENSOR_TYPES[SENSOR_TEMPERATURE][1] = hass.config.units.temperature_unit
|
|
||||||
available_sensors = {
|
available_sensors = {
|
||||||
"AM2302": adafruit_dht.DHT22,
|
"AM2302": adafruit_dht.DHT22,
|
||||||
"DHT11": adafruit_dht.DHT11,
|
"DHT11": adafruit_dht.DHT11,
|
||||||
@ -94,7 +92,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
DHTSensor(
|
DHTSensor(
|
||||||
data,
|
data,
|
||||||
variable,
|
variable,
|
||||||
SENSOR_TYPES[variable][1],
|
|
||||||
name,
|
name,
|
||||||
temperature_offset,
|
temperature_offset,
|
||||||
humidity_offset,
|
humidity_offset,
|
||||||
@ -111,7 +108,6 @@ class DHTSensor(SensorEntity):
|
|||||||
self,
|
self,
|
||||||
dht_client,
|
dht_client,
|
||||||
sensor_type,
|
sensor_type,
|
||||||
temp_unit,
|
|
||||||
name,
|
name,
|
||||||
temperature_offset,
|
temperature_offset,
|
||||||
humidity_offset,
|
humidity_offset,
|
||||||
@ -120,7 +116,6 @@ class DHTSensor(SensorEntity):
|
|||||||
self.client_name = name
|
self.client_name = name
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self.dht_client = dht_client
|
self.dht_client = dht_client
|
||||||
self.temp_unit = temp_unit
|
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
self.temperature_offset = temperature_offset
|
self.temperature_offset = temperature_offset
|
||||||
self.humidity_offset = humidity_offset
|
self.humidity_offset = humidity_offset
|
||||||
@ -159,8 +154,6 @@ class DHTSensor(SensorEntity):
|
|||||||
)
|
)
|
||||||
if -20 <= temperature < 80:
|
if -20 <= temperature < 80:
|
||||||
self._state = round(temperature + temperature_offset, 1)
|
self._state = round(temperature + temperature_offset, 1)
|
||||||
if self.temp_unit == TEMP_FAHRENHEIT:
|
|
||||||
self._state = round(celsius_to_fahrenheit(temperature), 1)
|
|
||||||
elif self.type == SENSOR_HUMIDITY and SENSOR_HUMIDITY in data:
|
elif self.type == SENSOR_HUMIDITY and SENSOR_HUMIDITY in data:
|
||||||
humidity = data[SENSOR_HUMIDITY]
|
humidity = data[SENSOR_HUMIDITY]
|
||||||
_LOGGER.debug("Humidity %.1f%% + offset %.1f", humidity, humidity_offset)
|
_LOGGER.debug("Humidity %.1f%% + offset %.1f", humidity, humidity_offset)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user