Allow update entities on add_entities callback (#4114)
* Allow udpate entities on add_entities callback * fix wrong position * update force_update to update_before_add * add unittest for update_befor_add * fix unittest * change mocking
This commit is contained in:
1 parent
5d43d3eb1c
commit
9c0455e3dc
5 files changed
+50
-31
No files matched your search
@@ -61,7 +61,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
_LOGGER.error("No sensors added")
|
||||
return False
|
||||
|
||||
hass.loop.create_task(async_add_devices(sensors))
|
||||
hass.loop.create_task(async_add_devices(sensors, True))
|
||||
return True
|
||||
|
||||
|
||||
@@ -80,9 +80,6 @@ class SensorTemplate(Entity):
|
||||
self._template = state_template
|
||||
self._state = None
|
||||
|
||||
# update state
|
||||
self._async_render()
|
||||
|
||||
@callback
|
||||
def template_sensor_state_listener(entity, old_state, new_state):
|
||||
"""Called when the target device changes state."""
|
||||
@@ -114,10 +111,6 @@ class SensorTemplate(Entity):
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
"""Update the state from the template."""
|
||||
self._async_render()
|
||||
|
||||
def _async_render(self):
|
||||
"""Render the state from the template."""
|
||||
try:
|
||||
self._state = self._template.async_render()
|
||||
except TemplateError as ex:
|
||||
|
||||
Reference in new issue
Block a user