Fix Point does I/O in event loop (#20939)
* call I/O operations via hass.async_add_executor_job * asyncio fixes * Fixes from @amelchio * async _update_callbackpull/21016/head
parent
2702c75fb0
commit
d89c56829c
|
@ -12,7 +12,6 @@ import voluptuous as vol
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_TOKEN, CONF_WEBHOOK_ID
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect, async_dispatcher_send)
|
||||
|
@ -117,8 +116,11 @@ async def async_setup_webhook(hass: HomeAssistantType, entry: ConfigEntry,
|
|||
entry, data={
|
||||
**entry.data,
|
||||
})
|
||||
session.update_webhook(entry.data[CONF_WEBHOOK_URL],
|
||||
entry.data[CONF_WEBHOOK_ID], events=['*'])
|
||||
await hass.async_add_executor_job(
|
||||
session.update_webhook,
|
||||
entry.data[CONF_WEBHOOK_URL],
|
||||
entry.data[CONF_WEBHOOK_ID],
|
||||
['*'])
|
||||
|
||||
hass.components.webhook.async_register(
|
||||
DOMAIN, 'Point', entry.data[CONF_WEBHOOK_ID], handle_webhook)
|
||||
|
@ -127,8 +129,8 @@ async def async_setup_webhook(hass: HomeAssistantType, entry: ConfigEntry,
|
|||
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
||||
"""Unload a config entry."""
|
||||
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
||||
client = hass.data[DOMAIN].pop(entry.entry_id)
|
||||
client.remove_webhook()
|
||||
session = hass.data[DOMAIN].pop(entry.entry_id)
|
||||
await hass.async_add_executor_job(session.remove_webhook)
|
||||
|
||||
if not hass.data[DOMAIN]:
|
||||
hass.data.pop(DOMAIN)
|
||||
|
@ -174,7 +176,8 @@ class MinutPointClient():
|
|||
|
||||
async def _sync(self):
|
||||
"""Update local list of devices."""
|
||||
if not self._client.update() and self._is_available:
|
||||
if not await self._hass.async_add_executor_job(
|
||||
self._client.update) and self._is_available:
|
||||
self._is_available = False
|
||||
_LOGGER.warning("Device is unavailable")
|
||||
return
|
||||
|
@ -237,15 +240,14 @@ class MinutPointEntity(Entity):
|
|||
_LOGGER.debug('Created device %s', self)
|
||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_ENTITY, self._update_callback)
|
||||
self._update_callback()
|
||||
await self._update_callback()
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
if self._async_unsub_dispatcher_connect:
|
||||
self._async_unsub_dispatcher_connect()
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
async def _update_callback(self):
|
||||
"""Update the value of the sensor."""
|
||||
pass
|
||||
|
||||
|
|
|
@ -75,8 +75,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice):
|
|||
if self._async_unsub_hook_dispatcher_connect:
|
||||
self._async_unsub_hook_dispatcher_connect()
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
async def _update_callback(self):
|
||||
"""Update the value of the sensor."""
|
||||
if not self.is_updated:
|
||||
return
|
||||
|
|
|
@ -13,7 +13,6 @@ from homeassistant.components.sensor import DOMAIN
|
|||
from homeassistant.const import (
|
||||
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE,
|
||||
TEMP_CELSIUS)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.util.dt import parse_datetime
|
||||
|
||||
|
@ -50,12 +49,12 @@ class MinutPointSensor(MinutPointEntity):
|
|||
super().__init__(point_client, device_id, device_class)
|
||||
self._device_prop = SENSOR_TYPES[device_class]
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
async def _update_callback(self):
|
||||
"""Update the value of the sensor."""
|
||||
if self.is_updated:
|
||||
_LOGGER.debug('Update sensor value for %s', self)
|
||||
self._value = self.device.sensor(self.device_class)
|
||||
self._value = await self.hass.async_add_executor_job(
|
||||
self.device.sensor, self.device_class)
|
||||
self._updated = parse_datetime(self.device.last_update)
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
|
|
Loading…
Reference in New Issue