Handle race condition on startup.
This commit is contained in:
parent
b1f7b5c6d7
commit
87a9fd8252
1 changed files with 4 additions and 1 deletions
|
@ -77,7 +77,10 @@ class SensorTemplate(Entity):
|
||||||
|
|
||||||
def _update_callback(_event):
|
def _update_callback(_event):
|
||||||
""" Called when the target device changes state. """
|
""" Called when the target device changes state. """
|
||||||
self.update_ha_state(True)
|
# This can be called before the entity is properly
|
||||||
|
# initialised, so check before updating state,
|
||||||
|
if self.entity_id:
|
||||||
|
self.update_ha_state(True)
|
||||||
|
|
||||||
self.hass.bus.listen(EVENT_STATE_CHANGED, _update_callback)
|
self.hass.bus.listen(EVENT_STATE_CHANGED, _update_callback)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue