def update(self): """Read from sensor and update the state.""" self._mhz_client.update() data = self._mhz_client.data self._temperature = data.get(SENSOR_TEMPERATURE) if self._temperature is not None and self._temp_unit == TEMP_FAHRENHEIT: self._temperature = round(celsius_to_fahrenheit(self._temperature), 1) self._ppm = data.get(SENSOR_CO2)
async def async_update(self): """Get the latest data from the HTU21D sensor and update the state.""" await self.opp.async_add_executor_job(self._client.update) if self._client.sensor.sample_ok: if self._variable == SENSOR_TEMPERATURE: value = round(self._client.sensor.temperature, 1) if self.unit_of_measurement == TEMP_FAHRENHEIT: value = celsius_to_fahrenheit(value) else: value = round(self._client.sensor.humidity, 1) self._state = value else: _LOGGER.warning("Bad sample")
async def async_update(self): """Get the latest data from the BME280 and update the states.""" await self.opp.async_add_executor_job(self.bme280_client.update) if self.bme280_client.sensor.sample_ok: if self.type == SENSOR_TEMP: temperature = round(self.bme280_client.sensor.temperature, 2) if self.temp_unit == TEMP_FAHRENHEIT: temperature = round(celsius_to_fahrenheit(temperature), 2) self._state = temperature elif self.type == SENSOR_HUMID: self._state = round(self.bme280_client.sensor.humidity, 1) elif self.type == SENSOR_PRESS: self._state = round(self.bme280_client.sensor.pressure, 1) else: _LOGGER.warning("Bad update of sensor.%s", self.name)
def update(self): """ Update current conditions. This uses a rolling median over 3 values to filter out outliers. """ try: _LOGGER.debug("Polling data for %s", self.name) data = self.poller.parameter_value(self.parameter) except (OSError, BluetoothBackendException) as err: _LOGGER.info("Polling error %s: %s", type(err).__name__, err) return if data is not None: _LOGGER.debug("%s = %s", self.name, data) if self._unit == TEMP_FAHRENHEIT: data = celsius_to_fahrenheit(data) self.data.append(data) self.last_successful_update = dt_util.utcnow() else: _LOGGER.info("Did not receive any data from Mi Flora sensor %s", self.name) # Remove old data from median list or set sensor value to None # if no data is available anymore if self.data: self.data = self.data[1:] else: self._state = None return _LOGGER.debug("Data collected: %s", self.data) if len(self.data) > self.median_count: self.data = self.data[1:] if len(self.data) == self.median_count: median = sorted(self.data)[int((self.median_count - 1) / 2)] _LOGGER.debug("Median is: %s", median) self._state = median elif self._state is None: _LOGGER.debug("Set initial state") self._state = self.data[0] else: _LOGGER.debug("Not yet enough data for median calculation")
async def async_update(self): """Get the latest data from the BME680 and update the states.""" await self.opp.async_add_executor_job(self.bme680_client.update) if self.type == SENSOR_TEMP: temperature = round(self.bme680_client.sensor_data.temperature, 1) if self.temp_unit == TEMP_FAHRENHEIT: temperature = round(celsius_to_fahrenheit(temperature), 1) self._state = temperature elif self.type == SENSOR_HUMID: self._state = round(self.bme680_client.sensor_data.humidity, 1) elif self.type == SENSOR_PRESS: self._state = round(self.bme680_client.sensor_data.pressure, 1) elif self.type == SENSOR_GAS: self._state = int( round(self.bme680_client.sensor_data.gas_resistance, 0)) elif self.type == SENSOR_AQ: aq_score = self.bme680_client.sensor_data.air_quality if aq_score is not None: self._state = round(aq_score, 1)
def update(self): """Get the latest data from the DHT and updates the states.""" self.dht_client.update() temperature_offset = self.temperature_offset humidity_offset = self.humidity_offset data = self.dht_client.data if self.type == SENSOR_TEMPERATURE and SENSOR_TEMPERATURE in data: temperature = data[SENSOR_TEMPERATURE] _LOGGER.debug( "Temperature %.1f \u00b0C + offset %.1f", temperature, temperature_offset, ) if -20 <= temperature < 80: 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: humidity = data[SENSOR_HUMIDITY] _LOGGER.debug("Humidity %.1f%% + offset %.1f", humidity, humidity_offset) if 0 <= humidity <= 100: self._state = round(humidity + humidity_offset, 1)