Update remaining i2c sensors to use async_add_executor_job (#41860)
parent
086378c48f
commit
2e05592039
|
@ -69,7 +69,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
|
||||
bus = smbus.SMBus(bus_number)
|
||||
|
||||
sensor = await hass.async_add_job(
|
||||
sensor = await hass.async_add_executor_job(
|
||||
partial(
|
||||
BH1750,
|
||||
bus,
|
||||
|
@ -130,7 +130,7 @@ class BH1750Sensor(Entity):
|
|||
|
||||
async def async_update(self):
|
||||
"""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:
|
||||
self._state = int(round(self.bh1750_sensor.light_level * self._multiplier))
|
||||
else:
|
||||
|
|
|
@ -89,7 +89,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
i2c_address = config[CONF_I2C_ADDRESS]
|
||||
|
||||
bus = smbus.SMBus(config[CONF_I2C_BUS])
|
||||
sensor = await hass.async_add_job(
|
||||
sensor = await hass.async_add_executor_job(
|
||||
partial(
|
||||
BME280,
|
||||
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)
|
||||
return False
|
||||
|
||||
sensor_handler = await hass.async_add_job(BME280Handler, sensor)
|
||||
sensor_handler = await hass.async_add_executor_job(BME280Handler, sensor)
|
||||
|
||||
dev = []
|
||||
try:
|
||||
|
@ -166,7 +166,7 @@ class BME280Sensor(Entity):
|
|||
|
||||
async def async_update(self):
|
||||
"""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.type == SENSOR_TEMP:
|
||||
temperature = round(self.bme280_client.sensor.temperature, 1)
|
||||
|
|
|
@ -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
|
||||
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:
|
||||
return
|
||||
|
||||
|
@ -347,7 +347,7 @@ class BME680Sensor(Entity):
|
|||
|
||||
async def async_update(self):
|
||||
"""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:
|
||||
temperature = round(self.bme680_client.sensor_data.temperature, 1)
|
||||
if self.temp_unit == TEMP_FAHRENHEIT:
|
||||
|
|
|
@ -41,12 +41,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
temp_unit = hass.config.units.temperature_unit
|
||||
|
||||
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:
|
||||
_LOGGER.error("HTU21D sensor not detected in bus %s", bus_number)
|
||||
return False
|
||||
|
||||
sensor_handler = await hass.async_add_job(HTU21DHandler, sensor)
|
||||
sensor_handler = await hass.async_add_executor_job(HTU21DHandler, sensor)
|
||||
|
||||
dev = [
|
||||
HTU21DSensor(sensor_handler, name, SENSOR_TEMPERATURE, temp_unit),
|
||||
|
@ -98,7 +98,7 @@ class HTU21DSensor(Entity):
|
|||
|
||||
async def async_update(self):
|
||||
"""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._variable == SENSOR_TEMPERATURE:
|
||||
value = round(self._client.sensor.temperature, 1)
|
||||
|
|
Loading…
Reference in New Issue