mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Warn if fetching properties takes too long (#4208)
* Warn if fetching properties takes too long * Update entity.py
This commit is contained in:
parent
e88b98f5fa
commit
525d735f21
@ -1,6 +1,7 @@
|
|||||||
"""An abstract class for entities."""
|
"""An abstract class for entities."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from timeit import default_timer as timer
|
||||||
|
|
||||||
from typing import Any, Optional, List, Dict
|
from typing import Any, Optional, List, Dict
|
||||||
|
|
||||||
@ -210,7 +211,15 @@ class Entity(object):
|
|||||||
# future support?
|
# future support?
|
||||||
yield from self.hass.loop.run_in_executor(None, self.update)
|
yield from self.hass.loop.run_in_executor(None, self.update)
|
||||||
|
|
||||||
state = STATE_UNKNOWN if self.state is None else str(self.state)
|
start = timer()
|
||||||
|
|
||||||
|
state = self.state
|
||||||
|
|
||||||
|
if state is None:
|
||||||
|
state = STATE_UNKNOWN
|
||||||
|
else:
|
||||||
|
state = str(state)
|
||||||
|
|
||||||
attr = self.state_attributes or {}
|
attr = self.state_attributes or {}
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
device_attr = self.device_state_attributes
|
||||||
@ -231,6 +240,13 @@ class Entity(object):
|
|||||||
self._attr_setter('hidden', bool, ATTR_HIDDEN, attr)
|
self._attr_setter('hidden', bool, ATTR_HIDDEN, attr)
|
||||||
self._attr_setter('assumed_state', bool, ATTR_ASSUMED_STATE, attr)
|
self._attr_setter('assumed_state', bool, ATTR_ASSUMED_STATE, attr)
|
||||||
|
|
||||||
|
end = timer()
|
||||||
|
|
||||||
|
if end - start > 0.2:
|
||||||
|
_LOGGER.warning('Updating state for %s took %.3f seconds. '
|
||||||
|
'Please report to the developers.', self.entity_id,
|
||||||
|
end - start)
|
||||||
|
|
||||||
# Overwrite properties that have been set in the config file.
|
# Overwrite properties that have been set in the config file.
|
||||||
attr.update(_OVERWRITE.get(self.entity_id, {}))
|
attr.update(_OVERWRITE.get(self.entity_id, {}))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user