Update remaining i2c sensors to use async_add_executor_job (#41860)

This commit is contained in:
J. Nick Koston 2020-10-15 09:22:17 -05:00 committed by GitHub
parent 086378c48f
commit 2e05592039
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -69,7 +69,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
bus = smbus.SMBus(bus_number) bus = smbus.SMBus(bus_number)
sensor = await hass.async_add_job( sensor = await hass.async_add_executor_job(
partial( partial(
BH1750, BH1750,
bus, bus,
@ -130,7 +130,7 @@ class BH1750Sensor(Entity):
async def async_update(self): async def async_update(self):
"""Get the latest data from the BH1750 and update the states.""" """Get the latest data from the BH1750 and update the states."""
await self.hass.async_add_job(self.bh1750_sensor.update) await self.hass.async_add_executor_job(self.bh1750_sensor.update)
if self.bh1750_sensor.sample_ok and self.bh1750_sensor.light_level >= 0: if self.bh1750_sensor.sample_ok and self.bh1750_sensor.light_level >= 0:
self._state = int(round(self.bh1750_sensor.light_level * self._multiplier)) self._state = int(round(self.bh1750_sensor.light_level * self._multiplier))
else: else:

View File

@ -89,7 +89,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
i2c_address = config[CONF_I2C_ADDRESS] i2c_address = config[CONF_I2C_ADDRESS]
bus = smbus.SMBus(config[CONF_I2C_BUS]) bus = smbus.SMBus(config[CONF_I2C_BUS])
sensor = await hass.async_add_job( sensor = await hass.async_add_executor_job(
partial( partial(
BME280, BME280,
bus, bus,
@ -108,7 +108,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
_LOGGER.error("BME280 sensor not detected at %s", i2c_address) _LOGGER.error("BME280 sensor not detected at %s", i2c_address)
return False return False
sensor_handler = await hass.async_add_job(BME280Handler, sensor) sensor_handler = await hass.async_add_executor_job(BME280Handler, sensor)
dev = [] dev = []
try: try:
@ -166,7 +166,7 @@ class BME280Sensor(Entity):
async def async_update(self): async def async_update(self):
"""Get the latest data from the BME280 and update the states.""" """Get the latest data from the BME280 and update the states."""
await self.hass.async_add_job(self.bme280_client.update) await self.hass.async_add_executor_job(self.bme280_client.update)
if self.bme280_client.sensor.sample_ok: if self.bme280_client.sensor.sample_ok:
if self.type == SENSOR_TEMP: if self.type == SENSOR_TEMP:
temperature = round(self.bme280_client.sensor.temperature, 1) temperature = round(self.bme280_client.sensor.temperature, 1)

View File

@ -111,7 +111,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit
name = config[CONF_NAME] name = config[CONF_NAME]
sensor_handler = await hass.async_add_job(_setup_bme680, config) sensor_handler = await hass.async_add_executor_job(_setup_bme680, config)
if sensor_handler is None: if sensor_handler is None:
return return
@ -347,7 +347,7 @@ class BME680Sensor(Entity):
async def async_update(self): async def async_update(self):
"""Get the latest data from the BME680 and update the states.""" """Get the latest data from the BME680 and update the states."""
await self.hass.async_add_job(self.bme680_client.update) await self.hass.async_add_executor_job(self.bme680_client.update)
if self.type == SENSOR_TEMP: if self.type == SENSOR_TEMP:
temperature = round(self.bme680_client.sensor_data.temperature, 1) temperature = round(self.bme680_client.sensor_data.temperature, 1)
if self.temp_unit == TEMP_FAHRENHEIT: if self.temp_unit == TEMP_FAHRENHEIT:

View File

@ -41,12 +41,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
temp_unit = hass.config.units.temperature_unit temp_unit = hass.config.units.temperature_unit
bus = smbus.SMBus(config.get(CONF_I2C_BUS)) bus = smbus.SMBus(config.get(CONF_I2C_BUS))
sensor = await hass.async_add_job(partial(HTU21D, bus, logger=_LOGGER)) sensor = await hass.async_add_executor_job(partial(HTU21D, bus, logger=_LOGGER))
if not sensor.sample_ok: if not sensor.sample_ok:
_LOGGER.error("HTU21D sensor not detected in bus %s", bus_number) _LOGGER.error("HTU21D sensor not detected in bus %s", bus_number)
return False return False
sensor_handler = await hass.async_add_job(HTU21DHandler, sensor) sensor_handler = await hass.async_add_executor_job(HTU21DHandler, sensor)
dev = [ dev = [
HTU21DSensor(sensor_handler, name, SENSOR_TEMPERATURE, temp_unit), HTU21DSensor(sensor_handler, name, SENSOR_TEMPERATURE, temp_unit),
@ -98,7 +98,7 @@ class HTU21DSensor(Entity):
async def async_update(self): async def async_update(self):
"""Get the latest data from the HTU21D sensor and update the state.""" """Get the latest data from the HTU21D sensor and update the state."""
await self.hass.async_add_job(self._client.update) await self.hass.async_add_executor_job(self._client.update)
if self._client.sensor.sample_ok: if self._client.sensor.sample_ok:
if self._variable == SENSOR_TEMPERATURE: if self._variable == SENSOR_TEMPERATURE:
value = round(self._client.sensor.temperature, 1) value = round(self._client.sensor.temperature, 1)