mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
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_callback
This commit is contained in:
parent
2702c75fb0
commit
d89c56829c
@ -12,7 +12,6 @@ import voluptuous as vol
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_TOKEN, CONF_WEBHOOK_ID
|
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 import config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect, async_dispatcher_send)
|
async_dispatcher_connect, async_dispatcher_send)
|
||||||
@ -117,8 +116,11 @@ async def async_setup_webhook(hass: HomeAssistantType, entry: ConfigEntry,
|
|||||||
entry, data={
|
entry, data={
|
||||||
**entry.data,
|
**entry.data,
|
||||||
})
|
})
|
||||||
session.update_webhook(entry.data[CONF_WEBHOOK_URL],
|
await hass.async_add_executor_job(
|
||||||
entry.data[CONF_WEBHOOK_ID], events=['*'])
|
session.update_webhook,
|
||||||
|
entry.data[CONF_WEBHOOK_URL],
|
||||||
|
entry.data[CONF_WEBHOOK_ID],
|
||||||
|
['*'])
|
||||||
|
|
||||||
hass.components.webhook.async_register(
|
hass.components.webhook.async_register(
|
||||||
DOMAIN, 'Point', entry.data[CONF_WEBHOOK_ID], handle_webhook)
|
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):
|
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
|
||||||
client = hass.data[DOMAIN].pop(entry.entry_id)
|
session = hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
client.remove_webhook()
|
await hass.async_add_executor_job(session.remove_webhook)
|
||||||
|
|
||||||
if not hass.data[DOMAIN]:
|
if not hass.data[DOMAIN]:
|
||||||
hass.data.pop(DOMAIN)
|
hass.data.pop(DOMAIN)
|
||||||
@ -174,7 +176,8 @@ class MinutPointClient():
|
|||||||
|
|
||||||
async def _sync(self):
|
async def _sync(self):
|
||||||
"""Update local list of devices."""
|
"""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
|
self._is_available = False
|
||||||
_LOGGER.warning("Device is unavailable")
|
_LOGGER.warning("Device is unavailable")
|
||||||
return
|
return
|
||||||
@ -237,15 +240,14 @@ class MinutPointEntity(Entity):
|
|||||||
_LOGGER.debug('Created device %s', self)
|
_LOGGER.debug('Created device %s', self)
|
||||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||||
self.hass, SIGNAL_UPDATE_ENTITY, self._update_callback)
|
self.hass, SIGNAL_UPDATE_ENTITY, self._update_callback)
|
||||||
self._update_callback()
|
await self._update_callback()
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self):
|
async def async_will_remove_from_hass(self):
|
||||||
"""Disconnect dispatcher listener when removed."""
|
"""Disconnect dispatcher listener when removed."""
|
||||||
if self._async_unsub_dispatcher_connect:
|
if self._async_unsub_dispatcher_connect:
|
||||||
self._async_unsub_dispatcher_connect()
|
self._async_unsub_dispatcher_connect()
|
||||||
|
|
||||||
@callback
|
async def _update_callback(self):
|
||||||
def _update_callback(self):
|
|
||||||
"""Update the value of the sensor."""
|
"""Update the value of the sensor."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -75,8 +75,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice):
|
|||||||
if self._async_unsub_hook_dispatcher_connect:
|
if self._async_unsub_hook_dispatcher_connect:
|
||||||
self._async_unsub_hook_dispatcher_connect()
|
self._async_unsub_hook_dispatcher_connect()
|
||||||
|
|
||||||
@callback
|
async def _update_callback(self):
|
||||||
def _update_callback(self):
|
|
||||||
"""Update the value of the sensor."""
|
"""Update the value of the sensor."""
|
||||||
if not self.is_updated:
|
if not self.is_updated:
|
||||||
return
|
return
|
||||||
|
@ -13,7 +13,6 @@ from homeassistant.components.sensor import DOMAIN
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE,
|
||||||
TEMP_CELSIUS)
|
TEMP_CELSIUS)
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.util.dt import parse_datetime
|
from homeassistant.util.dt import parse_datetime
|
||||||
|
|
||||||
@ -50,12 +49,12 @@ class MinutPointSensor(MinutPointEntity):
|
|||||||
super().__init__(point_client, device_id, device_class)
|
super().__init__(point_client, device_id, device_class)
|
||||||
self._device_prop = SENSOR_TYPES[device_class]
|
self._device_prop = SENSOR_TYPES[device_class]
|
||||||
|
|
||||||
@callback
|
async def _update_callback(self):
|
||||||
def _update_callback(self):
|
|
||||||
"""Update the value of the sensor."""
|
"""Update the value of the sensor."""
|
||||||
if self.is_updated:
|
if self.is_updated:
|
||||||
_LOGGER.debug('Update sensor value for %s', self)
|
_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._updated = parse_datetime(self.device.last_update)
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user